【发布时间】:2015-02-18 10:52:21
【问题描述】:
我正在尝试编写配置一个网关,它应该接收一个完整的 SOAP 消息,然后将其委托给另一个 SOAP 提供者(包括第一个请求的所有 SOAP 标头)。
到目前为止我做了什么:
1) web.xml
MessageDispatcherServlet with Mapping:
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/appservices/*</url-pattern>
</servlet-mapping>
2) 使用端点映射进行配置
<bean class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
<property name="defaultEndpoint" ref="ws-in-gw"/>
</bean>
3) Spring Integration inbound-gateway 和 outbound-gateway 的配置
<int-ws:inbound-gateway id="ws-in-gw"
request-channel="in"
reply-channel="out"
mapped-request-headers="*" />
<int:channel id="in" />
<int:channel id="out" />
<int-ws:outbound-gateway
id="ws-out-gw-status"
request-channel="in-status"
reply-channel="out-status"
uri="http://${delegationServer}/${delegation.contextroot}/soap/AnotherService"
interceptor="soapEnricher"
</int-ws:outbound-gateway>
<bean id="soapEnricher" class="foo.bar.SoapHeaderEnricher" />
public class SoapHeaderEnricher implements ClientInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
try {
SoapMessage soapMessage = (SoapMessage) messageContext.getRequest();
SoapHeader sh = soapMessage.getSoapHeader();
// can use sh.addHeaderElement(new QName(...)) now, but where are the original Headers???
} catch () {
}
}
我的第一个问题是,原始的 SOAP 标头已被删除,因此我在入站网关处引入了 'mapped-request-headers="*" ' 属性。 当我现在配置窃听器时,我看到收到了标头 (myToken:MySecretToken):
DEBUG 10:46:53 - [Payload DOMSource content=javax.xml.transform.dom.DOMSource@24a6ce98][Headers={errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@43456ff4, myToken:MySecretToken=org.springframework.ws.soap.saaj.SaajSoapHeaderElement@3b91ead, ...}]
这是我测试的 SOAP 消息:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:stat="http://status.service.promakler.provinzial.com/">
<soapenv:Header>
<myToken:MySecretToken xmlns=""
xmlns:myToken="http://foo.bar">12345</myToken:MySecretToken>
</soapenv:Header>
<soapenv:Body>
<stat:getStatus/>
</soapenv:Body>
</soapenv:Envelope>
所以标题现在在我的消息中,但是在 ClientInterceptor 中,没有办法获取标题(只是有效负载)?!我可以添加新的标头,但是如何获得原始标头? 任何人都可以给我一个提示(或者甚至可能有一个更简单的解决方案??)
问候 蒂莫
【问题讨论】: