/** * 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; }
/** * Set parent successful attribute based on IGNORE_FAILED_EMBEDDED_RESOURCES parameter * @param res {@link HTTPSampleResult} * @param initialValue boolean */ private void setParentSampleSuccess(HTTPSampleResult res, boolean initialValue) { if (!IGNORE_FAILED_EMBEDDED_RESOURCES) { res.setSuccessful(initialValue); if (!initialValue) { StringBuilder detailedMessage = new StringBuilder(80); detailedMessage.append("Embedded resource download error:"); //$NON-NLS-1$ for (SampleResult subResult : res.getSubResults()) { HTTPSampleResult httpSampleResult = (HTTPSampleResult) subResult; if (!httpSampleResult.isSuccessful()) { detailedMessage.append(httpSampleResult.getURL()) .append(" code:") //$NON-NLS-1$ .append(httpSampleResult.getResponseCode()) .append(" message:") //$NON-NLS-1$ .append(httpSampleResult.getResponseMessage()) .append(", "); //$NON-NLS-1$ } } res.setResponseMessage(detailedMessage.toString()); //$NON-NLS-1$ } } }
/** * Update HTTPSampleResult for a resource in cache * @param res {@link HTTPSampleResult} * @return HTTPSampleResult */ protected HTTPSampleResult updateSampleResultForResourceInCache(HTTPSampleResult res) { switch (CACHED_RESOURCE_MODE) { case RETURN_NO_SAMPLE: return null; case RETURN_200_CACHE: res.sampleEnd(); res.setResponseCodeOK(); res.setResponseMessage(RETURN_200_CACHE_MESSAGE); res.setSuccessful(true); return res; case RETURN_CUSTOM_STATUS: res.sampleEnd(); res.setResponseCode(RETURN_CUSTOM_STATUS_CODE); res.setResponseMessage(RETURN_CUSTOM_STATUS_MESSAGE); res.setSuccessful(true); return res; default: // Cannot happen throw new IllegalStateException("Unknown CACHED_RESOURCE_MODE"); } } }
int status = getInt(); res.setResponseCode(Integer.toString(status)); res.setSuccessful(200 <= status && status <= 399); String msg = getString(); res.setResponseMessage(msg);
res.setSuccessful(true); res.setResponseData(body.toString(), res.getDataEncodingWithDefault()); res.setContentType("text/html");
res.setResponseCodeOK(); res.setResponseMessageOK(); res.setSuccessful(true); StringBuilder ctb=new StringBuilder("text/html"); // $NON-NLS-1$
res.setResponseCode(Integer.toString(errorLevel)); res.setSuccessful(isSuccessCode(errorLevel));
res.setResponseCode(Integer.toString(statusCode)); res.setResponseMessage(statusLine.getReasonPhrase()); res.setSuccessful(isSuccessCode(statusCode)); res.setResponseHeaders(getResponseHeaders(httpResponse)); if (res.isRedirect()) {
totalRes.setSuccessful(lastRes.isSuccessful()); totalRes.setResponseMessage(lastRes.getResponseMessage()); totalRes.setDataType(lastRes.getDataType());