Apache httpclient: Reading SSL with self-signed certificates

When we try to access SSL sites secured with self-signed certificates using apache httpclient, we get the below exception:

Exception in thread “main” 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

We will attempt to work-around this problem. First, we will run a docker image that has a Tomcat8 with a self-signed certificate (refer to http://palashray.com/tomcat-8-ssl-configuration-with-self-signed-certificate/).

Check that the link is accessible: https://localhost:9090/docs/security-howto.html

The below code will ignore the self-signed certificate security issue and allow us to access this site:

Here are the Maven dependencies:

The sources for this example can be found here:




Leave a Reply

Your email address will not be published. Required fields are marked *