如何在 Spring 中设置 SOAP 信封 Header 与来自 int-http:inbound-gateway 的数据集成?

How to set SOAP Envelope Header in Spring Integration with data from int-http:inbound-gateway?

我尝试构建一个简单的 spring 集成项目,我在其中获取 REST 请求并将其转换为 SOAP 请求。类似于:

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

但是 REST 请求中的一些信息需要放入 SAOP 信封 header 而不是信封 body。例如

REST 请求:

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

SOAP 请求应该是:

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

我该怎么做?转换器仅创建 soap body,在拦截器或 header 映射器中我不再有原始请求。有什么办法吗?

参见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.

...