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
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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With