我正在尝试使用Spring Integration发送SOAP请求,如
<int:chain input-channel="wsOutChannel" output-channel="stdoutChannel">
<int-ws:header-enricher>
<int-ws:soap-action value="..."/>
</int-ws:header-enricher>
<int-ws:outbound-gateway
uri="..."/>
</int:chain>
但是你只能添加SOAP主体,Spring Integration会添加信封,标题和正文标记,如
<SOAP-ENV:Envelope>
<SOAP-ENV:Header>
<SOAP-ENV:Body>
...
</SOAP-ENV:Body>
<SOAP-ENV:Header>
</SOAP-ENV:Envelope>
我需要使用特定属性自定义信封和标头标记,例如:
<soapenv:Envelope attribute1="value1" attribute2="value2">
和子元素,例如:
<soapenv:Header>
<child>...<child>
<soapenv:Header>
这可以通过Spring Integration Web Services实现,还是应该使用int-ws:outbound-gateway
并采用不同的方法?
答案 0 :(得分:1)
您可以添加ClientInterceptor
(通过interceptor
属性),以便在请求发出之前修改请求。
修改强>
@ Artem的建议比较简单,但拦截器也可以让你访问响应;但无论哪种方式,代码都是相似的。
拦截器:
public class MyInterceptor extends ClientInterceptorAdapter {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
SoapMessage request = (SoapMessage) messageContext.getRequest();
SoapEnvelope envelope = request.getEnvelope();
envelope.addAttribute(new QName("foo"), "bar");
SoapHeader header = envelope.getHeader();
header.addHeaderElement(new QName("http://fiz/buz", "baz"));
return super.handleRequest(messageContext);
}
}
对于回调版本:
@Override
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
SoapEnvelope envelope = ((SoapMessage) message).getEnvelope();
envelope.addAttribute(new QName("foo"), "bar");
SoapHeader header = envelope.getHeader();
header.addHeaderElement(new QName("http://fiz/buz", "baz"));
}
答案 1 :(得分:1)
我可以注入openssl s_client -connect evilcorp.com/webservices:443
:
WebServiceMessageCallback
并将邮件投放到<xsd:attribute name="request-callback" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Reference to a Spring Web Services WebServiceMessageCallback. This enables changing
the Web Service request message after the payload has been written to it but prior
to invocation of the actual Web Service.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.ws.client.core.WebServiceMessageCallback"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
并使用其SoapMessage
自定义所需方式。