java - 太阳.security.provider.certpath.SunCertPathBuilderException : unable to find valid certification path to requested target error

标签 java ssl soap keystore

在我运行以下代码时出现错误:

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/

相关文章:

java - PNG 到 GeoJSON(或类似格式)

java - 组织 JBehave 故事

ios - react native ssl 固定

java - "openTlsConnect"CA 和 openTlsConnect 认证

php - PHP 中的 SOAP 服务器 - 如何编写 WSDL 文件 - 技巧

c# - 序列化通过 SOAP 发送的对象

java - Hibernate:使用子选择和左外连接执行条件查询?

java - 如何杀死从第三方库导入的线程?

ssl - 当 HTTPS 站点使用 "ISRG Root X1"CA 时,Python3.4+requests 2.26 无法验证 SSL 证书 - 为什么?

python - 是否存在 Python 3 SOAP 客户端模块?