How to Configure Spring MVC 4 to send and receive soap messages in two way SSL using Web Service Consumer?

被刻印的时光 ゝ 提交于 2019-12-23 06:00:42

问题


I have tried to configure Spring MVC in two way SSL using Spring Ws to connect to third party but due to the lack of documentation I have decided to integrate my Spring MVC 4 Application with Web Service Consumer .I am a beginner in Web Service consumption.I would like to know how to configure my Spring MVC 4 application with web service consumer with annotation based configuration to achieve a Two way SSl communication with Third party and also encrypt my soap messages before it is sent to the https server ?If any links or sample code would be helpful. Also if the WSDL is located in a a https link how do I generate the classes?


回答1:


This question is huge. There is no a trivial solution

I can provide the steps and guide to the manual

1)Resolve CXF dependencies to include libraries in your project

Use maven, ivy or download. You need jax-ws and related http://cxf.apache.org/docs/using-cxf-with-maven.html

2) Generate a Java client with wsdl2java to your wsdl

For example

wsdl2java -p com.mycompany.greeting Greeting.wsdl

http://cxf.apache.org/docs/wsdl-to-java.html

3) Create the jax-ws programmatically

wdsl2java have done the work for you 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");

Note: It is also possible configure with spring

4) Configure the authentication with client certificate

This is the hard step http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport(includingSSLsupport)-ConfiguringSSLSupport

Define a conduit file with the reference to your certificate. This is an example

<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>

If you prefer to do programmaticaly you can do

Client client = ClientProxy.getClient(helloClient);
HTTPConduit http = (HTTPConduit) client.getConduit();
//set the parameters in a similar way to file


来源:https://stackoverflow.com/questions/37599417/how-to-configure-spring-mvc-4-to-send-and-receive-soap-messages-in-two-way-ssl-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!