Spring集成应该路由消息(使用SOAP标头)

时间:2015-02-18 10:52:21

标签: soap spring-integration

我正在尝试编写配置网关,它应该接受完整的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 Headers已被切断,因此我在入站网关中引入了“mapped-request-headers =”*“'属性。 当我现在配置一个窃听时,我看到收到了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>

所以Headers现在在我的Message中,但在ClientInterceptor中,没有办法获取Headers(只是有效载荷)?!我可以添加新的标题,但我怎样才能获得原始标题? 任何人都可以给我一个提示(或者甚至可能有一个更简单的解决方案?)

此致  蒂莫

1 个答案:

答案 0 :(得分:0)

尝试引入DefaultSoapHeaderMapper的自定义扩展并覆盖populateUserDefinedHeader以从SaajSoapHeaderElement中提取MessageHeaders并将其填充到SoapHeader。最后将您的解决方案注入header-mapper的{​​{1}}。