in src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java [352:422]
public SampleResult sample(Entry e)// Entry tends to be ignored ...
{
if (firstSample) { // Do stuff we cannot do as part of threadStarted()
initSampling();
firstSample=false;
}
final boolean reUseConnection = isReUseConnection();
final boolean closeConnection = isCloseConnection();
String socketKey = getSocketKey();
if (log.isDebugEnabled()){
log.debug(getLabel() + " " + getFilename() + " " + getUsername() + " " + getPassword());
}
SampleResult res = new SampleResult();
boolean isSuccessful = false;
res.setSampleLabel(getName());// Use the test element name for the label
String sb = "Host: " + getServer() +
" Port: " + getPort() + "\n" +
"Reuse: " + reUseConnection +
" Close: " + closeConnection + "\n[" +
"SOLINGER: " + getSoLinger() +
" EOL: " + getEolByte() +
" noDelay: " + getNoDelay() +
"]";
res.setSamplerData(sb);
res.sampleStart();
try {
Socket sock;
try {
sock = getSocket(socketKey);
} finally {
res.connectEnd();
}
if (sock == null) {
res.setResponseCode("500"); //$NON-NLS-1$
res.setResponseMessage(getError());
} else if (protocolHandler == null){
res.setResponseCode("500"); //$NON-NLS-1$
res.setResponseMessage("Protocol handler not found");
} else {
currentSocket = sock;
InputStream is = sock.getInputStream();
OutputStream os = sock.getOutputStream();
String req = getRequestData();
// TODO handle filenames
res.setSamplerData(req);
protocolHandler.write(os, req);
String in = protocolHandler.read(is, res);
isSuccessful = setupSampleResult(res, in, null, protocolHandler);
}
} catch (ReadException ex) {
log.error("", ex);
isSuccessful=setupSampleResult(res, ex.getPartialResponse(), ex,protocolHandler);
closeSocket(socketKey);
} catch (Exception ex) {
log.error("", ex);
isSuccessful=setupSampleResult(res, "", ex, protocolHandler);
closeSocket(socketKey);
} finally {
currentSocket = null;
// Calculate response time
res.sampleEnd();
// Set if we were successful or not
res.setSuccessful(isSuccessful);
if (!reUseConnection || closeConnection) {
closeSocket(socketKey);
}
}
return res;
}