![](/img/trans.png)
[英]Spring Integration (HTTP in/outbound gateway) Vs Spring Data REST
[英]Spring integration: Using cusom header for http:outbound-channel-adapter
我有一種情況,可以使用<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>
什么沒用,就是通過outbound-channel-adapter調用服務,該調用本身可以工作,但是我的標頭“配置文件”消失了。
<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 。
默認情況下,自定義標頭(當前)以X-
前綴映射; 要映射它們而不帶前綴,您需要連接一個DefaultHttpHeaderMapper
並將userDefinedHeaderPrefix
設置為null(或""
)以及要映射的出站標頭名稱。
請參閱文檔 。
編輯:
<bean class="org.springframework.integration.http.support.DefaultHttpHeaderMapper" id="headerMapper"
p:userDefinedHeaderPrefix=""
p:inboundHeaderNames="profile"
p:outboundHeaderNames="profile"
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.