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!!!