我实现了一个Spring-WS Web服务客户端,我发送一个请求而不需要解开封装,因为我发送的是一个现成的带有所有SOAP封装的签名(wssec)请求。
比如说,我发送了一个现成的有签名的(wssec)请求。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security wsu:Id="Id-sec-98b44dc4123d94b309db4e47881c48c0cfde" SOAP-ENV:actor="http://smev.gosuslugi.ru/actors/smev">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="Id-sig-02747f3e4b2c3afbd9ee0c47b82df6ce1ce1">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256"/>
<Reference URI="#Id-wssecdata-d8392bad08e2095ea110d7ebdf6cb20b77f0" Id="Id-dataref-2f98695f5d03929ba61e8553e17275e99ea0">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256"/>
<DigestValue>DIGECT</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>SIG_VALUE</SignatureValue>
<KeyInfo Id="Id-keyinfo-60c321e68eba4e0b869013c3b661a255d39a">
<wsse:SecurityTokenReference wsu:Id="Id-strT8lVAuhyhE9ORsox">
<wsse:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#Id-bstKf4S_QPNjJpr839_"/>
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
<wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="Id-bstKf4S_QPNjJpr839_">CERT</wsse:BinarySecurityToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body wsu:Id="Id-wssecdata-d8392bad08e2095ea110d7ebdf6cb20b77f0">
<Message/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是根据定义的算法 Spring-WS文件,Spring-WS还通过调用我的请求,将我的请求封装在信封中。createWebServiceMessage()
在 WebServiceTemplate
.
发送的结果如下。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security wsu:Id="Id-sec-98b44dc4123d94b309db4e47881c48c0cfde" SOAP-ENV:actor="http://smev.gosuslugi.ru/actors/smev">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="Id-sig-02747f3e4b2c3afbd9ee0c47b82df6ce1ce1">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256"/>
<Reference URI="#Id-wssecdata-d8392bad08e2095ea110d7ebdf6cb20b77f0" Id="Id-dataref-2f98695f5d03929ba61e8553e17275e99ea0">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256"/>
<DigestValue>DIGECT</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>SIG_VALUE</SignatureValue>
<KeyInfo Id="Id-keyinfo-60c321e68eba4e0b869013c3b661a255d39a">
<wsse:SecurityTokenReference wsu:Id="Id-strT8lVAuhyhE9ORsox">
<wsse:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#Id-bstKf4S_QPNjJpr839_"/>
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
<wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="Id-bstKf4S_QPNjJpr839_">CERT</wsse:BinarySecurityToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body wsu:Id="Id-wssecdata-d8392bad08e2095ea110d7ebdf6cb20b77f0">
<Message/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我是这样做的
public void callWebService(String request) {
StreamSource source = new StreamSource(new StringReader(request));
StreamResult result = new StreamResult(System.out);
getWebServiceTemplate().sendSourceAndReceiveToResult(source, webServiceMessage -> {
SaajSoapMessage saajMessage = (SaajSoapMessage) webServiceMessage;
saajMessage.setSoapAction(SOAP_ACTION);
}, result);
在我看来,使用SAAJ没有任何帮助。我如何发送我的请求?谢谢!我实现了一个Spring-WS Web服务客户端,我发送了一个请求。
我自己找到了一个解决方案 它包括建立一个新的SAAJ消息并将其替换为旧的。希望有人能帮助我。
public void callWebService(String request) {
StreamSource source = new StreamSource(new StringReader(request));
StreamResult result = new StreamResult(System.out);
getWebServiceTemplate().sendSourceAndReceiveToResult(source, webServiceMessage -> {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) webServiceMessage;
try {
SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();
SOAPBody soapBody = soapPart.getEnvelope().getBody();
Document innerSoapBody = soapBody.extractContentAsDocument();
//Строим новое SAAJ-сообщение for webServiceMessage
MessageFactory soapMessageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = soapMessageFactory.createMessage();
soapMessage.getSOAPPart().setContent(new DOMSource(innerSoapBody));
((SaajSoapMessage) webServiceMessage).setSaajMessage(soapMessage);
} catch (SOAPException e) {
LOGGER.error("Can't rebuild WebServiceMessage in SMEV2 invoke!");
e.printStackTrace();
}
//Передаим корректный SOAP-Action.
saajSoapMessage.setSoapAction(SMEV2_SOAP_ACTION);
}, result);