Http Gateways and Json Transformers: stripped headers

不打扰是莪最后的温柔 提交于 2019-12-06 15:38:33

With the outbound http adapter, user headers (in his case the json type information) are conveyed over HTTP as X-<header>...

<int-http:outbound-gateway request-channel="requestChannel" 
                           url="http://localhost:18080/http/receiveGateway"
                           http-method="POST"
                           mapped-request-headers="foo"
                           expected-response-type="java.lang.String"/>

POST /http/receiveGateway HTTP/1.1
Accept: text/plain, */*
X-foo: bar

On the server side, the X- is not removed so you have to map it with the x...

<int-http:inbound-gateway request-channel="receiveChannel"
                      path="/receiveGateway"
                      mapped-request-headers="x-foo"
                      supported-methods="POST"/>

You will then need a <header-enricher/> in your <chain/> before the transformer to set the headers (minus the 'x-')...

<int:header-enricher>
    <int:header name="json__TypeId__" expression="headers['x-json__TypeId__']" />
    ...
</int:header-enricher>

(Note lower case x).

EDIT:

Or, on the sending side, you can configure the mapper to NOT prefix the custom header(s)...

<bean id="mapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
    <property name="outboundHeaderNames" value="foo,bar" />
    <property name="userDefinedHeaderPrefix" value="" />
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!