首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring集成:为http:出站通道适配器使用垫子头

Spring集成:为http:出站通道适配器使用垫子头
EN

Stack Overflow用户
提问于 2016-07-17 18:35:57
回答 1查看 497关注 0票数 0

我遇到了一种情况,即使用<int-http:outbound-channel-adapter ... />发送包含存储在标头中的信息的对象。

当我调用<int-http:inbound-channel-adapter ... />时,如下所示:

代码语言:javascript
复制
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);
}

这将调用我的内置通道适配器成功地在标头中使用给定的配置文件:

代码语言:javascript
复制
<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>

不起作用的是通过出站通道适配器调用服务,呼叫本身也能工作,但是我的头文件“配置文件”已经消失了。

代码语言:javascript
复制
<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-Boot1.3.6

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-18 07:22:23

默认情况下,(当前)用X-前缀映射自定义标头;要映射它们,需要将userDefinedHeaderPrefix设置为null (或"")的DefaultHttpHeaderMapper和要映射的出站标头名称连接起来。

文献资料

编辑:

代码语言:javascript
复制
<bean class="org.springframework.integration.http.support.DefaultHttpHeaderMapper" id="headerMapper"
    p:userDefinedHeaderPrefix=""
    p:inboundHeaderNames="profile"
    p:outboundHeaderNames="profile"
/>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38424637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档