Spring Integration Http Outbound Gateway Header Mapper [英] Spring Integration Http Outbound Gateway Header Mapper
问题描述
我正在尝试将自定义标头添加到我的http出站网关。
I am trying to add custom headers to my http outbound gateway.
我尝试过的事情&工作:
Things that I have tried & work:
<int:header-enricher>
<int:header name="replyChannel" value="nullChannel" />
<int:header name="Content-Type" value="application/xml" />
<int:header name="X-Operation" value="CUSTOM_OPERATION" />
<int:header name="X-StatusCode" value="200" />
</int:header-enricher>
<int-http:outbound-gateway url="${custom.url}/update"
mapped-request-headers="HTTP_REQUEST_HEADERS, Operation, StatusCode"
http-method="POST" request-factory="serviceRequestFactory"
expected-response-type="java.lang.String"
error-handler="errorChannelHandler" />
在上面的场景中,它有效但我添加的自定义标题以X-为前缀默认。
In the above scenario, it works but the custom headers that I add, are prefixed with X- by default.
为了摆脱它,我尝试了以下但是没有将我的自定义值设置为标题:
To get rid of it, I tried the following but it doesn't set my custom values to the headers:
<int:header-enricher>
<int:header name="replyChannel" value="nullChannel" />
<int:header name="Content-Type" value="application/xml" />
<int:header name="Operation" value="CUSTOM_OPERATION" />
<int:header name="StatusCode" value="200" />
</int:header-enricher>
<int-http:outbound-gateway url="${custom.url}/update"
header-mapper="headerMapper"
http-method="POST" request-factory="serviceRequestFactory"
expected-response-type="java.lang.String"
error-handler="errorChannelHandler" />
<bean id="headerMapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*"/>
<property name="outboundHeaderNames" value="HTTP_REQUEST_HEADERS, Operation, StatusCode" />
<property name="userDefinedHeaderPrefix" value=""/>
</bean>
花了很多时间试图解决这个问题后,我陷入困境。任何帮助将不胜感激。
After spending a lot of time in trying to fix this, I am stuck. Any help would be appreciated.
推荐答案
我刚刚使用示例应用程序测试了您的映射器,它工作正常......
I just tested your mapper with the sample app and it worked fine...
<int:gateway id="requestGateway"
service-interface="org.springframework.integration.samples.http.RequestGateway"
default-request-channel="requestChannel">
<int:default-header name="Operation" value="foo" />
<int:default-header name="StatusCode" value="bar" />
</int:gateway>
<int:channel id="requestChannel"/>
<int-http:outbound-gateway request-channel="requestChannel"
url="http://localhost:18080/http/receiveGateway"
http-method="POST"
header-mapper="headerMapper"
expected-response-type="java.lang.String"/>
<bean id="headerMapper"
class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*" />
<property name="outboundHeaderNames" value="HTTP_REQUEST_HEADERS, Operation, StatusCode" />
<property name="userDefinedHeaderPrefix" value="" />
</bean>
POST /http/receiveGateway HTTP/1.1
Accept: text/plain, */*
Operation: foo
StatusCode: bar
Content-Type: text/plain;charset=UTF-8
Accept-Charset: big5, ...
User-Agent: Java/1.8.0_60
Host: localhost:8080
Connection: keep-alive
Content-Length: 5
打开DEBUG记录for org.springframework.integration
获取标题映射的详细日志记录...
Turn on DEBUG logging for org.springframework.integration
to get detailed logging for header mapping...
11:13:19.562 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] headerName=[operation] WILL be mapped, matched pattern=operation
11:13:19.562 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] setting headerName=[Operation], value=foo
11:13:19.563 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] headerName=[errorchannel] WILL NOT be mapped
11:13:19.563 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] headerName=[id] WILL NOT be mapped
11:13:19.563 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] headerName=[statuscode] WILL be mapped, matched pattern=statuscode
11:13:19.563 DEBUG [main][org.springframework.integration.http.support.DefaultHttpHeaderMapper] setting headerName=[StatusCode], value=bar
这篇关于Spring Integration Http Outbound Gateway Header Mapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!