[Solved] javax.net.ssl.sslhandshakeexception

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

Sometime you might have received this kind of exception while running your application. The main reason behind this error is, the URL you are trying to access have no valid certificate issued from an authorized CA. In such cases you have to add those certificates to your JRE to make it a valid one. By using the following steps, you can make it working.
Steps:
  1. Download security certificate from Server
    1. Open the URL from IE
    2. You will get a certificate related warning message. Click on view certificate and then Install certificate. Ignore warning messages if gets displayed.
    3. Now go to Tools->’Internet Options’ ->Content->Certificates.
    4. Locate the installed certificate from the list of certificates.
    5. Click “export” button and save it as “DER encoded binary” in somewhere in your PC.
  2. Add certificate to JRE
    1. Open a Command Prompt.
    2. Go to “bin” directory of your JRE.
    3. Use keytool command as follows to import the certificate to JRE.
      • keytool -import -alias mycertificate -keystore ..\lib\security\cacerts -file c:\mycert.cer
      • It will ask for a password. By default the password is “changeit“.
      • Here I assume that your certificate is saved as “mycert.cer” in “c:\” directory.
Thats all. You have successfully added the SSL certificate to your JRE.
To confirm this use the following command.
keytool -list
It will display all the certificates added to the JRE cert.

Leave a Reply

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