/** * Populates the provided HTTPSampleResult with details from the Exception. * Does not create a new instance, so should not be used directly to add a subsample. * * @param e * Exception representing the error. * @param res * SampleResult to be modified * @return the modified sampling result containing details of the Exception. */ protected HTTPSampleResult errorResult(Throwable e, HTTPSampleResult res) { res.setSampleLabel(res.getSampleLabel()); res.setDataType(SampleResult.TEXT); ByteArrayOutputStream text = new ByteArrayOutputStream(200); e.printStackTrace(new PrintStream(text)); // NOSONAR Stacktrace will be used in the response res.setResponseData(text.toByteArray()); res.setResponseCode(NON_HTTP_RESPONSE_CODE+": " + e.getClass().getName()); res.setResponseMessage(NON_HTTP_RESPONSE_MESSAGE+": " + e.getMessage()); res.setSuccessful(false); return res; }
res.setResponseData(body.toString(), res.getDataEncodingWithDefault()); res.setContentType("text/html"); res.sampleStart();
res.setResponseData(responseData); res.setBodySize(totalBytes); res.setResponseCodeOK();
@Override protected HTTPSampleResult sample(URL url, String method, boolean frd, int fd) { HTTPSampleResult res = new HTTPSampleResult(); res.setSampleLabel(url.toExternalForm()); res.sampleStart(); try { setupConnection(url, method, res); activeChannel = channel; execute(method, res); res.sampleEnd(); res.setResponseData(responseData.toByteArray()); return res; } catch(IOException iex) { res.sampleEnd(); lastPort = -1; // force reopen on next sample channel = null; return errorResult(iex, res); } finally { activeChannel = null; JOrphanUtils.closeQuietly(body); body = null; } }
res.setResponseData(responseData);
res.setResponseData(readResponse(res, entity.getContent(), entity.getContentLength()));
totalRes.setRequestHeaders(lastRes.getRequestHeaders()); totalRes.setResponseData(lastRes.getResponseData()); totalRes.setResponseCode(lastRes.getResponseCode()); totalRes.setSuccessful(lastRes.isSuccessful());