Skip to content

Instantly share code, notes, and snippets.

View panser's full-sized avatar

Sergey Panov panser

  • Kiev
View GitHub Profile
public static ClientHttpRequestFactory httpRequestFactoryWithoutSsl() {
TrustStrategy acceptingTrustStrategy = (x509Certificates, s) -> true;
SSLContext sslContext = null;
try {
sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
log.error("problem with creating no-ssl context");
}
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();