0

I tried to build a simple spring integration project where I get a REST request and convert it to a SOAP request. Something like:

<int-http:inbound-gateway id="rest-inbound-gateway" request-channel="restRequestChannel"
    reply-channel="restOutputChannel" supported-methods="POST"
    path="/somepath" request-payload-type="com.something.RequestObject">
        <int-http:request-mapping consumes="application/json" produces="application/json" />
</int-http:inbound-gateway>

<int:transformer ref="RestToSoapTransformer" method="transform"
                 input-channel="restRequestChannel" output-channel="transformedChannel"/>

<int-ws:outbound-gateway id="marshallingGateway"
    request-channel="transformedChannel" reply-channel="restOutputChannel"
    uri="http://localhost:8088/mockSoapBinding" marshaller="marshaller"
    message-sender="messageSender"
    unmarshaller="marshaller" >
</int-ws:outbound-gateway>

But some informations which are in the REST request need to put to the SAOP envelope header and not the envelope body. Eg.

REST Request:

{
    "foo": "foo",
    "bar": "bar"
}

And SOAP Request sould be:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <foo>foo</foo>
    </soapenv:Header>
    <soapenv:Body>
         <bar>bar</bar>
    </soapenv:Body>
</soapenv:Envelope>

How can I do that? The transformer only create the soap body, and the in an interceptor or header mapper I don't have the original request anymore. Is there any way to do that?

1 Answers1

1

See the documentation.

WS Message Headers

The Spring Integration WebService Gateways will map the SOAP Action header automatically. It will be copied by default to and from Spring Integration MessageHeaders using the DefaultSoapHeaderMapper.

Of course, you can pass in your own implementation of SOAP specific header mappers, as the gateways have respective properties to support that.

Any user-defined SOAP headers will NOT be copied to or from a SOAP Message, unless explicitly specified by the requestHeaderNames and/or replyHeaderNames properties of the DefaultSoapHeaderMapper.

...

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Sorry I wrote the question equivocally. I need to set SOAP envelope header and not soap action header. I enlarged the question. – prophet4955 Oct 30 '18 at 09:39
  • That's exactly what the documentation describes `Any user-defined SOAP headers will NOT be copied to or from a SOAP Message, unless explicitly specified by the requestHeaderNames and/or replyHeaderNames properties of the DefaultSoapHeaderMapper.`. Add a `` before the gateway to add the headers, then configure the mapper to map them via the`requestHeaderNames` property. – Gary Russell Oct 30 '18 at 13:29
  • Thanks! Now if I'm return a String in my `` its in the header like `. Is there a way to put it under the header element in a separate tag? If I'm returning an object or a JAXBElement, it is not appear in the header at all. – prophet4955 Oct 31 '18 at 16:52
  • See [the documentation I pointed you to](https://docs.spring.io/spring-integration/reference/html/ws.html#ws-message-headers). You can use a `StringSource` as the header value - scroll down to the bottom of that section. – Gary Russell Oct 31 '18 at 17:27