首页 > 解决方案 > 如何在 Spring Integration 中使用来自 int-http:inbound-gateway 的数据设置 SOAP Envelope Header?

问题描述

我尝试构建一个简单的 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 信封头而不是信封正文。例如。

休息请求:

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

我怎样才能做到这一点?转换器仅创建肥皂主体,而在拦截器或标头映射器中,我不再有原始请求。有没有办法做到这一点?

标签: springspring-integrationspring-wsspring-integration-http

解决方案


请参阅文档

WS 消息头

Spring Integration WebService 网关将自动映射 SOAP Action 标头。默认情况下,它将使用 DefaultSoapHeaderMapper 在 Spring Integration MessageHeaders 之间复制。

当然,您可以传入您自己的 SOAP 特定标头映射器实现,因为网关具有相应的属性来支持它。

除非 DefaultSoapHeaderMapper 的 requestHeaderNames 和/或 replyHeaderNames 属性明确指定,否则任何用户定义的 SOAP 标头都不会复制到 SOAP 消息中或从 SOAP 消息中复制。

...


推荐阅读