0
votes

I created one JAX-WS client using one wsdl file. All works fine at localhost but not on server. I'm getting Caused by: javax.net.ssl.SSLHandshakeException ... Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator

I know, that my JAX-WS client doesn't trust the certificate.So I found one quick and dirty solution here: http://ws.apache.org/xmlrpc/ssl.html and tried to implement it:

ApiVersion1Service apiVersion1Service = new ApiVersion1Service(wsdlURL, SERVICE_NAME);
    APIport = apiVersion1Service.getApiVersion1Port();

    // SOAP Header
    BindingProvider bindingProvider = (BindingProvider) APIport;
    Binding binding = bindingProvider.getBinding();
    Map<String, Object> requestContext = bindingProvider.getRequestContext();

    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL + accountID);
    List<Handler> handlers = binding.getHandlerChain();
    handlers.add(new SOAPAuthenticationHandler(username, password));
    binding.setHandlerChain(handlers);

    // SSL
    SSLContext context = SSLContext.getInstance("SSL");
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
        public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
            return;
        }
        public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
            return;
        }
    } };
    context.init(null, trustAllCerts, new SecureRandom());
    SSLSocketFactory sslSocketFactory = context.getSocketFactory(); 
    bindingProvider.getRequestContext().put(/*JAXWSProperties.SSL_SOCKET_FACTORY*/ "com.sun.xml.ws.transport.https.client.SSLSocketFactory" , sslSocketFactory);

.... but I still get the SSLHandshakeException. Do you have any idea? Thanks for all your help!!!

1
Not sure if this will work but after the context.init add a line: SSLContext.setDefault(context); - Xargos
Have you tried running with -Djavax.net.debug=all ? Follow through the trace carefully and it will become very apparent what your next question to ask should be :-) - user924272

1 Answers

-1
votes
public class VerifyEverythingHostnameVerifier
        implements HostnameVerifier {

    @Override
    public boolean verify(String string, SSLSession sslSession) {
        return true;
    }
}

Using:

 HttpsURLConnection.setDefaultHostnameVerifier(new VerifyEverythingHostnameVerifier());