我必须在java.which中为soap web服务创建客户端代码,输入为基本身份验证和ssl证书。我无法通过邮寄请求找到附加证书的方法。您可以告诉我如何使用邮政请求附上证书和密码
答案 0 :(得分:0)
如果您使用的是apache CXF,此代码可能会对您有所帮助:
Client client = ClientProxy.getClient(service);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
TLSClientParameters tlsConfig = new TLSClientParameters();
try {
//Set up the keyStore for CXF
InputStream keyStoreInputStream = new FileOrClasspathResource(keyStorePath).openStream();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(keyStoreInputStream, keyStorePassword.toCharArray());
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(keyStore);
TrustManager[] tm = trustFactory.getTrustManagers();
tlsConfig.setTrustManagers(tm);
} catch (Exception e) {
log.error("Couldn't initialize keyStore with name " + keyStorePath, e);
}
httpConduit.setTlsClientParameters(tlsConfig);