Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jmeter.protocol.tcp.sampler;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.Interruptible;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* A sampler which understands Tcp requests.
*
*/
public class TCPSampler extends AbstractSampler implements ThreadListener, Interruptible {
private static final long serialVersionUID = 280L;
private static final Logger log = LoggerFactory.getLogger(TCPSampler.class);
private static final Set APPLIABLE_CONFIG_CLASSES = new HashSet<>(
Arrays.asList(
"org.apache.jmeter.config.gui.LoginConfigGui",
"org.apache.jmeter.protocol.tcp.config.gui.TCPConfigGui",
"org.apache.jmeter.config.gui.SimpleConfigGui"
));
public static final String SERVER = "TCPSampler.server"; //$NON-NLS-1$
public static final String PORT = "TCPSampler.port"; //$NON-NLS-1$
public static final String FILENAME = "TCPSampler.filename"; //$NON-NLS-1$
public static final String CLASSNAME = "TCPSampler.classname";//$NON-NLS-1$
public static final String NODELAY = "TCPSampler.nodelay"; //$NON-NLS-1$
public static final String TIMEOUT = "TCPSampler.timeout"; //$NON-NLS-1$
public static final String TIMEOUT_CONNECT = "TCPSampler.ctimeout"; //$NON-NLS-1$
public static final String REQUEST = "TCPSampler.request"; //$NON-NLS-1$
public static final String RE_USE_CONNECTION = "TCPSampler.reUseConnection"; //$NON-NLS-1$
public static final boolean RE_USE_CONNECTION_DEFAULT = true;
public static final String CLOSE_CONNECTION = "TCPSampler.closeConnection"; //$NON-NLS-1$
public static final boolean CLOSE_CONNECTION_DEFAULT = false;
public static final String SO_LINGER = "TCPSampler.soLinger"; //$NON-NLS-1$
public static final String EOL_BYTE = "TCPSampler.EolByte"; //$NON-NLS-1$
private static final String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap
private static final String ERRKEY = "ERR"; //$NON-NLS-1$ key for HashMap
// the response is scanned for these strings
private static final String STATUS_PREFIX = JMeterUtils.getPropDefault("tcp.status.prefix", ""); //$NON-NLS-1$
private static final String STATUS_SUFFIX = JMeterUtils.getPropDefault("tcp.status.suffix", ""); //$NON-NLS-1$
private static final String STATUS_PROPERTIES = JMeterUtils.getPropDefault("tcp.status.properties", ""); //$NON-NLS-1$
private static final Properties STATUS_PROPS = new Properties();
private static final String PROTO_PREFIX = "org.apache.jmeter.protocol.tcp.sampler."; //$NON-NLS-1$
private static final boolean HAVE_STATUS_PROPS;
//设置tcp编码
public static String charset = "UTF-8";
public void setCharset(String charset) {
this.setProperty("CHARSET", charset);
}
public String getCharset() {
return getPropertyAsString("CHARSET");
}
static {
boolean hsp = false;
log.debug("Status prefix={}, suffix={}, properties={}",
STATUS_PREFIX, STATUS_SUFFIX, STATUS_PROPERTIES); //$NON-NLS-1$
if (STATUS_PROPERTIES.length() > 0) {
File f = new File(STATUS_PROPERTIES);
try (FileInputStream fis = new FileInputStream(f)){
STATUS_PROPS.load(fis);
log.debug("Successfully loaded properties"); //$NON-NLS-1$
hsp = true;
} catch (FileNotFoundException e) {
log.debug("Property file {} not found", STATUS_PROPERTIES); //$NON-NLS-1$
} catch (IOException e) {
log.debug("Error reading property file {} error {}", STATUS_PROPERTIES, e.toString()); //$NON-NLS-1$
}
}
HAVE_STATUS_PROPS = hsp;
}
/** the cache of TCP Connections */
// KEY = TCPKEY or ERRKEY, Entry= Socket or String
private static final ThreadLocal