java - 如何以编程方式设置 Axis 客户端的 SSL 上下文?

标签 java ssl soap axis

在一个非常古老的项目中,我们使用使用 Axis 1.4 开发的客户端来调用 SOAP Web 服务。此 Web 服务使用相互身份验证机制,因此我们在 keystore 中安装了私有(private)证书,在信任库中安装了公钥。

SOAP 客户端在 BPM 流程的任务中使用。我们不能也不想使用 JVM 全局信任库和 keystore 。那么我们就不能以编程方式配置 JVM global trustore 和 keystore:

// Keystore
System.setProperty("javax.net.ssl.keyStore", fileKeystore);
System.setProperty("javax.net.ssl.keyStorePassword", pwdKeystore);
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
// Truststore
System.setProperty("javax.net.ssl.trustStore", fileTruststore);
System.setProperty("javax.net.ssl.trustStorePassword", pwdTruststore);
System.setProperty("javax.net.ssl.trustStoreType", "JKS");

这样的方法将迫使我们在 JVM 属性上同步进程,我们不想这样做。而且,机器上还有其他java进程在运行。

我的问题是:Axis 1.4 是否提供一些 API 来指定用于特定 Web 服务调用的 keystore 和信任库?

最佳答案

好的,通过谷歌搜索,我找到了问题的答案。答案是,仅使用 Axis 1.4 不可能为每个服务调用指定不同的 keystore /信任库。我们需要一个名为 axistools 的外部库.

该库实现了一种特殊类型的EngineConfiguration,允许您为每个服务调用指定一个 keystore 和/或信任库。

下面的例子将是解释性的:

// Setting up the configuration
SSLClientAxisEngineConfig config = new SSLClientAxisEngineConfig();
config.setKeystore("path/to/your/keystore");
config.setKeystoreType("JKS");
config.setKeystorePassword("password");
config.setTruststore("path/to/your/truststore");
config.setTruststoreType("JKS");
config.setTruststorePassword("password");
// Very important: without this method invocation 
// the client won't work at all
config.initialize();

// Calling the web service
URL url = new URL("https://localhost:8443/someService");
WebServiceLocator locator = new WebServiceLocator (config);
WebServiceSoap port = locator.getWebServiceSoap(url);
WebServiceSoapStub stub = (WebServiceSoapStub) port;
stub.serviceMethod();

就这些了,伙计们!!!

关于java - 如何以编程方式设置 Axis 客户端的 SSL 上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30827978/

相关文章:

web-services - 使用 JAX-WS 修改 Web 服务的响应

Ruby net/imap 获取 OpenSSL::SSL::SSLError - 自签名证书?

c# - 在 SOAP 请求中添加 KeyInfo 引用

java - 一种在 Eclipse 中按部分包定义搜索的方法?

java - 解析直播广播的 RTSP 流

java - 虚拟主机 Apache 和 Tomcat

ruby - 如何在 Ruby 中编写一个简单的 HTTPS 代理服务器?

c# - 即使调用了 beforesendrequest 方法,SOAP header 也强制使用 Mustunderstand = 1

java - 方法调用有 .class 作为参数吗?

java - 使用包含小数的数字通配符检查文件夹是否存在