2014-06-09 64 views
1

我想通過https調用Web服務,我需要包含客戶端證書。我這樣做與SAAJSAAJ包括客戶端證書

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); 
conn = soapConnectionFactory.createConnection(); 
URL endpoint = new URL(urlEndPoint); 
SOAPMessage response = conn.call(msg, endpoint); 

但如何包括客戶端證書?

回答

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()); 
+0

不知道究竟在何處,你在這裏添加的客戶證書 – Leo