当用于标头值路由的标头时,Spring Integration将X- *添加到自定义标头

时间:2015-09-25 02:11:47

标签: spring spring-integration

我正在使用标头值路由器,在最终的Web服务中,用于标头值路由的标头附加了一个X- * String。

Spring Integration路由器代码段

<?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" />

捕获的标题如下:

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作为标题传递,但它变为X- * routingCode:。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您没有显示您的headerMapper bean,但看起来您正在映射所有标头;这可能不正确(例如replyChannel),您应该更具体地说明要映射的标头。

*标题中的X-*...看起来很奇怪 - 我猜测还有其他错误的映射配置。

如果您不想要前缀(X-是自定义HTTP标头的公共前缀),则可以在标头映射器中对其进行抑制。

请将您的标头映射器配置添加到问题以及任何其他相关的上游配置中。

与往常一样,DEBUG日志记录通常可以帮助解决这类问题。