Spring 集成应路由消息(使用 SOAP Headers)

Spring Integration should route Message (with SOAP Headers)

我正在尝试编写配置网关,它应该获取完整的 SOAP 消息,然后将其委托给另一个 SOAP 提供程序(包括第一个请求的所有 SOAP headers)。

到目前为止我做了什么:

1) web.xml

MessageDispatcherServlet with Mapping:
<servlet-mapping>
    <servlet-name>spring-ws</servlet-name>
    <url-pattern>/appservices/*</url-pattern>
</servlet-mapping>

2) 配置 Endpoint-Mapping

<bean class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
    <property name="defaultEndpoint" ref="ws-in-gw"/>
</bean>

3) Spring 集成 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="*"”属性。 当我现在配置 wire-tap 时,我看到收到 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 现在在我的消息中,但是在 ClientInterceptor 中,没有办法获得 Headers(只是有效负载)?!我可以添加新的 Header,但我怎样才能得到原来的 Header? 谁能给我一个提示(或者甚至有一个更简单的解决方案??)

问候 蒂莫

尝试引入 DefaultSoapHeaderMapper 的自定义扩展并覆盖 populateUserDefinedHeader 以从 MessageHeaders 中提取那些 SaajSoapHeaderElement 并将它们填充到 SoapHeader。最后将您的解决方案注入 <int-ws:outbound-gateway>.

header-mapper