Created
April 6, 2017 16:46
-
-
Save cherniag/bbb4a6872b11f0eaadfedcaeca38bf03 to your computer and use it in GitHub Desktop.
CloseableHttpClient with ssl config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RequestConfig requestConfig = RequestConfig.custom() | |
.setConnectTimeout(connectTimeout) | |
.setSocketTimeout(socketTimeout) | |
.build(); | |
HttpClientBuilder httpClientBuilder = HttpClients | |
.custom() | |
.setDefaultRequestConfig(requestConfig) | |
.evictIdleConnections(evictIdleConnectionSeconds, TimeUnit.SECONDS) | |
.setMaxConnPerRoute(maxConnections) | |
.setMaxConnTotal(maxConnections); | |
if (sslEnabled) { | |
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build(); | |
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; | |
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); | |
httpClientBuilder | |
.setSslcontext(sslContext) | |
.setSSLHostnameVerifier(hostnameVerifier) | |
.setSSLSocketFactory(sslSocketFactory); | |
} | |
return httpClientBuilder.build(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment