I was recently working on writing some client code which makes multiple webservices calls. The stubs for both my client were generated using Axis2. I had to make requests to 2 different services, where one of the service was serving a dummy SSL certificate and the other one was serving a valid SSL certificate.
I landed up getting the following exception,
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
Here are the steps I took to overcome this error,
Bypass SSL security checkI googled and got several links on how to bypass the SSL security check in Java. Most of them were suggesting to use XTrustProvider.install() to turn off SSL check. After implementing this solution the error went away if I invoked only the service which was serving a dummy SSL certificate. When I tried using both the services I again got caught with the same exception, though I tried ignoring the SSL check in the 2nd service. Axis2 actually for some reason "reuses" or caches the security certificate and the SSL socket factory is singleton. So use this class only if you are using a single service.
Use the following InstallCert.java to generate your certificate and tell your SSL socket factory to use this trust store like this. Note: Add this line before the call to your first service, else you will end up in the same exception.