2016-07-17 4 views
0

<int-http:outbound-channel-adapter ... />を使用して、ヘッダーに情報が格納されたオブジェクトを送信する状況があります。私は<int-http:inbound-channel-adapter ... />が好き呼び出すときに作品に続いてSpringインテグレーション:http:アウトバウンドチャネルアダプタ用のcusomヘッダーの使用

は次のとおりです。

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チャンネル・アダプタを呼び出します。

<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> 

呼んでいる何doesntの仕事outbound-channel-adapter経由のサービスでは、呼び出し自体は機能しますが、私のヘッダ 'profile'はなくなりました。

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

私は春ブーツ1.3.6.RELEASEを使用しています。

答えて

1

デフォルトでは、カスタムヘッダーは(現在)X-のプレフィックスでマップされています。接頭辞なしでそれらをマッピングするには、DefaultHttpHeaderMapperuserDefinedHeaderPrefixをヌル(または"")に設定してマップするアウトバウンドヘッダー名を配線する必要があります。

the documentationを参照してください。

EDIT:

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

ねえゲイリー、ご回答いただきありがとうございます。良い習慣とは何か?私は 'X-'プレフィックスを維持すると思います。カスタムヘッダーキーのマーキングに使用されているのか、 'X-'の平均は何ですか? –

+0

私は元の意図が将来の標準見出しとの衝突を避けることだったと思います。私は現在、カスタムヘッダーにプレフィックスを付けないように考えているので、5.0でデフォルトを変更することを考えています。 –

+0

ありがとうございましたゲーリー、私はフォーマットコードをコメントに書いていませんでした私はあなたが行った設定であなたの答えを編集しました。いいですね。 –

関連する問題