【问题标题】:How to create a request with WS-A attributes in Spring-integration xml如何在 Spring-integration xml 中创建具有 WS-A 属性的请求
【发布时间】:2018-05-16 14:24:48
【问题描述】:

请您帮忙创建一个包含 WS-A 参数的请求 从: 到: 等等

<int:chain input-channel="msoapInChannel" output-channel="justLog">
<ws:header-enricher >
    <ws:soap-action value="http://yeah.com/Txns/port/sPortType/getesRequest"/>
</ws:header-enricher>
<ws:outbound-gateway uri="http://g.tst.b.l/wsb/router"/>
</int:chain>

我想将 wsa:From wsa:To 添加到请求中

错误:1100 表示消息寻址属性的标头不是 展示。 (原因:所需的头元素 wsa:From 不存在)

如何在基于 xml 的配置中做到这一点?

编辑: 我们创建请求并使用 JMS 队列。请求如下所示

String requestXml =  
"<getnNames xmlns=\"http://b.do.com/DTositeTxns/port\">" +
    "<RequestControl xmlns=\"http://www.im.com/mm/schema\">" + 
"<requestID>123896</requestID>" +
"<DLControl>" + 
    "<requesterName>LW</requesterName>" + 
    "<requesterLocale>RTnl</requesterLocale>" + 
"</DLControl>" +
    "</RequestControl>" +
    "<InquiryParam xmlns=\"http://www.im.com/mm/schema\">" + 
"<tcrmParam name=\"identiftionNumber\">" + bn + "</tcrmParam>" + 
"<tcrmParam name=\"PartficationType\">1000001</tcrmParam>" +
"<tcrmParam name=\"Filter\">ACTIVE</tcrmParam>" + 
    "</InquiryParam>" +
"</getnNames>" ;

TextMessage outMessage = session.createTextMessage(requestXml);

并发送到队列。 如果我使用soapenv:Body,则该请求不被接受为有效。所以我的要求只是正文中的标签。不知道如何添加标题位。

请指出一个示例,该示例使用 wsa:To 和 wsa:From 创建请求,与 To 相关,Fault to 等

【问题讨论】:

    标签: spring spring-integration mq


    【解决方案1】:

    wsa:Fromwsa:ToElement 标头,它们不是像上面提到的 soap-action 这样的简单字符串。 &lt;ws:header-enricher&gt; 不会帮助你。

    但是,您仍然可以为普通的 &lt;int:header-enricher&gt; 声明一个 bean,并为您的标头提供一个 javax.xml.transform.Source 作为值。

    版本 5.0 开始,Spring Integration 的DefaultSoapHeaderMapper 可以将元素添加到&lt;soapenv:Header&gt;https://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/ws.html#ws-message-headers

    查看示例有 Docs:

    Map<String, Object> headers = new HashMap<>();
    
    String authXml =
         "<auth xmlns='http://test.auth.org'>"
               + "<username>user</username>"
               + "<password>pass</password>"
               + "</auth>";
    headers.put("auth", new StringSource(authXml));
    ...
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    mapper.setRequestHeaderNames("auth");
    

    更新

    &lt;ws:outbound-gateway&gt; 具有如下属性:

    <xsd:attribute name="request-callback" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
    Reference to a Spring Web Services WebServiceMessageCallback. This enables changing
    the Web Service request message after the payload has been written to it but prior
    to invocation of the actual Web Service.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <tool:annotation kind="ref">
                            <tool:expected-type type="org.springframework.ws.client.core.WebServiceMessageCallback"/>
                        </tool:annotation>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:attribute>
    

    所以,你需要为ActionCallback 配置一个bean,并从这个属性中引用它。

    有关 ActionCallback 的更多信息在 Spring WS Reference Manual 中。

    【讨论】:

    • 感谢您的快速回复。我们没有使用 Spring 5.0。我不知道如何在我的 -int:chain 中使用 bean,请您指出一个示例 wsa 属性。我想创建一个像下面这样的标题 -
      w3.org/2005/08/addressing"> to.com/teTxns/port/nsPortType/getRequest
      @987654325 @> b.com/iteTxns/port/nsPortType</wsa:To>
    • 如果你不使用 Spring Integration 5.0.x,那么它不会起作用:它只是在以前的版本中还不支持......我会想一点信如何帮助你与以前的版本。
    • 你可以考虑直接使用WebServiceTemplate。这样您就可以控制要发送的消息及其标头。
    • 对不起,我不知道 WebServiceTemplate。这适用于 JMS 队列吗?我添加了用于不同服务的代码,不需要 wsa 并且工作正常 [不使用 WebServiceTemplate]
    • 我说的是这个项目projects.spring.io/spring-ws。这正是 Spring Integration WS 所基于的。您使用 JMS 代码显示的内容与 SOAP WebServices 完全无关。不知道你为什么混淆和混淆我们......
    猜你喜欢
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多