我试图使用发送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,添加了信封、标头和正文标记,如
<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>这在中是可能的吗,还是我不应该使用int-ws:outbound-gateway并采取不同的方法呢?
发布于 2016-09-08 20:24:21
您可以添加一个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"));
}发布于 2016-09-08 20:25:32
我想你可以注射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,并使用其getEnvelope()自定义所需的方式。
https://stackoverflow.com/questions/39399377
复制相似问题