在我运行以下代码时出现错误:
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
我已尝试将证书添加到 JDK 的 CAcerts keystore ,但错误没有任何变化。无论如何,他们是否要弄清楚它正在读取哪个 keystore ?或者是其他问题?
public static void main(String args[]) throws Exception {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
String url = "https://www.mywebservice.com/ws";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(),url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
谢谢,我很乐意提供所需的任何其他详细信息。
最佳答案
您必须将服务器证书或根 CA 添加到 JDK 使用的信任库中。默认情况下使用 jre/lib/security/cacerts
。
如果您已经导入了服务器证书,请确认您确实使用了正确的 JDK,或者证书已成功导入。您可以使用类似 http://www.keystore-explorer.org/ 的 GUI 工具或者使用 key 工具
您还可以使用包含服务器证书的 JKS 文件来使用自己的信任库(推荐)。这样配置使用
System.setProperty ("javax.net.ssl.trustStore", path_to_your_trustore_jks_file);
System.setProperty ("javax.net.ssl.trustStorePassword", "password");
关于java - 太阳.security.provider.certpath.SunCertPathBuilderException : unable to find valid certification path to requested target error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38426695/