Quantcast
Channel: Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error? - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Answer by AutomatedMike for Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

$
0
0

None of the previous answers worked for me using Spring 5 in the situation where I don't control the code making the http connection.

The following code disables SSL Certificate verification for all new RestTemplates:

@Beanpublic RestTemplateCustomizer restTemplateCustomizer() {    return restTemplate -> {        try {            SSLContext sslContext = SSLContextBuilder.create()                    .loadTrustMaterial((TrustStrategy) (chain, authType) -> true)                    .build();            SSLConnectionSocketFactory socketFactory =                     new SSLConnectionSocketFactory(                        sslContext, NoopHostnameVerifier.INSTANCE);            PoolingHttpClientConnectionManager connectionManager =                     PoolingHttpClientConnectionManagerBuilder.create()                        .setSSLSocketFactory(socketFactory)                        .build();            CloseableHttpClient httpClient = HttpClients.custom()                    .setConnectionManager(connectionManager)                    .build();            HttpComponentsClientHttpRequestFactory requestFactory =                     new HttpComponentsClientHttpRequestFactory(httpClient);            restTemplate.setRequestFactory(requestFactory);        } catch (Exception e) {            e.printStackTrace();        }    };

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>