在Spring集成中将spring集成头设置为soap头(没有拦截器/ threadlocal)

时间:2016-09-08 23:45:49

标签: spring soap spring-integration spring-ws

无论如何在Spring集成头文件中设置Spring-integration标头中的SOAP-ENV头文件?

我尝试了以下方法,并期望将bId填充到soap标头

<int:chain id="soapcall" input-channel="soapchannel">      
        <int-xml:header-enricher>
            <int-xml:header name="bId" expression="headers['bId']"/>
        </int-xml:header-enricher>
          <int-ws:outbound-gateway  uri="${soap.url}" interceptor="myInterceptor">
          </int-ws:outbound-gateway> 
     </int:chain>

但实际输出没有标题。见下文:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:n1="http://namespace/n1">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body> ...
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

在调用出站网关之前,我还查看了内部链路的下方方法。似乎这个标题丰富只需要肥皂动作作为标题。所以这会引发异常action headers not found

<int-ws:header-enricher >
            <int-ws:soap-action expression="headers['bId']"/>
          </int-ws:header-enricher>

我也查看了this帖子。但是我无法在链中编译这个。

1 个答案:

答案 0 :(得分:1)

我不确定#include <iostream> using namespace std; int main() { int row[5][10] = {}; for (int j = 0; j < 10; j++) { for (int i = 0; i < 5; i++) { row[i][j] = 500; cout << row[i][j] << " "; } cout << endl; } return 0; } 是什么,但这并不重要。

您需要的内容在<int-xml:header-enricher>上被称为header-mapper

它的代码如下:

<int-ws:outbound-gateway>

因此,默认情况下,它会将@Override protected void populateStandardHeaders(Map<String, Object> headers, SoapMessage target) { String soapAction = getHeaderIfAvailable(headers, WebServiceHeaders.SOAP_ACTION, String.class); if (!StringUtils.hasText(soapAction)) { soapAction = "\"\""; } target.setSoapAction(soapAction); } @Override protected void populateUserDefinedHeader(String headerName, Object headerValue, SoapMessage target) { SoapHeader soapHeader = target.getSoapHeader(); if (headerValue instanceof String) { QName qname = QNameUtils.parseQNameString(headerName); soapHeader.addAttribute(qname, (String) headerValue); } } 映射为标准值,并将所有用户定义为WebServiceHeaders.SOAP_ACTION且仅定位为目标String元素的attribute

这些用户定义的标题可以通过以下方式映射:

SOAP-ENV:Header

如果您需要将子元素填充到<xsd:attribute name="mapped-request-headers" type="xsd:string"> <xsd:annotation> <xsd:documentation><![CDATA[ Comma-separated list of names of SOAP Headers to be mapped from the SOAP request into the MessageHeaders. This can only be provided if the 'header-mapper' reference is not being set directly. The values in this list can also be simple patterns to be matched against the header names (e.g. "foo*" or "*foo"). ]]></xsd:documentation> </xsd:annotation> </xsd:attribute> ,除非扩展<SOAP-ENV:Header>并覆盖DefaultSoapHeaderMapper并使用populateUserDefinedHeader() API,否则您无法做出选择

另请查看Reference Manual