如何将 Spring Ws 中的 Soap 请求消息发送到接受 Soap 请求消息的服务器?
How to send Soap request messages in Spring Ws to a Server which accepts Soap request messages?
如何使用 Spring WS 配置我的 Spring MvC 4 应用程序以与银行等第三方建立双向 SSL 连接。我需要交换我的证书并验证服务器证书,然后交换 Soap 消息。如果有任何链接或代码或程序,请更新
按照所述here in the JSSE doc:
,使用密钥库和信任库的必要属性启动您的 VM
-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=...
然后在您的客户端代码中您需要获取 SSLSocketFactory
SSLSocketFactory sslsocketfactory =(SSLSocketFactory) SSLSocketFactory.getDefault();
并将其附加到 WebServiceTemplate(用于创建 HttpClient 的代码段取自 ClientCustomSSL from apache examples):
WebServiceMessageSender sender = new HttpComponentsMessageSender(HttpClients.custom().setSSLSocketFactory(sslsocketfactory ));
getWebServiceTemplate().setMessageSender(sender);
Spring-WS 是可能的。您必须使用 Spring WS 提供的 WebServiceTemplate
API。下面是使用方法。
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);
}
}
请参考这个link
还有一个有用的link2
如何使用 Spring WS 配置我的 Spring MvC 4 应用程序以与银行等第三方建立双向 SSL 连接。我需要交换我的证书并验证服务器证书,然后交换 Soap 消息。如果有任何链接或代码或程序,请更新
按照所述here in the JSSE doc:
,使用密钥库和信任库的必要属性启动您的 VM -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=...
然后在您的客户端代码中您需要获取 SSLSocketFactory
SSLSocketFactory sslsocketfactory =(SSLSocketFactory) SSLSocketFactory.getDefault();
并将其附加到 WebServiceTemplate(用于创建 HttpClient 的代码段取自 ClientCustomSSL from apache examples):
WebServiceMessageSender sender = new HttpComponentsMessageSender(HttpClients.custom().setSSLSocketFactory(sslsocketfactory ));
getWebServiceTemplate().setMessageSender(sender);
Spring-WS 是可能的。您必须使用 Spring WS 提供的 WebServiceTemplate
API。下面是使用方法。
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);
}
}
请参考这个link
还有一个有用的link2