我有 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>)
请问我该怎么做?
谢谢!