For testing purposes in a development environment, I want to ignore https
certificate problems with my development servers.
My Web Service Client was getting :-
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
There are a number of similar Questions which helped me find the solution, but I thought I would post the answer to this specific question here for anyone who needs it....
class UnTrustworthyTrustManager
implements X509TrustManager
{
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
public void checkServerTrusted(X509Certificate[] arg0, String arg1)throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() { return null; }
}
and then
setDefaultUri("https://myServer/soapws/ws/");
Source requestSource = new ResourceSource(new ClassPathResource("MyRequest.xml"));
StringResult result = new StringResult();
WebServiceTemplate template = getWebServiceTemplate();
HttpsUrlConnectionMessageSender sender = new HttpsUrlConnectionMessageSender();
sender.setTrustManagers(new TrustManager[] { new UnTrustworthyTrustManager() });
template.setMessageSender(sender);
template.sendSourceAndReceiveToResult(requestSource, result);
System.out.println(result);
(requires spring-ws-support)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With