Spring 当 header 用于 header 值路由时,集成将 X-* 添加到自定义 Headers
Spring Integration added X-* to Custom Headers when the header used for header value routing
我正在使用 header 值路由,在最终的网络服务中,用于 header 值路由的 header 附加了一个 X-* 字符串。
Spring 集成路由器代码段
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<bean id="byteArrayHttpMessageConverter"
class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
</bean>
<bean id="formHttpMessageConverter"
class="org.springframework.http.converter.FormHttpMessageConverter">
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id="headerMapper"
class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*" />
<property name="outboundHeaderNames" value="*" />
<property name="userDefinedHeaderPrefix" value="" />
</bean>
<int:channel id="http.request.submit.withfiles" />
<int:channel id="http.response.submit.withfiles" />
<int:channel id="http.router.route1.process.submit.withfiles" />
<int:channel id="http.router.route2.process.submit.withfiles" />
<int-http:inbound-gateway id="http.gateway.inbound.submit.withfiles"
supported-methods="POST" header-mapper="headerMapper"
request-channel="http.request.submit.withfiles"
reply-channel="http.response.submit.withfiles" path="/v1.0/file">
<int-http:request-mapping consumes="multipart/form-data"
produces="application/json" />
<int-http:header name="routingCode" expression="headers['routingCode']" />
</int-http:inbound-gateway>
<int:header-value-router input-channel="http.request.submit.withfiles"
header-name="routingCode" default-output-
channel="http.router.route2.process.submit.withfiles">
<int:mapping value="AB"
channel="http.router.route1.process.submit.withfiles" />
<int:mapping value="AC"
channel="http.router.route2.process.submit.withfiles" />
</int:header-value-router>
<int-http:outbound-gateway
id="http.gateway.outbound.route1.submit.withfiles" header-mapper="headerMapper"
request-channel="http.router.route1.process.submit.withfiles"
reply-channel="http.response.submit.withfiles"
url="http://localhost:8080/myapplication1/file"
http-method-expression="headers.http_requestMethod"
expected-response-type="java.lang.String" charset="UTF-8"
reply-timeout="50000" />
抓取的header如下:
GET /mapfre-tron-mobile/badgeCounters HTTP/1.1
Accept: */*
X-*routingCode: AB
X-*http_requestMethod: GET
X-*errorChannel: org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@c52014
accept-language: en-US,en;q=0.8,ml;q=0.6
authorization: 43c3a826-eef1-42f7-af80-e017964ca158
X-*replyChannel: org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@c52014
X-*http_requestUrl: http://localhost:8080/my-switcher/v1.0/file
content-type: application/json
X-*id: 1b24823e-0d07-1225-aead-b80f3a8691b1
Cache-Control: no-cache
accept-encoding: gzip, deflate, sdch
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36
X-*timestamp: 1443145971493
Pragma: no-cache
Host: localhost:8081
Connection: keep-alive
如您所见,我将 routingCode 作为 header 传递,但它变成了 X-*routingCode:.
有什么想法吗?
您没有显示 headerMapper
bean,但看起来您正在映射所有 header;这不太可能是正确的(例如 replyChannel
),您应该更具体地说明正在映射哪些 header。
X-*...
header 中的 *
看起来很奇怪 - 我猜还有一些其他错误的映射配置。
如果您不需要前缀(X-
是自定义 HTTP headers 的常见前缀),您可以在 header 映射器中取消它。
请将您的 header 映射器配置以及任何其他相关的上游配置添加到问题中。
一如既往,DEBUG 日志记录通常可以帮助解决此类情况。
我正在使用 header 值路由,在最终的网络服务中,用于 header 值路由的 header 附加了一个 X-* 字符串。
Spring 集成路由器代码段
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<bean id="byteArrayHttpMessageConverter"
class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
</bean>
<bean id="formHttpMessageConverter"
class="org.springframework.http.converter.FormHttpMessageConverter">
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id="headerMapper"
class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*" />
<property name="outboundHeaderNames" value="*" />
<property name="userDefinedHeaderPrefix" value="" />
</bean>
<int:channel id="http.request.submit.withfiles" />
<int:channel id="http.response.submit.withfiles" />
<int:channel id="http.router.route1.process.submit.withfiles" />
<int:channel id="http.router.route2.process.submit.withfiles" />
<int-http:inbound-gateway id="http.gateway.inbound.submit.withfiles"
supported-methods="POST" header-mapper="headerMapper"
request-channel="http.request.submit.withfiles"
reply-channel="http.response.submit.withfiles" path="/v1.0/file">
<int-http:request-mapping consumes="multipart/form-data"
produces="application/json" />
<int-http:header name="routingCode" expression="headers['routingCode']" />
</int-http:inbound-gateway>
<int:header-value-router input-channel="http.request.submit.withfiles"
header-name="routingCode" default-output-
channel="http.router.route2.process.submit.withfiles">
<int:mapping value="AB"
channel="http.router.route1.process.submit.withfiles" />
<int:mapping value="AC"
channel="http.router.route2.process.submit.withfiles" />
</int:header-value-router>
<int-http:outbound-gateway
id="http.gateway.outbound.route1.submit.withfiles" header-mapper="headerMapper"
request-channel="http.router.route1.process.submit.withfiles"
reply-channel="http.response.submit.withfiles"
url="http://localhost:8080/myapplication1/file"
http-method-expression="headers.http_requestMethod"
expected-response-type="java.lang.String" charset="UTF-8"
reply-timeout="50000" />
抓取的header如下:
GET /mapfre-tron-mobile/badgeCounters HTTP/1.1
Accept: */*
X-*routingCode: AB
X-*http_requestMethod: GET
X-*errorChannel: org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@c52014
accept-language: en-US,en;q=0.8,ml;q=0.6
authorization: 43c3a826-eef1-42f7-af80-e017964ca158
X-*replyChannel: org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@c52014
X-*http_requestUrl: http://localhost:8080/my-switcher/v1.0/file
content-type: application/json
X-*id: 1b24823e-0d07-1225-aead-b80f3a8691b1
Cache-Control: no-cache
accept-encoding: gzip, deflate, sdch
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36
X-*timestamp: 1443145971493
Pragma: no-cache
Host: localhost:8081
Connection: keep-alive
如您所见,我将 routingCode 作为 header 传递,但它变成了 X-*routingCode:.
有什么想法吗?
您没有显示 headerMapper
bean,但看起来您正在映射所有 header;这不太可能是正确的(例如 replyChannel
),您应该更具体地说明正在映射哪些 header。
X-*...
header 中的 *
看起来很奇怪 - 我猜还有一些其他错误的映射配置。
如果您不需要前缀(X-
是自定义 HTTP headers 的常见前缀),您可以在 header 映射器中取消它。
请将您的 header 映射器配置以及任何其他相关的上游配置添加到问题中。
一如既往,DEBUG 日志记录通常可以帮助解决此类情况。