[英]Spring Integration - http outbound gateway retry logic implementation
[英]Spring Integration - http outbound gateway custom headers
我有一個Java對象,我想將其作為自定義標頭傳遞給http出站網關上的請求。 下面是一個片段
<int:gateway id="service" service-interface="MyService" default-request-channel="requestChannel" default-reply-channel="replyChannel">
<int:method name="doSomething" payload-expression="#args[0] + ',' + #args[1]">
<int:header name="method_name" value="login"/>
<int:header name="service_identifier" value="myService"/>
</int:method>
</int:gateway>
<int:header-enricher input-channel="requestChannel" output-channel="gatewayChannel">
<int:header name="user_context" expression="T(UserContextHolder).getContext()"/>
</int:header-enricher>
<int-http:outbound-gateway request-channel="gatewayChannel" url="myURL" mapped-request-headers="user_context, service_identifier, method_name, HTTP_REQUEST_HEADERS"
http-method="POST" reply-channel="replyChannel"/>
其中UserContext可以是Java對象
UserContext implements Serializable {
String userId;
RequestParameters params;
ScopeEnum scope;
....
}
我的問題是標題user_context沒有映射在標題中。 從日志中,我可以看到DefaultHttpHeaderMapper正在請求Converter或ConversionService。 見下文 -
09:54:59,488 - WARN main org.springframework.integration.http.support.DefaultHttpHeaderMapper - Header 'X- user_context' with value 'UserContextImpl@5e3ca754' will not be set since it is not a String and no Converter is available. Consider registering a Converter with ConversionService (e.g., <int:converter>)
請問我該怎么做?
謝謝!
標准的HTTP標頭采用key:value格式,並且key和value均為字符串。 您嘗試將對象作為HTTP標頭值發送,這不是很明智(並且幾乎不可能,因為標頭的大小可能有一些限制,例如8KB Apache默認限制)。
您有三種選擇:
考慮不使用HTTP出站網關,而使用JMS(我認為最好的一種)
添加轉換器,該轉換器將UserContext
序列化為String
(如果字符串相對較短,則可以,在其他情況下,我不建議這樣做)
Datatype Channel Configuration
”部分中的描述,實現自定義轉換器UserContext-> String: http : //static.springsource.org/spring-integration/reference/htmlsingle/#channel-configuration
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.