使用 wsimport 创建 SOAP 客户端但无法使用 SSL 证书

Using wsimport to create a SOAP client but unable to get it to work with SSL certificate

自从我不得不进行任何 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

不兼容

这似乎是一个众所周知的错误,但是,尝试:

  1. 升级org.apache.ws.commons.schema.XmlSchemaCollection
  2. 添加此代码:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("https://blwq-auth.betasys.com/tsaproxyservice/soaproxy.asmx?wsdl");
factory.setServiceClass(SoaProxySoap.class);
SoaProxySoap servicePort = (SoaProxySoap) factory.create();
  1. 或者在我的 Manifest.mf 和管理控制台中将 DisableIBMJAXWSEngine 设置为 true 似乎不起作用。

有谁知道让 SOAP 客户端使用 SSL 证书的最快、最简单的方法,无论是使用 JAX-WS 本身还是使用 CXF?谢谢!!!

假设客户端应用程序 运行 在 WebSphere 内部,来自 Web 服务的证书需要添加到 WebSphere 的信任库中。我在这里找到了执行此操作的过程:https://www.ibm.com/support/knowledgecenter/en/SSRMWJ_6.0.0.4/com.ibm.isim.doc_6.0.0.4/installing/tsk/tsk_ic_config_was_ssl_dbservr.htm(不同的产品,但过程相同。)