sun.security.validator.ValidatorException 当 java 使用 Web 服务方法时

sun.security.validator.ValidatorException when use web service methods by java

我想通过 java 将 soap 网络服务与此 wsdl 一起使用:

https://sadad.shaparak.ir/services/MerchantUtility.asmx?wsdl

但是当我运行一些方法时会发生这个错误:

Failed to access the WSDL at: https://sadad.shaparak.ir/services/MerchantUtility.asmx?wsdl. It failed with: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

我使用下面的代码来做到这一点:

MerchantUtilitySoap port;
MerchantUtility service = new MerchantUtility();
port = service.getMerchantUtilitySoap();

例如,通过此网络服务使用此方法:

long timeStamp = Long.parseLong(port.calcTimeStamp());

谁能解决这个问题?我应该如何修复我的网站?

我也阅读了这些解决方案,但它们不能帮助我解决这个问题:

javax.xml.ws.WebServiceException: Failed to access the WSDL

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

"PKIX path building failed" and "unable to find valid certification path to requested target"

http://www.java-samples.com/showtutorial.php?tutorialid=210

这就是我修复 ValidatorException 所做的工作。 首先从您的浏览器获取网站的证书(.cer 文件)(因为它使用的是 HTTPS)。 现在,如果您使用的是 windows,请打开 CMD 并转到 jre/bin 文件夹和 运行 此命令:

keytool -importcert -file path/to/certificate.cer -keystore keystore.jks -alias "Alias"

-file : 您从浏览器获得的 .cer 文件的路径

-别名:此证书的名称

此命令将证书导入到 keystore.jks 文件 在您 运行 之后,它会要求您输入密码。为 keystore.jks 设置密码。 现在,在您的 java 代码中添加这些行

System.setProperty("javax.net.ssl.trustStore","path/to/keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword","keystore_pass");

您还可以将 keystore.jks 从 jre/bin 文件夹复制到您的项目文件夹并从那里使用它 我认为有更好的方法,但这是我从其他 Whosebug 主题中学到的并解决了我的问题。