我想通过https呼叫Web服务,我需要包含客户端证书。我是用SAAJ做的那样
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
conn = soapConnectionFactory.createConnection();
URL endpoint = new URL(urlEndPoint);
SOAPMessage response = conn.call(msg, endpoint);
但如何包含客户证书?
答案 0 :(得分:0)
我创建
KeyManagerFactory kmf = csm.getKeyManagerFactory();
TrustManagerFactory tmf = csm.getTrustManagerFactory();
SSLContext sslcontext = SSLContexts.custom().useProtocol("SSL").build();
sslcontext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
然后我setDefaultSSLSocketFactory
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());