【问题标题】:http GET failed with error javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failedhttp GET 失败并出现错误 javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败
【发布时间】:2017-06-04 18:43:31
【问题描述】:

我正在尝试将 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)

【问题讨论】:

标签: java spring ssl


【解决方案1】:

您的 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?

【讨论】:

    【解决方案2】:

    参考详细的GUIDE 并按照以下步骤操作

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

    注意

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-24
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 2021-11-27
      • 2022-11-10
      相关资源
      最近更新 更多