Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Soap request messages in Spring Ws to a Server which accepts Soap request messages?

How do I configure my Spring MvC 4 Application with Spring WS to establish a two way SSL connection with a third party such as Bank .I need to exchange my certificates and also verify server certificates and then exchange Soap messages. If any links or code or procedure please kindly update

like image 943
briantaurostack7 Avatar asked May 12 '16 18:05

briantaurostack7


2 Answers

It is possible with Spring-WS. You have to use the WebServiceTemplate API provided by Spring WS. Following is the way to use it.

import java.io.StringReader;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.WebServiceMessageSender;

public class WebServiceClient {

    private static final String MESSAGE =
        "<message xmlns=\"http://tempuri.org\">Hello Web Service World</message>";

    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    public void setDefaultUri(String defaultUri) {
        webServiceTemplate.setDefaultUri(defaultUri);
    }

    // send to the configured default URI
    public void simpleSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    }

    // send to an explicit URI
    public void customSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/AnotherWebService",
            source, result);
    }

}

Please refer this link

And another useful link2

like image 136
Radhakrishna Sharma Gorenta Avatar answered Oct 21 '22 05:10

Radhakrishna Sharma Gorenta


Start your VM with the necessary properties for keystore and trustore as described here in the JSSE doc:

 -Djavax.net.ssl.keyStoreType=yourKeystoreType(jks,pkcs12,etc.)
 -Djavax.net.ssl.trustStoreType=yourTruststoreType(jks,pkcs12,etc.)  
 -Djavax.net.ssl.keyStore=/path/to/your/keystore  
 -Djavax.net.ssl.trustStore=/path/to/your/truststore
 -Djavax.net.debug=ssl  
 -Djavax.net.ssl.keyStorePassword=...  
 -Djavax.net.ssl.trustStorePassword=...

Then in your client code you need to obtain the SSLSocketFactory

SSLSocketFactory sslsocketfactory =(SSLSocketFactory) SSLSocketFactory.getDefault();

and attach it to the WebServiceTemplate (Snippet for creation of HttpClient taken from ClientCustomSSL from apache examples):

WebServiceMessageSender sender = new HttpComponentsMessageSender(HttpClients.custom().setSSLSocketFactory(sslsocketfactory ));
getWebServiceTemplate().setMessageSender(sender);
like image 35
Frank Avatar answered Oct 21 '22 05:10

Frank