1
votes

I want to use soap web service with this wsdl by java:

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

but this error happens when I run some methods:

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.

I use codes below to do this :

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

And for example use this method from this web service:

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

who can fix this problem? what should I do to fix it for my website?

Also I read these solutions but they can not help me to solve this problem:

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

1

1 Answers

1
votes

this is what I did to fix ValidatorException. First of all get the ceritificate (.cer file) of the website from your browser (because it's using HTTPS). Now, if you're on windows, open CMD and go to jre/bin folder and run this command:

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

-file : path of your .cer file which you got from browser

-alias : a name for this certificate

this command imports the certificate to keystore.jks file after you run, it asks for a password. set a password for keystore.jks. now, in your java code add these lines

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

you can also copy the keystore.jks from jre/bin folder to your project folder and use it from there I think there are better ways but this is what I learnt from other stackoverflow topics and solved my problem.