web-services - 如何配置 Spring MVC 4 以使用 Web 服务使用者以两种方式 SSL 发送和接收 soap 消息?

标签 web-services spring-mvc ssl cxf soap-client

我尝试使用 Spring Ws 以两种方式配置 Spring MVC 以连接到第三方,但由于缺乏文档,我决定将我的 Spring MVC 4 应用程序与 Web 服务消费者集成。我是 Web 的初学者服务消费。我想知道如何配置我的 Spring MVC 4 应用程序和 Web 服务消费者以及基于注释的配置,以实现与第三方的双向 SSl 通信,并在发送到 https 之前加密我的 soap 消息服务器?如果有任何链接或示例代码会有所帮助。 另外,如果 WSDL 位于 https 链接中,我该如何生成类?

最佳答案

这个问题很大。没有简单的解决方案

我可以提供手册的步骤和指南

1)解决 CXF 依赖关系以在您的项目中包含库

使用 maven、ivy 或下载。你需要 jax-ws 和相关的 http://cxf.apache.org/docs/using-cxf-with-maven.html

2) 使用 wsdl2java 为您的 wsdl 生成一个 Java 客户端

例如

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");

注意:也可以用spring配置

4)使用客户端证书配置身份验证

这是艰难的一步 http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport(includingSSLsupport)-ConfiguringSSLSupport

使用对您的证书的引用定义管道文件。这是一个例子

<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

关于web-services - 如何配置 Spring MVC 4 以使用 Web 服务使用者以两种方式 SSL 发送和接收 soap 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599417/

相关文章:

java - Spring Hibernate MySQL 初始化

asp.net - 我能否从网站代码中检测 ASP.NET 网站是否启用了 SSL/https?

java - 如何优雅地检测 SSL

ssl - 在lighttpd上配置https

c# - 在acumatica中使用webservices api导出数据时如何设置超时

ios - 我们可以在Apple Watch上使用网络服务吗?

java - 测试 JPA 实体

java - 使用GenericsDAO + SpringMVC + Hibernate报错

web-services - 为什么/如何 SOAP 是有状态的?

php - 如何在我的 Android 应用程序中收听互联网连接的变化?