1

I am trying to integrate an API with a Spring Application deployed in a Tomcat. In order to integrate with that API I just make a GET HTTP on a link to retrieve data from that link, but I receive an error like this:

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
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
  • try to hit the same url from browser. It's probably redirecting to https with 302 status code – Deepak Agarwal Jan 20 '17 at 00:19
  • Possible duplicate of [Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?](http://stackoverflow.com/questions/9619030/resolving-javax-net-ssl-sslhandshakeexception-sun-security-validator-validatore) – Evan Knowles Jan 20 '17 at 08:42

2 Answers2

0

You API must be on SSL. You need to configure the SSL certificate/keystore in the tomcat.

For example:

-Djavax.net.ssl.trustStore=C:\keystore\.keystore
-Djavax.net.ssl.trustStorePassword=changeit

Alternatively, you can add your certificate to Java cacert.

Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

Community
  • 1
  • 1
amant singh
  • 488
  • 5
  • 12
0

Refer detailed GUIDE and follow these steps

  1. get root certificate of your network
  2. install that certificate to java cacerts of your jre.

NOTE

  1. you are supposed to install your certificate to PATHTOYOURJDK/jre/lib/cacerts.
  2. If you have multiple jdk please confirm you are installing certificate to that particular jre only which your application or code is using.
Community
  • 1
  • 1
positivecrux
  • 1,307
  • 2
  • 16
  • 35