[英]How to disable SSL certificate checking with Spring RestTemplate?
[英]How to disable SSL certificate checking with Spring WebServiceTemplate?
为了在开发环境中进行测试,我想忽略我的开发服务器的https
证书问题。
我的Web服务客户端得到: -
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
有许多类似的问题帮助我找到了解决方案,但我想我会在这里为任何需要它的人发布这个具体问题的答案....
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; }
}
接着
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);
(需要spring-ws-support)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.