javax.net.ssl.SSLHandshakeException: (...)
unable to find valid certification path to requested target
Andreas Sterbenz provides a very nice guide that shows you how to add a self-signed SSL certificate to the keystore with your app's trusted certificates. It basically comes down to 4 steps:
- Use his InstallCert java program to make a request to the host with the SSL certificate you want to trust. Assuming the host address "somehost.com" and the port for the SSL connection is "8443", you should compile the InstallCert.java file and execute it with these parameters:
java InstallCert somehost.com:8443
- Following the instructions on the guide, after the exception you should receive a list of SSL certificates from the host. If you decide to trust one of them, pick the number corresponding to that certificate.
- If you picked one of the available certificates, the InstallCert program will generate a file called jssecacerts on the directory where you executed the program.
- To use the newly added certificate when establishing SSL connections to "somehost.com", add the following line your java application:
System.setProperty("javax.net.ssl.trustStore", "path/to/jssecacerts");
where "path/to/" represents the full path to your jssecacerts file