HTTPSampleResult totalRes = new HTTPSampleResult(res); totalRes.addRawSubResult(res); HTTPSampleResult lastRes = res; for (redirect = 0; redirect < MAX_REDIRECTS; redirect++) { boolean invalidRedirectUrl = false; String location = lastRes.getRedirectLocation(); if (log.isDebugEnabled()) { log.debug("Initial location: " + location); String method = lastRes.getHTTPMethod(); method = computeMethodForRedirect(method); URL url = ConversionUtils.makeRelativeURL(lastRes.getURL(), location); url = ConversionUtils.sanitizeUrl(url).toURL(); if (log.isDebugEnabled()) { if (lastRes.getSubResults() != null && lastRes.getSubResults().length > 0) { SampleResult[] subs = lastRes.getSubResults(); for (SampleResult sub : subs) { totalRes.addSubResult(sub); totalRes.addSubResult(lastRes); if (!lastRes.isRedirect()) { break; lastRes = errorResult(new IOException("Exceeded maximum number of redirects: " + MAX_REDIRECTS), new HTTPSampleResult(lastRes)); totalRes.addSubResult(lastRes);
@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; }
HTTPSampleResult res = new HTTPSampleResult(); res.setSamplerData(req.toString()); res.setRequestHeaders("\n"); res.setHTTPMethod("GET"); try { res.setURL(new URL("http://parallel-urls-list")); } catch (MalformedURLException e) { log.warn("Failed to set empty url", e); res.setSuccessful(true); res.setResponseData(body.toString(), res.getDataEncodingWithDefault()); res.setContentType("text/html"); res.sampleStart(); downloadPageResources(res, res, depth); if (res.getEndTime() == 0L) { res.sampleEnd();
/** * Create HTTPSampleResult filling url, method and SampleLabel. * Monitor field is computed calling isMonitor() * @param url URL * @param method HTTP Method * @return {@link HTTPSampleResult} */ protected HTTPSampleResult createSampleResult(URL url, String method) { HTTPSampleResult res = new HTTPSampleResult(); res.setSampleLabel(this.testElement.getName()); res.setHTTPMethod(method); res.setURL(url); return res; }
/** * 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"); } } }
private void retrieveHTTPItem(HierarchicalStreamReader reader, HTTPSampleResult res, Object subItem) { if (subItem instanceof URL) { res.setURL((URL) subItem); } else { String nodeName = reader.getNodeName(); if (nodeName.equals(TAG_COOKIES)) { res.setCookies((String) subItem); } else if (nodeName.equals(TAG_METHOD)) { res.setHTTPMethod((String) subItem); } else if (nodeName.equals(TAG_QUERY_STRING)) { res.setQueryString((String) subItem); } else if (nodeName.equals(TAG_REDIRECT_LOCATION)) { res.setRedirectLocation((String) subItem); } } } }
HTTPSampleResult res = new HTTPSampleResult(); res.setSampleLabel(this.testElement.getName()); res.setURL(url); res.setHTTPMethod(method); res.sampleStart(); // Count the retries as well in the time res.setQueryString(postBody); } else if (method.equals(HTTPConstants.PUT)) { String putBody = sendPutData(conn); res.setQueryString(putBody); res.sampleEnd(); res.setResponseData(responseData); res.setResponseCode("(null)"); // $NON-NLS-1$ } else { res.setResponseCode(Integer.toString(errorLevel)); res.setSuccessful(isSuccessCode(errorLevel)); res.setResponseMessage(respMsg); res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1 res.setEncodingAndType(ct); res.setResponseHeaders(responseHeaders);
res.sampleStart(); res.sampleEnd(); errorResult(e, res); return res; res.sampleStart(); res.setRequestHeaders(getAllHeadersExceptCookie(request)); res.setContentType(ct); res.setEncodingAndType(ct); res.setResponseData(readResponse(res, entity.getContent(), entity.getContentLength())); res.sampleEnd(); // Done with the sampling proper. currentRequest = null; res.setResponseCode(Integer.toString(statusCode)); res.setResponseMessage(statusLine.getReasonPhrase()); res.setSuccessful(isSuccessCode(statusCode)); res.setResponseHeaders(getResponseHeaders(httpResponse)); if (res.isRedirect()) { final Header headerLocation = httpResponse.getLastHeader(HTTPConstants.HEADER_LOCATION); if (headerLocation == null) { // HTTP protocol violation, but avoids NPE res.setRedirectLocation(redirectLocation); (long)res.getResponseHeaders().length() // condensed length (without \r) + (long) httpResponse.getAllHeaders().length // Add \r for each header
boolean areFollowingRedirect, int frameDepth) { HTTPSampleResult res = new HTTPSampleResult(); res.setHTTPMethod(HTTPConstants.GET); // Dummy res.setURL(url); res.setSampleLabel(url.toString()); InputStream is = null; res.sampleStart(); int bufferSize = 4096; try ( org.apache.commons.io.output.ByteArrayOutputStream bos = new org.apache.commons.io.output.ByteArrayOutputStream(bufferSize) ) { res.sampleEnd(); res.setResponseData(responseData); res.setBodySize(totalBytes); res.setResponseCodeOK(); res.setResponseMessageOK(); res.setSuccessful(true); StringBuilder ctb=new StringBuilder("text/html"); // $NON-NLS-1$ res.setContentType(ct); res.setEncodingAndType(ct);
@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; } }
Iterator<URL> urls = null; try { final byte[] responseData = res.getResponseData(); if (responseData.length > 0) { // Bug 39205 final LinkExtractorParser parser = getParser(res); if (parser != null) { String userAgent = getUserAgent(res); urls = parser.getEmbeddedResourceURLs(userAgent, responseData, res.getURL(), res.getDataEncodingWithDefault()); res.addSubResult(errorResult(e, new HTTPSampleResult(res))); setParentSampleSuccess(res, false); lContainer = new HTTPSampleResult(res); lContainer.addRawSubResult(res); url = escapeIllegalURLCharacters(url); } catch (Exception e) { // NOSONAR res.addSubResult(errorResult(new Exception(url.toString() + " is not a correct URI", e), new HTTPSampleResult(res))); setParentSampleSuccess(res, false); continue; url = url.toURI().normalize().toURL(); } catch (MalformedURLException | URISyntaxException e) { res.addSubResult(errorResult(new Exception(url.toString() + " URI can not be normalized", e), new HTTPSampleResult(res))); setParentSampleSuccess(res, false); continue; res.addSubResult(binRes); setParentSampleSuccess(res, res.isSuccessful() && (binRes == null || binRes.isSuccessful()));
boolean areFollowingRedirect = pAreFollowingRedirect; HTTPSampleResult res = pRes; if (!areFollowingRedirect && res.isRedirect()) { if(log.isDebugEnabled()) { log.debug("Location set to - " + res.getRedirectLocation()); if (res.isSuccessful() && SampleResult.TEXT.equals(res.getDataType()) && isImageParser() ) { if (frameDepth > MAX_FRAME_DEPTH) { HTTPSampleResult errSubResult = new HTTPSampleResult(res); errSubResult.removeSubResults(); res.addSubResult(errorResult(new Exception("Maximum frame/iframe nesting depth exceeded."), errSubResult)); } else { areFollowingRedirect ? res.getParent() : SEPARATE_CONTAINER ? null : res); res = downloadPageResources(res, container, frameDepth);
private void parseHeaders(HTTPSampleResult res) throws IOException { int status = getInt(); res.setResponseCode(Integer.toString(status)); res.setSuccessful(200 <= status && status <= 399); String msg = getString(); res.setResponseMessage(msg); int nh = getInt(); StringBuilder sb = new StringBuilder(); res.setContentType(value); res.setEncodingAndType(value); } else if(HTTPConstants.HEADER_SET_COOKIE.equalsIgnoreCase(name)) { CookieManager cookies = getCookieManager(); if(cookies != null) { cookies.addCookieFromHeader(value, res.getURL()); res.setResponseHeaders(sb.toString());
/** * 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$ } } }
protected HttpClient setupConnection(URL u, HttpMethodBase httpMethod) throws IOException { HTTPSampleResult temp = new HTTPSampleResult(); return super.setupConnection(u, httpMethod, temp); }
lastPort = port; res.setURL(url); res.setHTTPMethod(method); outpos = 4; setByte((byte)2); setInt(getHeaderSize(method, url)); String hdr = setConnectionHeaders(url, host, method); res.setRequestHeaders(hdr); res.setCookies(setConnectionCookies(url, getCookieManager())); String query = url.getQuery(); if (query != null) {
private void saveSamplerData(HierarchicalStreamWriter writer, MarshallingContext context, HTTPSampleResult res, SampleSaveConfiguration save) { if (save.saveSamplerData(res)) { writeString(writer, TAG_COOKIES, res.getCookies()); writeString(writer, TAG_METHOD, res.getHTTPMethod()); writeString(writer, TAG_QUERY_STRING, res.getQueryString()); writeString(writer, TAG_REDIRECT_LOCATION, res.getRedirectLocation()); } if (save.saveUrl()) { writeItem(res.getURL(), context, writer); } }
sampleResult.getHTTPMethod())); LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getRequestHeaders()); for (Entry<String, String> entry : lhm.entrySet()) { headersModel.addRow(new RowResult(entry.getKey(), entry.getValue())); URL hUrl = sampleResult.getURL(); if (hUrl != null){ // can be null - e.g. if URL was invalid requestModel.addRow(new RowResult(JMeterUtils String queryPost = sampleResult.getQueryString(); if (!isMultipart && StringUtils.isNotBlank(queryPost)) { if (queryGet.length() > 0) { String cookie = sampleResult.getCookies(); if (cookie != null && cookie.length() > 0) { headersModel.addRow(new RowResult( JMeterUtils.getParsedLabel("view_results_table_request_http_cookie"), //$NON-NLS-1$ sampleResult.getCookies()));
private void addFormUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) { NodeList rootList = html.getChildNodes(); List<HTTPSamplerBase> urls = new LinkedList<>(); for (int x = 0; x < rootList.getLength(); x++) { urls.addAll(HtmlParsingUtils.createURLFromForm(rootList.item(x), result.getURL())); } for (HTTPSamplerBase newUrl : urls) { newUrl.setMethod(HTTPConstants.POST); if (log.isDebugEnabled()) { log.debug("Potential Form match: " + newUrl.toString()); } if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) { log.debug("Matched!"); potentialLinks.add(newUrl); } } }
String responseText = result.getResponseDataAsString(); int index = responseText.indexOf('<'); // $NON-NLS-1$ if (index == -1) {