Skip to content

Instantly share code, notes, and snippets.

@cherniag
Created April 6, 2017 16:46
Show Gist options
  • Save cherniag/bbb4a6872b11f0eaadfedcaeca38bf03 to your computer and use it in GitHub Desktop.
Save cherniag/bbb4a6872b11f0eaadfedcaeca38bf03 to your computer and use it in GitHub Desktop.
CloseableHttpClient with ssl config
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