List of usage examples for org.apache.http.impl.client HttpClientBuilder setConnectionManager
public final HttpClientBuilder setConnectionManager(final HttpClientConnectionManager connManager)
From source file:sk.datalan.solr.impl.HttpClientUtil.java
public static HttpClientBuilder configureClient(final HttpClientConfiguration config) { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); // max total connections if (config.isSetMaxConnections()) { clientBuilder.setMaxConnTotal(config.getMaxConnections()); }/*from www . j a v a 2s .c o m*/ // max connections per route if (config.isSetMaxConnectionsPerRoute()) { clientBuilder.setMaxConnPerRoute(config.getMaxConnectionsPerRoute()); } RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH) .setExpectContinueEnabled(true).setStaleConnectionCheckEnabled(true); // connection timeout if (config.isSetConnectionTimeout()) { requestConfigBuilder.setConnectTimeout(config.getConnectionTimeout()); } // soucket timeout if (config.isSetSocketTimeout()) { requestConfigBuilder.setSocketTimeout(config.getSocketTimeout()); } // soucket timeout if (config.isSetFollowRedirects()) { requestConfigBuilder.setRedirectsEnabled(config.getFollowRedirects()); } clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); if (config.isSetUseRetry()) { if (config.getUseRetry()) { clientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler()); } else { clientBuilder.setRetryHandler(NO_RETRY); } } // basic authentication if (config.isSetBasicAuthUsername() && config.isSetBasicAuthPassword()) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.getBasicAuthUsername(), config.getBasicAuthPassword())); } if (config.isSetAllowCompression()) { clientBuilder.addInterceptorFirst(new UseCompressionRequestInterceptor()); clientBuilder.addInterceptorFirst(new UseCompressionResponseInterceptor()); } // SSL context for secure connections can be created either based on // system or application specific properties. SSLContext sslcontext = SSLContexts.createSystemDefault(); // Use custom hostname verifier to customize SSL hostname verification. X509HostnameVerifier hostnameVerifier = new BrowserCompatHostnameVerifier(); // Create a registry of custom connection socket factories for supported // protocol schemes. Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier)).build(); clientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)); return clientBuilder; }
From source file:info.bonjean.beluga.connection.BelugaHTTPClient.java
private BelugaHTTPClient() { BelugaConfiguration configuration = BelugaConfiguration.getInstance(); HttpClientBuilder clientBuilder = HttpClients.custom(); // timeout//w ww . jav a2 s . c om RequestConfig config = RequestConfig.custom().setConnectTimeout(TIMEOUT).setSocketTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT).build(); clientBuilder.setDefaultRequestConfig(config); switch (configuration.getConnectionType()) { case PROXY_DNS: Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()).build(); BelugaDNSResolver dnsOverrider = new BelugaDNSResolver(DNSProxy.PROXY_DNS); connectionManager = new PoolingHttpClientConnectionManager(registry, dnsOverrider); break; case HTTP_PROXY: HttpHost proxy = new HttpHost(configuration.getProxyHost(), configuration.getProxyPort(), "http"); clientBuilder.setProxy(proxy); break; default: } // limit the pool size connectionManager.setDefaultMaxPerRoute(2); // add interceptor, currently for debugging only clientBuilder.addInterceptorFirst(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { HttpInetConnection connection = (HttpInetConnection) context .getAttribute(HttpCoreContext.HTTP_CONNECTION); log.debug("Remote address: " + connection.getRemoteAddress()); // TODO: reimplement blacklisting for DNS proxy by maintaining a // map [DNS IP,RESOLVED IP] in the DNS resolver for reverse // lookup } }); // finally create the HTTP client clientBuilder.setConnectionManager(connectionManager); httpClient = clientBuilder.build(); }
From source file:org.hyperledger.fabric_ca.sdk.HFCAClient.java
/** * Http Post Request./*from w w w. ja v a 2 s . co m*/ * * @param url Target URL to POST to. * @param body Body to be sent with the post. * @param credentials Credentials to use for basic auth. * @return Body of post returned. * @throws Exception */ String httpPost(String url, String body, UsernamePasswordCredentials credentials) throws Exception { logger.debug(format("httpPost %s, body:%s", url, body)); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CredentialsProvider provider = null; if (credentials != null) { provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, credentials); httpClientBuilder.setDefaultCredentialsProvider(provider); } if (registry != null) { httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(registry)); } HttpClient client = httpClientBuilder.build(); HttpPost httpPost = new HttpPost(url); httpPost.setConfig(getRequestConfig()); AuthCache authCache = new BasicAuthCache(); HttpHost targetHost = new HttpHost(httpPost.getURI().getHost(), httpPost.getURI().getPort()); if (credentials != null) { authCache.put(targetHost, new BasicScheme()); } final HttpClientContext context = HttpClientContext.create(); if (null != provider) { context.setCredentialsProvider(provider); } if (credentials != null) { context.setAuthCache(authCache); } httpPost.setEntity(new StringEntity(body)); if (credentials != null) { httpPost.addHeader(new BasicScheme(). authenticate(credentials, httpPost, context)); } HttpResponse response = client.execute(httpPost, context); int status = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); logger.trace(format("httpPost %s sending...", url)); String responseBody = entity != null ? EntityUtils.toString(entity) : null; logger.trace(format("httpPost %s responseBody %s", url, responseBody)); if (status >= 400) { Exception e = new Exception(format( "POST request to %s with request body: %s, " + "failed with status code: %d. Response: %s", url, body, status, responseBody)); logger.error(e.getMessage()); throw e; } logger.debug(format("httpPost Status: %d returning: %s ", status, responseBody)); return responseBody; }
From source file:org.apache.sling.discovery.etcd.EtcdDiscoveryService.java
private void buildHttpClient(@Nonnull String keystoreFilePath, @Nonnull String keystorePwdFilePath) { boolean hasKeyStore = !isEmpty(keystoreFilePath); RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout) .setConnectTimeout(connectionTimeout).setRedirectsEnabled(true).setStaleConnectionCheckEnabled(true) .build();/*from w w w .j a v a2s.co m*/ HttpClientBuilder builder = HttpClients.custom().setDefaultRequestConfig(requestConfig) .addInterceptorFirst(new GzipRequestInterceptor()) .addInterceptorFirst(new GzipResponseInterceptor()); if (hasKeyStore) { final SSLContextBuilder sslContextBuilder = SSLContexts.custom(); LOG.info("Loading keystore from file: {}", keystoreFilePath); char[] pwd = readPwd(keystorePwdFilePath); try { KeyStore keystore = loadKeyStore(keystoreFilePath, pwd); sslContextBuilder.loadTrustMaterial(keystore); sslContextBuilder.loadKeyMaterial(keystore, pwd); LOG.info("Setup custom SSL context"); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory( sslContextBuilder.build()); Registry<ConnectionSocketFactory> connectionSocketFactory = RegistryBuilder .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", sslConnectionSocketFactory).build(); builder.setSSLSocketFactory(sslConnectionSocketFactory); connectionManager = new PoolingHttpClientConnectionManager(connectionSocketFactory); } catch (UnrecoverableKeyException e) { throw wrap(e); } catch (NoSuchAlgorithmException e) { throw wrap(e); } catch (KeyStoreException e) { throw wrap(e); } catch (KeyManagementException e) { throw wrap(e); } finally { reset(pwd); } } else { connectionManager = new PoolingHttpClientConnectionManager(); } builder.setConnectionManager(connectionManager); httpClient = builder.build(); }
From source file:net.www_eee.portal.channels.ProxyChannel.java
/** * Construct and configure the {@link HttpClient} to be used to * {@linkplain #doProxyRequest(Page.Request, Channel.Mode) proxy} content while fulfilling the specified * <code>pageRequest</code>. This method will also configure {@linkplain ProxyRequestInterceptor request} and * {@linkplain ProxyResponseInterceptor response} interceptors on the created client. * //from w w w . ja v a 2s . co m * @param pageRequest The {@link net.www_eee.portal.Page.Request Request} currently being processed. * @return The created {@link HttpClient}. * @throws WWWEEEPortal.Exception If a problem occurred while determining the result. * @see #doProxyRequest(Page.Request, Channel.Mode) * @see #PROXY_CLIENT_HOOK * @see ProxyRequestInterceptor * @see ProxyResponseInterceptor */ protected CloseableHttpClient createProxyClient(final Page.Request pageRequest) throws WWWEEEPortal.Exception { final org.apache.http.client.CookieStore proxyClientCookieStore = createProxyClientCookieStore(pageRequest); Object[] context = new Object[] { proxyClientManager, proxyClientCookieStore }; HttpClientBuilder proxyClientBuilder = PROXY_CLIENT_HOOK.value(plugins, context, pageRequest); if (proxyClientBuilder == null) { final HttpClientBuilder pcb = HttpClientBuilder.create(); Optional.ofNullable(proxyClientManager) .ifPresent((proxyClientManager) -> pcb.setConnectionManager(proxyClientManager)); proxyClientBuilder = pcb; proxyClientBuilder.setDefaultCookieStore(proxyClientCookieStore); proxyClientBuilder = proxyClientBuilder.addInterceptorLast(new ProxyRequestInterceptor(pageRequest)); proxyClientBuilder = proxyClientBuilder.addInterceptorLast(new ProxyResponseInterceptor(pageRequest)); } proxyClientBuilder = PROXY_CLIENT_HOOK .requireFilteredResult(PROXY_CLIENT_HOOK.filter(plugins, context, pageRequest, proxyClientBuilder)); return proxyClientBuilder.build(); }
From source file:org.fao.geonet.utils.GeonetHttpRequestFactory.java
public HttpClientBuilder getDefaultHttpClientBuilder() { final HttpClientBuilder builder = HttpClientBuilder.create(); builder.setRedirectStrategy(new LaxRedirectStrategy()); builder.disableContentCompression(); synchronized (this) { if (connectionManager == null) { connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(this.numberOfConcurrentRequests); nonShutdownableConnectionManager = new HttpClientConnectionManager() { public void closeExpiredConnections() { connectionManager.closeExpiredConnections(); }//from w w w. j a v a2 s . c om public ConnectionRequest requestConnection(HttpRoute route, Object state) { return connectionManager.requestConnection(route, state); } public void releaseConnection(HttpClientConnection managedConn, Object state, long keepalive, TimeUnit tunit) { connectionManager.releaseConnection(managedConn, state, keepalive, tunit); } public void connect(HttpClientConnection managedConn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException { connectionManager.connect(managedConn, route, connectTimeout, context); } public void upgrade(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException { connectionManager.upgrade(managedConn, route, context); } public void routeComplete(HttpClientConnection managedConn, HttpRoute route, HttpContext context) throws IOException { connectionManager.routeComplete(managedConn, route, context); } public void shutdown() { // don't shutdown pool } public void closeIdleConnections(long idleTimeout, TimeUnit tunit) { connectionManager.closeIdleConnections(idleTimeout, tunit); } }; } connectionManager.setDefaultSocketConfig( SocketConfig.custom().setSoTimeout((int) TimeUnit.MINUTES.toMillis(3)).build()); builder.setConnectionManager(nonShutdownableConnectionManager); } return builder; }
From source file:nl.uva.mediamosa.impl.MediaMosaImpl.java
private HttpClient getHttpClient() { HttpClientBuilder b = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore); SSLContext sslContext = null; try {/*from w w w .j a va 2s .com*/ sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { log.warn("Unexpected error occurerd while setting up SSL context", e); } b.setSSLContext(sslContext); HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); // allows multi-threaded use PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); b.setConnectionManager(connMgr); return b.build(); }
From source file:io.cloudslang.content.httpclient.ScoreHttpClient.java
public HttpComponents buildHttpComponents(HttpClientInputs httpClientInputs) { buildDefaultServices();//from w w w . ja v a2 s. c om URI uri = uriBuilder.setUrl(httpClientInputs.getUrl()).setQueryParams(httpClientInputs.getQueryParams()) .setQueryParamsAreURLEncoded(httpClientInputs.getQueryParamsAreURLEncoded()) .setQueryParamsAreFormEncoded(httpClientInputs.getQueryParamsAreFormEncoded()).buildURI(); ContentType theContentType = contentTypeBuilder.setContentType(httpClientInputs.getContentType()) .setRequestCharacterSet(httpClientInputs.getRequestCharacterSet()).buildContentType(); HttpEntity httpEntity = httpEntityBuilder.setFormParams(httpClientInputs.getFormParams()) .setFormParamsAreURLEncoded(httpClientInputs.getFormParamsAreURLEncoded()) .setBody(httpClientInputs.getBody()).setFilePath(httpClientInputs.getSourceFile()) .setContentType(theContentType) .setMultipartValuesAreURLEncoded(httpClientInputs.getMultipartValuesAreURLEncoded()) .setMultipartBodies(httpClientInputs.getMultipartBodies()) .setMultipartFiles(httpClientInputs.getMultipartFiles()) .setMultipartBodiesContentType(httpClientInputs.getMultipartBodiesContentType()) .setMultipartFilesContentType(httpClientInputs.getMultipartFilesContentType()) .setChunkedRequestEntity(httpClientInputs.getChunkedRequestEntity()).buildEntity(); HttpRequestBase httpRequestBase = requestBuilder.setMethod(httpClientInputs.getMethod()).setUri(uri) .setEntity(httpEntity).build(); List<Header> theHeaders = headersBuilder.setHeaders(httpClientInputs.getHeaders()) .setContentType(theContentType) .setEntityContentType(httpEntity != null ? httpEntity.getContentType() : null).buildHeaders(); RequestConfig requestConfig = requestConfigBuilder .setConnectionTimeout(httpClientInputs.getConnectTimeout()) .setSocketTimeout(httpClientInputs.getSocketTimeout()) .setFollowRedirects(httpClientInputs.getFollowRedirects()) .setProxyHost(httpClientInputs.getProxyHost()).setProxyPort(httpClientInputs.getProxyPort()) .buildRequestConfig(); httpRequestBase.setConfig(requestConfig); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); AuthTypes authTypes = new AuthTypes(httpClientInputs.getAuthType()); CredentialsProvider credentialsProvider = credentialsProviderBuilder.setAuthTypes(authTypes) .setUsername(httpClientInputs.getUsername()).setPassword(httpClientInputs.getPassword()) .setHost(uri.getHost()).setPort(String.valueOf(uri.getPort())) .setProxyUsername(httpClientInputs.getProxyUsername()) .setProxyPassword(httpClientInputs.getProxyPassword()).setProxyHost(httpClientInputs.getProxyHost()) .setProxyPort(httpClientInputs.getProxyPort()).buildCredentialsProvider(); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); Lookup<AuthSchemeProvider> authSchemeLookup = authSchemeProviderLookupBuilder.setAuthTypes(authTypes) .setHost(uri.getHost()).setHeaders(theHeaders) .setSkipPortAtKerberosDatabaseLookup(httpClientInputs.getKerberosSkipPortCheck()) .setKerberosConfigFile(httpClientInputs.getKerberosConfFile()) .setKerberosLoginConfigFile(httpClientInputs.getKerberosLoginConfFile()) .setUsername(httpClientInputs.getUsername()).setPassword(httpClientInputs.getPassword()) .buildAuthSchemeProviderLookup(); httpClientBuilder.setDefaultAuthSchemeRegistry(authSchemeLookup); httpRequestBase.setHeaders(theHeaders.toArray(new Header[theHeaders.size()])); CookieStore cookieStore = cookieStoreBuilder.setUseCookies(httpClientInputs.getUseCookies()) .setCookieStoreSessionObject(httpClientInputs.getCookieStoreSessionObject()).buildCookieStore(); if (cookieStore != null) { httpClientBuilder.setDefaultCookieStore(cookieStore); } SSLConnectionSocketFactory sslConnectionSocketFactory = sslConnectionSocketFactoryBuilder .setTrustAllRoots(httpClientInputs.getTrustAllRoots()).setKeystore(httpClientInputs.getKeystore()) .setKeystorePassword(httpClientInputs.getKeystorePassword()) .setTrustKeystore(httpClientInputs.getTrustKeystore()) .setTrustPassword(httpClientInputs.getTrustPassword()) .setX509HostnameVerifier(httpClientInputs.getX509HostnameVerifier()).build(); String connectionKey = ConnectionManagerBuilder.buildConnectionManagerMapKey( httpClientInputs.getTrustAllRoots(), httpClientInputs.getX509HostnameVerifier(), httpClientInputs.getKeystore(), httpClientInputs.getTrustKeystore()); PoolingHttpClientConnectionManager connManager = poolingHttpClientConnectionManagerBuilder .setConnectionManagerMapKey(connectionKey) .setConnectionPoolHolder(httpClientInputs.getConnectionPoolSessionObject()) .setSslsf(sslConnectionSocketFactory) .setDefaultMaxPerRoute(httpClientInputs.getConnectionsMaxPerRoute()) .setTotalMax(httpClientInputs.getConnectionsMaxTotal()).buildConnectionManager(); httpClientBuilder.setConnectionManager(connManager); if (StringUtils.isEmpty(httpClientInputs.getKeepAlive()) || Boolean.parseBoolean(httpClientInputs.getKeepAlive())) { httpClientBuilder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE); } else { httpClientBuilder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE); } CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); HttpClientContext context = contextBuilder.setAuthSchemeLookup(authSchemeLookup).setAuthTypes(authTypes) .setCredentialsProvider(credentialsProvider).setUri(uri) .setPreemptiveAuth(httpClientInputs.getPreemptiveAuth()).build(); HttpComponents result = new HttpComponents(); result.setCloseableHttpClient(closeableHttpClient); result.setHttpRequestBase(httpRequestBase); result.setHttpClientContext(context); result.setUri(uri); result.setConnManager(connManager); result.setCookieStore(cookieStore); result.setHttpClientBuilder(httpClientBuilder); return result; }
From source file:org.openscore.content.httpclient.ScoreHttpClient.java
public HttpComponents buildHttpComponents(HttpClientInputs httpClientInputs) { buildDefaultServices();/* www . j a v a 2 s.c o m*/ URI uri = uriBuilder.setUrl(httpClientInputs.getUrl()).setQueryParams(httpClientInputs.getQueryParams()) .setQueryParamsAreURLEncoded(httpClientInputs.getQueryParamsAreURLEncoded()).buildURI(); ContentType theContentType = contentTypeBuilder.setContentType(httpClientInputs.getContentType()) .setRequestCharacterSet(httpClientInputs.getRequestCharacterSet()).buildContentType(); HttpEntity httpEntity = httpEntityBuilder.setFormParams(httpClientInputs.getFormParams()) .setFormParamsAreURLEncoded(httpClientInputs.getFormParamsAreURLEncoded()) .setBody(httpClientInputs.getBody()).setFilePath(httpClientInputs.getSourceFile()) .setContentType(theContentType) .setMultipartValuesAreURLEncoded(httpClientInputs.getMultipartValuesAreURLEncoded()) .setMultipartBodies(httpClientInputs.getMultipartBodies()) .setMultipartFiles(httpClientInputs.getMultipartFiles()) .setMultipartBodiesContentType(httpClientInputs.getMultipartBodiesContentType()) .setMultipartFilesContentType(httpClientInputs.getMultipartFilesContentType()) .setChunkedRequestEntity(httpClientInputs.getChunkedRequestEntity()).buildEntity(); HttpRequestBase httpRequestBase = requestBuilder.setMethod(httpClientInputs.getMethod()).setUri(uri) .setEntity(httpEntity).build(); List<Header> theHeaders = headersBuilder.setHeaders(httpClientInputs.getHeaders()) .setContentType(theContentType) .setEntityContentType(httpEntity != null ? httpEntity.getContentType() : null).buildHeaders(); RequestConfig requestConfig = requestConfigBuilder .setConnectionTimeout(httpClientInputs.getConnectTimeout()) .setSocketTimeout(httpClientInputs.getSocketTimeout()) .setFollowRedirects(httpClientInputs.getFollowRedirects()) .setProxyHost(httpClientInputs.getProxyHost()).setProxyPort(httpClientInputs.getProxyPort()) .buildRequestConfig(); httpRequestBase.setConfig(requestConfig); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); AuthTypes authTypes = new AuthTypes(httpClientInputs.getAuthType()); CredentialsProvider credentialsProvider = credentialsProviderBuilder.setAuthTypes(authTypes) .setUsername(httpClientInputs.getUsername()).setPassword(httpClientInputs.getPassword()) .setHost(uri.getHost()).setPort(String.valueOf(uri.getPort())) .setProxyUsername(httpClientInputs.getProxyUsername()) .setProxyPassword(httpClientInputs.getProxyPassword()).setProxyHost(httpClientInputs.getProxyHost()) .setProxyPort(httpClientInputs.getProxyPort()).buildCredentialsProvider(); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); Lookup<AuthSchemeProvider> authSchemeLookup = authSchemeProviderLookupBuilder.setAuthTypes(authTypes) .setHost(uri.getHost()).setHeaders(theHeaders) .setSkipPortAtKerberosDatabaseLookup(httpClientInputs.getKerberosSkipPortCheck()) .setKerberosConfigFile(httpClientInputs.getKerberosConfFile()) .setKerberosLoginConfigFile(httpClientInputs.getKerberosLoginConfFile()) .setUsername(httpClientInputs.getUsername()).setPassword(httpClientInputs.getPassword()) .buildAuthSchemeProviderLookup(); httpClientBuilder.setDefaultAuthSchemeRegistry(authSchemeLookup); httpRequestBase.setHeaders(theHeaders.toArray(new Header[theHeaders.size()])); CookieStore cookieStore = httpClientInputs.getCookieStoreSessionObject() == null ? null : cookieStoreBuilder.setUseCookies(httpClientInputs.getUseCookies()) .setCookieStoreSessionObject(httpClientInputs.getCookieStoreSessionObject()) .buildCookieStore(); if (cookieStore != null) { httpClientBuilder.setDefaultCookieStore(cookieStore); } SSLConnectionSocketFactory sslConnectionSocketFactory = sslConnectionSocketFactoryBuilder .setTrustAllRoots(httpClientInputs.getTrustAllRoots()).setKeystore(httpClientInputs.getKeystore()) .setKeystorePassword(httpClientInputs.getKeystorePassword()) .setTrustKeystore(httpClientInputs.getTrustKeystore()) .setTrustPassword(httpClientInputs.getTrustPassword()) .setX509HostnameVerifier(httpClientInputs.getX509HostnameVerifier()).build(); String connectionKey = ConnectionManagerBuilder.buildConnectionManagerMapKey( httpClientInputs.getTrustAllRoots(), httpClientInputs.getX509HostnameVerifier(), httpClientInputs.getKeystore(), httpClientInputs.getTrustKeystore()); PoolingHttpClientConnectionManager connManager = poolingHttpClientConnectionManagerBuilder .setConnectionManagerMapKey(connectionKey) .setConnectionPoolHolder(httpClientInputs.getConnectionPoolSessionObject()) .setSslsf(sslConnectionSocketFactory) .setDefaultMaxPerRoute(httpClientInputs.getConnectionsMaxPerRoute()) .setTotalMax(httpClientInputs.getConnectionsMaxTotal()).buildConnectionManager(); httpClientBuilder.setConnectionManager(connManager); if (StringUtils.isEmpty(httpClientInputs.getKeepAlive()) || Boolean.parseBoolean(httpClientInputs.getKeepAlive())) { httpClientBuilder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE); } else { httpClientBuilder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE); } CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); HttpClientContext context = contextBuilder.setAuthSchemeLookup(authSchemeLookup).setAuthTypes(authTypes) .setCredentialsProvider(credentialsProvider).setUri(uri) .setPreemptiveAuth(httpClientInputs.getPreemptiveAuth()).build(); HttpComponents result = new HttpComponents(); result.setCloseableHttpClient(closeableHttpClient); result.setHttpRequestBase(httpRequestBase); result.setHttpClientContext(context); result.setUri(uri); result.setConnManager(connManager); result.setCookieStore(cookieStore); return result; }