timo.gruetter
timo.gruetter

Reputation: 33

Spring Integration should route Message (with SOAP Headers)

I am trying to write configure a gateway, which should take a complete SOAP Message and then delegate it to another SOAP Provider (incl. all SOAP headers of the first request).

What I have done so far:

1) web.xml

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

2) Configuration with an Endpoint-Mapping

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

3) Configuration of Spring Integration inbound-gateway and 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 () {
    }
}

My first Problem was, that the original SOAP Headers had been cut of, so I introduced the ' mapped-request-headers="*" ' attribute at the inbound gateway. When I now configure a wire-tap, I see the Headers (myToken:MySecretToken) are received:

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, ...}]

This is the SOAP Message for my test:

<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>

So the Headers are now in my Message, but in the ClientInterceptor, there is no way to get the Headers (just the payload)?! I can add new Headers, but how can I get the original Header? Can anybody give me a hint (or perhaps there is even a quiet simpler solution??)

Regards Timo

Upvotes: 1

Views: 1081

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

Try to introduce a custom extension of DefaultSoapHeaderMapper and override populateUserDefinedHeader to extract those SaajSoapHeaderElement from the MessageHeaders and populate them to the SoapHeader. And finally inject your solution to the header-mapper of your <int-ws:outbound-gateway>.

Upvotes: 0

Related Questions