Skip to content

Instantly share code, notes, and snippets.

@panser
Created July 28, 2022 13:26
Show Gist options
  • Save panser/75687121f848af24af03c0d46907f466 to your computer and use it in GitHub Desktop.
Save panser/75687121f848af24af03c0d46907f466 to your computer and use it in GitHub Desktop.
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();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return requestFactory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment