public void setResponseNoContent(){ setResponseCode(HTTP_NO_CONTENT_CODE); setResponseMessage(HTTP_NO_CONTENT_MSG); }
@Override protected HTTPSampleResult sample(java.net.URL u, String method, boolean areFollowingRedirect, int depth) { HTTPSampleResult sample = super.sample(u, method, areFollowingRedirect, depth); sample.setSampleLabel(queryGenerator.getQueryId()); if (getArguments().getArgumentsAsMap().get(QueryOptions.COUNT).equalsIgnoreCase("true")) { String str = sample.getResponseDataAsString(); sample.setResponseMessage(str.substring(str.lastIndexOf("[") + 1, str.indexOf("]"))); } return sample; }
/** * 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"); } } }
res.setSuccessful(200 <= status && status <= 399); String msg = getString(); res.setResponseMessage(msg); int nh = getInt(); StringBuilder sb = new StringBuilder();
int statusCode = statusLine.getStatusCode(); res.setResponseCode(Integer.toString(statusCode)); res.setResponseMessage(statusLine.getReasonPhrase()); res.setSuccessful(isSuccessCode(statusCode)); res.setResponseHeaders(getResponseHeaders(httpResponse));
totalRes.setResponseCode(lastRes.getResponseCode()); totalRes.setSuccessful(lastRes.isSuccessful()); totalRes.setResponseMessage(lastRes.getResponseMessage()); totalRes.setDataType(lastRes.getDataType()); totalRes.setResponseHeaders(lastRes.getResponseHeaders());