http GET失败,错误为javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败

时间:2017-01-19 21:55:12

标签: java spring ssl

我正在尝试将API与部署在Tomcat中的Spring应用程序集成。为了与该API集成,我只需在链接上创建GET HTTP以从该链接检索数据,但是我收到如下错误:

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)

2 个答案:

答案 0 :(得分:0)

您的API必须在SSL上。您需要在tomcat中配置SSL证书/密钥库。

例如:

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

或者,您可以将证书添加到Java cacert。

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

答案 1 :(得分:0)

请参阅详细GUIDE并按照以下步骤操作

  1. 获取网络的根证书
  2. 将该证书安装到jre的java cacerts。
  3. 请注意

    1. 您应该将证书安装到PATHTOYOURJDK / jre / lib / cacerts。
    2. 如果您有多个jdk,请确认您正在为您的应用程序或代码正在使用的特定jre安装证书。