Search code examples
javassljks

Calling WS with SSL in java


I connect to a web service with this client that work fine:

WSCSI WSCS = new WSCSI("http://localhost:8080/ServiceV2/services/WSCSISoap?wsdl","WSCSI","WSCSISoap");
IScoring instance = new ScoringCFA(WSCS);

assertEquals(true, instance.statusService());

I need to use SSL, So i change the url to: https://localhost:8181/ServiceV2/services/WSCSISoap?wsdl

And add this in the VM Options:

-Djavax.net.ssl.trustStore="C:\cacerts.jks"

('Keytool -list -keystore "C:\cacerts.jks', when i run this command i see that the certificate that i need is there)

When i run the client get this error:

java.security.cert.CertificateException: No name matching localhost found.)

Solution

  • That's probably because the cert you're using is issued against a specific hostname (www.myhost.com). Try the solution in this article.
    But be warned, the code sample is only intended for localhost testing, remove it once you move onto the integration/assembly testing on a proper server.