如何在 Spring-integration xml 中创建具有 WS-A 属性的请求

How to create a request with WS-A attributes in Spring-integration xml

请您帮忙创建一个包含 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:Fromwsa:To

Error: 1100 A header representing a Message Addressing Property is not present. (Reason: the required header element wsa:From is absent)

如何在基于 xml 的配置中执行此操作?

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

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

并发送到 queue。 如果我使用 soapenv:Body,请求将不会被视为有效。所以我的请求只是 body 内的标签。不确定如何添加 header 位。

请指出一个示例,该示例使用 wsa:To 和 wsa:From 创建请求,涉及到,错误等

wsa:Fromwsa:ToElementheaders,不是像上面提到的soap-action那样简单的字符串。 <ws:header-enricher> 帮不了你。

但是您仍然可以为普通的 <int:header-enricher> 声明一个 bean 并为您的 headers 提供一个 javax.xml.transform.Source 作为值。

5.0 版 开始,Spring 集成的 DefaultSoapHeaderMapper 可以向 <soapenv:Header> 添加元素:https://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/ws.html#ws-message-headers

查看示例有文档:

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");

更新

<ws:outbound-gateway> 的属性如下:

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