Ignorar certificado SSL em um servlet
Estou recebendo a seguinte exceção:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Eu fiz algumas pesquisas e alterei meu código de conexão:
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
CloseableHttpClient client = HttpClients.custom()
.setRedirectStrategy(new LaxRedirectStrategy())
.setSslcontext(sslContext)
.setConnectionManager(connMgr)
.build();
Isso corrigiu o problema até agora, não estou mais recebendo a exceção e a conexão funciona.
O problema surge novamente quando eu uso o mesmo código em um Servlet em execução no Tomcat.
Por quê ?