如何使用Web Service使用者配置Spring MVC 4以两种方式通过SSL发送和接收肥皂消息?
问题内容:
我试图使用Spring Ws通过两种方式配置Spring MVC SSL以连接到第三方,但是由于缺乏文档,我决定将Spring MVC 4
Application与Web Service Consumer集成。我是Web Service消费的初学者。我想知道
如何使用基于批注的配置来配置带有Web服务使用者的Spring MVC
4应用程序,以实现与第三方的双向SSl通信,并在将其肥皂消息发送到https服务器之前对其进行加密?示例代码将很有帮助 。另外,如果WSDL位于aa
https链接中,那么如何生成类?
问题答案:
这个问题很大。没有简单的解决方案
我可以提供步骤和手册指南
1)解决CXF依赖项以在您的项目中包含库
使用Maven,Ivy或下载。您需要jax-ws和相关的 http://cxf.apache.org/docs/using-cxf-with-
maven.html
2)使用wsdl2java生成Java客户端到您的wsdl
例如
wsdl2java -p com.mycompany.greeting Greeting.wsdl
http://cxf.apache.org/docs/wsdl-to-
java.html
3)以编程方式创建jax-ws
wdsl2java已为您完成了工作 http://cxf.apache.org/docs/how-do-i-develop-a-
client.html#HowdoIdevelopaclient?-JAX-WSProxy
HelloService service = new HelloService();
Hello helloClient = service.getHelloHttpPort();
String result = helloClient .sayHi("Joe");
注意:也可以通过弹簧进行配置
4)使用客户端证书配置身份验证
这是艰难的一步 http://cxf.apache.org/docs/client-http-transport-includes-ssl-
support.html#ClientHTTPTransport(包括SSLsupport)-配置SSLSupport
定义参考您的证书的管道文件。这是一个例子
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xmlns:sec="http://cxf.apache.org/configuration/security"
xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<http-conf:conduit name="*.http-conduit">
<http-conf:tlsClientParameters disableCNCheck="true" secureSocketProtocol="TLS">
<sec:keyManagers keyPassword="password" >
<sec:keyStore type="pkcs12" password="password"
file="yourcertificate.p12" />
</sec:keyManagers> </http-conf:tlsClientParameters>
<http-conf:client Connection="Keep-Alive" MaxRetransmits="1" AllowChunking="false" />
</http-conf:conduit>
</beans>
如果您喜欢以编程方式进行操作,则可以
Client client = ClientProxy.getClient(helloClient);
HTTPConduit http = (HTTPConduit) client.getConduit();
//set the parameters in a similar way to file