Spring集成:为http:outbound-channel-adapter使用cusom头

时间:2016-07-17 18:35:58

标签: rest http http-headers spring-integration http-put

我有一种情况是使用<int-http:outbound-channel-adapter ... />发送一个包含存储在标题中的信息的对象。

我致电<int-http:inbound-channel-adapter ... />之后的工作如下:

public void openTicket(final Profile profile, final Ticket ticket) {
    final HttpHeaders headers = new HttpHeaders();
    headers.set("profile", profile.toString());
    final HttpEntity<Ticket> entity = new HttpEntity<Ticket>(ticket, headers);
    template.exchange(URL, HttpMethod.PUT, entity, Ticket.class);
}

使用标题中的给定个人资料调用我的inboung-channel-adapter成功:

<int-http:inbound-channel-adapter
    channel="api_app_integration_request_channel" 
    supported-methods="PUT" 
    path="/process/ticket"
    request-payload-type="*.model.Ticket"
    mapped-request-headers="profile"
    error-channel="internal-client-rest-ticket-error-channel"
>
    <int-http:request-mapping consumes="application/json" />
</int-http:inbound-channel-adapter>

什么不起作用是通过出站通道适配器调用服务,呼叫本身有效,但我的标题&#39; profile&#39;走了。

<int-http:outbound-channel-adapter 
    channel="client_rest_ticket_outbound_channel"
    http-method="PUT"
    url="http://localhost:8080/process/ticket"
    mapped-request-headers="profile"
/>

我正在使用 Spring-Boot 1.3.6.RELEASE

1 个答案:

答案 0 :(得分:1)

默认情况下,自定义标头(当前)映射为X-前缀;要在没有前缀的情况下映射它们,您需要将DefaultHttpHeaderMapperuserDefinedHeaderPrefix设置为null(或"")以及要映射的出站标题名称连接起来。< / p>

请参阅using

修改

<bean class="org.springframework.integration.http.support.DefaultHttpHeaderMapper" id="headerMapper"
    p:userDefinedHeaderPrefix=""
    p:inboundHeaderNames="profile"
    p:outboundHeaderNames="profile"
/>