public HTTPSampler(){ hc = new HTTPJavaImpl(this); }
/** * Get all the headers for the <code>HttpURLConnection</code> passed in * * @param conn * <code>HttpUrlConnection</code> which represents the URL * request * @param securityHeaders Map of security Header * @return the headers as a string */ private String getAllHeadersExceptCookie(HttpURLConnection conn, Map<String, String> securityHeaders) { return getFromConnectionHeaders(conn, securityHeaders, ALL_EXCEPT_COOKIE, true); }
final String proxyHost = getProxyHost(); final int proxyPort = getProxyPortInt(); if (proxyHost.length() > 0 && proxyPort > 0){ Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); conn.setInstanceFollowRedirects(getAutoRedirects()); int cto = getConnectTimeout(); if (cto > 0){ conn.setConnectTimeout(cto); int rto = getResponseTimeout(); if (rto > 0){ conn.setReadTimeout(rto); if (getUseKeepAlive()) { conn.setRequestProperty(HTTPConstants.HEADER_CONNECTION, HTTPConstants.KEEP_ALIVE); } else { setConnectionHeaders(conn, u, getHeaderManager(), getCacheManager()); String cookies = setConnectionCookie(conn, u, getCookieManager()); Map<String, String> securityHeaders = setConnectionAuthorization(conn, u, getAuthManager()); setPostHeaders(conn); } else if (method.equals(HTTPConstants.PUT)) { setPutHeaders(conn); res.setRequestHeaders(getAllHeadersExceptCookie(conn, securityHeaders));
final CacheManager cacheManager = getCacheManager(); if (cacheManager != null && HTTPConstants.GET.equalsIgnoreCase(method)) { if (cacheManager.inCache(url, getHeaders(getHeaderManager()))) { return updateSampleResultForResourceInCache(res); conn = setupConnection(url, method, res); setUseKeepAlive(false); } catch (IOException e) { log.debug("Connection failed, giving up"); String postBody = sendPostData(conn); res.setQueryString(postBody); } else if (method.equals(HTTPConstants.PUT)) { String putBody = sendPutData(conn); res.setQueryString(putBody); byte[] responseData = readResponse(conn, res); res.setSuccessful(isSuccessCode(errorLevel)); String responseHeaders = getResponseHeaders(conn); res.setResponseHeaders(responseHeaders); if (res.isRedirect()) { if (getAutoRedirects()){ res.setURL(conn.getURL()); saveConnectionCookies(conn, url, getCookieManager());
/** * Get only the Cookie headers for the <code>HttpURLConnection</code> passed in * * @param conn * <code>HttpUrlConnection</code> which represents the URL * request * @param securityHeaders Map of security Header * @return the headers as a string */ private String getOnlyCookieFromHeaders(HttpURLConnection conn, Map<String, String> securityHeaders) { String cookieHeader= getFromConnectionHeaders(conn, securityHeaders, ONLY_COOKIE, false).trim(); if(!cookieHeader.isEmpty()) { return cookieHeader.substring((HTTPConstants.HEADER_COOKIE_IN_REQUEST).length(), cookieHeader.length()).trim(); } return ""; }
public static HTTPAbstractImpl getImplementation(String impl, HTTPSamplerBase base){ if (HTTPSamplerBase.PROTOCOL_FILE.equals(base.getProtocol())) { return new HTTPFileImpl(base); } if (JOrphanUtils.isBlank(impl)){ impl = DEFAULT_CLASSNAME; } if (IMPL_JAVA.equals(impl) || HTTP_SAMPLER_JAVA.equals(impl)) { return new HTTPJavaImpl(base); } else if (IMPL_HTTP_CLIENT4.equals(impl) || IMPL_HTTP_CLIENT3_1.equals(impl)) { return new HTTPHC4Impl(base); } else { throw new IllegalArgumentException("Unknown implementation type: '"+impl+"'"); } }