2015-05-13 45 views
1

我想發送一個cookie作爲HTTP服務請求的一部分。該cookie的名稱是_br_uid_2,並且cookie的值應該是有效內容對象的customerId屬性。向彈簧集成請求添加動態cookie

的服務配置,像這樣:

<int:channel id="InChannelBr"></int:channel> 
<int:channel id="OutChannelBr"></int:channel> 

<!-- Gateway Start --> 
<int:gateway id="BloomreachGateway" default-request-timeout="5000" default-reply-timeout="5000" 
default-request-channel="InChannelBr" service-interface="com.someco.service.BloomreachSpringService"> 
    <int:method name="getSearchResults" request-channel="InChannelBr" reply-channel="OutChannelBr" />  
</int:gateway> 

<int-http:outbound-gateway id="locationBloomreachGateway" 
          request-channel="InChannelBr" 
          reply-channel="OutChannelBr" 
          url="${bloomreach_search_url}?account_id=${br_account_id}&amp;auth_key=${br_auth_key}&amp;domain_key=${br_domain_key}&amp;url=${br_url}&amp;request_type=${br_request_type}&amp;br_origin=${br_origin}&amp;search_type=${br_search_type}&amp;fl=${br_field_list}{urlParams}&amp;facet.range=${br_price_range}" 
          http-method="GET" 
          encode-uri="false" 
          transfer-cookies="true" 
          reply-timeout='5000' 
          expected-response-type="com.someco.BloomreachSearchResponse" 
          message-converters="brJsonConverter" 
          uri-variables-expression="@brUriVariablesBean.populate(payload)"> 
</int-http:outbound-gateway> 

這似乎是一個共同的願望,但我沒有看到任何明確的文件。我看着變形金剛和標題精靈。

有人能告訴我如何更新Spring服務定義,以便它發送payload.getCustomerId()作爲_br_uid_2 cookie的值嗎?

謝謝! Bobby

回答

0

我想通了。我添加了名稱爲「Cookie」的表達式=「'_ br_uid_2 ='+ payload.customerId」。

<int:channel id="InChannelBr"></int:channel> 
<int:channel id="InChannelBrWithCookies"></int:channel> 
<int:channel id="OutChannelBr"></int:channel> 

<!-- Gateway Start --> 
<int:gateway id="BloomreachGateway" default-request-timeout="5000" default-reply-timeout="5000" 
default-request-channel="InChannelBr" service-interface="com.someco.service.BloomreachSpringService"> 
    <int:method name="getSearchResults" request-channel="InChannelBr" reply-channel="OutChannelBr" />  
</int:gateway> 

<int:header-enricher input-channel="InChannelBr" output-channel="InChannelBrWithCookies"> 
    <int:header name="Cookie" expression="'_br_uid_2=' + payload.customerId"/> 
</int:header-enricher> 

<int-http:outbound-gateway id="locationBloomreachGateway" 
          request-channel="InChannelBrWithCookies" 
          reply-channel="OutChannelBr" 
          url="${bloomreach_search_url}?account_id=${br_account_id}&amp;auth_key=${br_auth_key}&amp;domain_key=${br_domain_key}&amp;url=${br_url}&amp;request_type=${br_request_type}&amp;br_origin=${br_origin}&amp;search_type=${br_search_type}&amp;fl=${br_field_list}{urlParams}&amp;facet.range=${br_price_range}" 
          http-method="GET" 
          encode-uri="false" 
          transfer-cookies="true" 
          reply-timeout='5000' 
          expected-response-type="com.someco.BloomreachSearchResponse" 
          message-converters="brJsonConverter" 
          uri-variables-expression="@brUriVariablesBean.populate(payload)"> 
</int-http:outbound-gateway>