public static HTTPAbstractImpl getInstance(HTTPSamplerBase sampler) { return new HTTPHC4Impl(sampler); }
@Override protected void threadFinished() { log.debug("Thread Finished"); closeThreadLocalConnections(); }
HTTPSampleResult res = createSampleResult(url, method); HttpContext localContext = new BasicHttpContext(); HttpClientContext clientContext = HttpClientContext.adapt(localContext); clientContext.setAttribute(CONTEXT_ATTRIBUTE_AUTH_MANAGER, getAuthManager()); try { httpClient = setupClient(jMeterVariables, url, clientContext); URI uri = url.toURI(); httpRequest = createHttpRequest(uri, method, areFollowingRedirect); setupRequest(url, httpRequest, res); // can throw IOException } catch (Exception e) { res.sampleStart(); res.sampleEnd(); errorResult(e, res); return res; setupClientContextBeforeSample(jMeterVariables, localContext); final CacheManager cacheManager = getCacheManager(); if (cacheManager != null && HTTPConstants.GET.equalsIgnoreCase(method) && cacheManager.inCache(url, httpRequest.getAllHeaders())) { return updateSampleResultForResourceInCache(res); handleMethod(method, res, httpRequest, localContext); executeRequest(httpClient, httpRequest, localContext, url); extractClientContextAfterSample(jMeterVariables, localContext); res.setRequestHeaders(getAllHeadersExceptCookie(request));
HTTPFileArg[] files = getHTTPFiles(); final String contentEncoding = getContentEncodingOrNull(); final boolean haveContentEncoding = contentEncoding != null; if(getUseMultipart()) { getDoBrowserCompatibleMultipart(), charset, haveContentEncoding); if(getDoBrowserCompatibleMultipart()) { multipartEntityBuilder.setLaxMode(); } else { for (JMeterProperty jMeterProperty : getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); String parameterName = arg.getName(); writeEntityToSB(postedBody, entity, fileBodies, contentEncoding); } else { // not multipart if(!hasArguments() && getSendFileAsPostBody()) { if(getSendParameterValuesAsPostBody()) { for (JMeterProperty jMeterProperty : getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); UrlEncodedFormEntity entity = createUrlEncodedFormEntity(urlContentEncoding); entityEnclosingRequest.setEntity(entity);
boolean hasEntityBody = false; final HTTPFileArg[] files = getHTTPFiles(); final String charset = getContentEncoding(HTTP.DEF_CONTENT_CHARSET.name()); if(!hasArguments() && getSendFileAsPostBody()) { hasEntityBody = true; else if(getSendParameterValuesAsPostBody()) { hasEntityBody = true; Arguments arguments = getArguments(); StringBuilder entityBodyContent = new StringBuilder(arguments.getArgumentCount()*15); for (JMeterProperty jMeterProperty : arguments) { } else if (hasArguments()) { hasEntityBody = true; entity.setEntity(createUrlEncodedFormEntity(getContentEncodingOrNull())); writeEntityToSB(entityBody, entityEntry, EMPTY_FILE_BODIES, charset); return entityBody.toString();
/** * Reset SSL State. <br/> * In order to do that we need to: * <ul> * <li>Call resetContext() on SSLManager</li> * <li>Close current Idle or Expired connections that hold SSL State</li> * <li>Remove HttpClientContext.USER_TOKEN from {@link HttpClientContext}</li> * </ul> * @param jMeterVariables {@link JMeterVariables} * @param clientContext {@link HttpClientContext} * @param mapHttpClientPerHttpClientKey Map of {@link Pair} holding {@link CloseableHttpClient} and {@link PoolingHttpClientConnectionManager} */ private void resetStateIfNeeded(JMeterVariables jMeterVariables, HttpClientContext clientContext, Map<HttpClientKey, Pair<CloseableHttpClient, PoolingHttpClientConnectionManager>> mapHttpClientPerHttpClientKey) { if (resetStateOnThreadGroupIteration.get()) { closeCurrentConnections(mapHttpClientPerHttpClientKey); clientContext.removeAttribute(HttpClientContext.USER_TOKEN); ((JsseSSLManager) SSLManager.getInstance()).resetContext(); resetStateOnThreadGroupIteration.set(false); } }
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+"'"); } }