【发布时间】:2020-11-05 07:43:57
【问题描述】:
自从我不得不进行任何 Java 开发以来已经有一段时间了,所以也许我有点生疏了。但是,我的任务是创建将在 IBM HATS (web) 应用程序中调用的 SOAP 客户端。没问题!我使用的是 Rational Application Developer 9.7.0.1,我只是导入了 WSDL 并生成了客户端类。 但是,问题在于该服务需要 SSL 证书。我尝试了很多不同的东西,但我所做的一切都无法让它发挥作用。 除了 RAD 9.7.0.1,我还在使用 WebSphere Application Server 9 和 Java 1.8.0_251。 我只想坚持使用普通的 JAX-WS,而不是引入 CXF/Spring。所以我尝试的第一件事就是设置信任库属性:
System.setProperty("javax.net.ssl.trustStore", "C:\\keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "******");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
这仍然给我一个错误,即找不到证书。
所以我硬着头皮尝试使用 CXF 3.3.7 设置 HTTPS 连接 -
//Set Up SSL Connection
SSLContext sslContext = null;
try
{
KeyStore trustStoreInst = KeyStore.getInstance("JKS");
trustStoreInst.load(CMPIDCASCustom.class.getClassLoader().getResourceAsStream(trustStore),
trustStorePassword.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(trustStoreInst);
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, tmf.getTrustManagers(), new SecureRandom());
}
catch (Exception e)
{
e.printStackTrace();
}
//Call the Service
SoaProxy service = new SoaProxy();
SoaProxySoap servicePort = service.getSoaProxySoap();
BindingProvider provider = (BindingProvider)servicePort;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"https://myurl.com/soaproxy.asmx");
Client client = ClientProxy.getClient(servicePort);
HTTPConduit http = (HTTPConduit) client.getConduit();
TLSClientParameters parameters = new TLSClientParameters();
parameters.setSSLSocketFactory(sslContext.getSocketFactory());
http.setTlsClientParameters(parameters);
UserResponse userResponse = servicePort.retrieveUser(param1, param2);
但是,这样做会给我以下错误: org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler 与 org.apache.cxf.frontend.ClientProxy 不兼容 java.lang.ClassCastException: org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler 与 org.apache.cxf.frontend.ClientProxy 不兼容
这似乎是一个众所周知的错误,但是,尝试:
- 升级 org.apache.ws.commons.schema.XmlSchemaCollection
- 添加此代码:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("https://blwq-auth.betasys.com/tsaproxyservice/soaproxy.asmx?wsdl");
factory.setServiceClass(SoaProxySoap.class);
SoaProxySoap servicePort = (SoaProxySoap) factory.create();
- 或者在我的 Manifest.mf 和管理控制台中将 DisableIBMJAXWSEngine 设置为 true 似乎不起作用。
有没有人知道让 SOAP 客户端使用 SSL 证书的最快、最简单的方法,无论是使用 JAX-WS 本身还是使用 CXF?谢谢!!!
【问题讨论】:
标签: ssl soap websphere cxf jax-ws