【问题标题】:How to set SOAP Envelope Header in Spring Integration with data from int-http:inbound-gateway?如何在 Spring Integration 中使用来自 int-http:inbound-gateway 的数据设置 SOAP Envelope Header?
【发布时间】:2018-10-29 09:16:29
【问题描述】:

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

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>

我该怎么做?转换器仅创建肥皂主体,而在拦截器或标头映射器中,我不再有原始请求。有什么办法吗?

【问题讨论】:

    标签: spring spring-integration spring-ws spring-integration-http


    【解决方案1】:

    the documentation

    WS 消息头

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

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

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

    ...

    【讨论】:

    • 对不起,我写的问题模棱两可。我需要设置 SOAP 信封头而不是肥皂动作头。我扩大了问题。
    • 这正是文档所描述的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.。在网关之前添加&lt;header-enricher/&gt; 以添加标头,然后配置映射器以通过requestHeaderNames 属性映射它们。
    • 谢谢!现在,如果我在我的&lt;header-enricher/&gt; 中返回一个字符串,它在标题中,如`
      。有没有办法将它放在单独的标签中的标题元素下?如果我要返回一个对象或 JAXBElement,它根本不会出现在标题中。
    • the documentation I pointed you to。您可以使用 StringSource 作为标题值 - 向下滚动到该部分的底部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多