【发布时间】:2014-10-16 23:35:33
【问题描述】:
将 Spring Integration 4.0.3.RELEASE 与 Jackson2 结合使用,我正在尝试将 Json Transformers 与 http 网关结合使用。
我的路径看起来类似于 Spring Integration 文档中引用的 amqp 适配器,但使用的是 http gateways(1):
...->object-to-json-transformer->http-outbound-gateway---->
---->http-inbound-gateway->json-to-object-transformer->
客户:
<int:chain id="messageTransformerChain" input-channel="toServer" output-channel="messagesToServer">
...
<int:object-to-json-transformer />
</int:chain>
<int-http:outbound-gateway id="httpOutToSever"
request-channel="messagesToServer"
reply-channel="replyFromServer"
url="${server.endpoint}"
http-method="POST"
extract-request-payload="true"
expected-response-type="java.lang.String" />
服务器:
<int-http:inbound-gateway id="httpInboundFromClientGateway"
supported-methods="GET, POST"
request-channel="fromClientChannel" />
<int:chain input-channel="fromClientChannel">
<int:json-to-object-transformer />
...
</int:chain>
我得到的例外是(我认为相关的是粗体):
2014-08-22T23:58:21.640-0400 警告 [http-bio-8080-exec-2] o.s.i.h.i.HttpRequestHandlingMessagingGateway 故障发生在 网关发送和接收 org.springframework.integration.transformer.MessageTransformationException: 未能在 org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:44) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:68) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.handler.MessageHandlerChain.handleMessageInternal(MessageHandlerChain.java:131) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:109) ~[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:144) ~[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:44) ~[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE] 在 org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:75) ~[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE] 在 org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:250) [spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:224) [spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.actualDoHandleRequest(HttpRequestHandlingEndpointSupport.java:473) [spring-integration-http-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:370) [spring-integration-http-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:101) [spring-integration-http-4.0.3.RELEASE.jar:na] 在 org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) [spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE] 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) [spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE] 原因: java.lang.IllegalArgumentException:无法解析“json__TypeId__” 在“javaTypes”中。在 org.springframework.integration.support.json.AbstractJacksonJsonObjectMapper.createJavaType(AbstractJacksonJsonObjectMapper.java:67) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.support.json.Jackson2JsonObjectMapper.extractJavaType(Jackson2JsonObjectMapper.java:119) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.support.json.Jackson2JsonObjectMapper.extractJavaType(Jackson2JsonObjectMapper.java:44) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.support.json.AbstractJacksonJsonObjectMapper.fromJson(AbstractJacksonJsonObjectMapper.java:60) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.json.JsonToObjectTransformer.doTransform(JsonToObjectTransformer.java:81) ~[spring-integration-core-4.0.3.RELEASE.jar:na] 在 org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:33) ~[spring-integration-core-4.0.3.RELEASE.jar:na] ... 102个常用框架 省略
调试时,我在客户端看到 json__TypeId__ 标头已从传出消息中删除。当我将JsonHeaders.HEADERS 添加到DefaultHttpHeaderMapper 并使用此映射器注入网关时,我看到当映射器工作完成时,Json 标头存在,但是当我最终回到RestTemplate.doWithRequest requestHeaders 没有不再包含 Json 的。当然,我得到相同的异常服务器端。
也许我的配置不正确,但是由于该标头被剥离,我不确定服务器端将如何进行json-to-object 转换。
我不希望在特定映射器上明确指出通道的类型,因为它们可能会有所不同。有没有办法配置我需要支持此路径的组件?
-- 参考资料--
(1) http://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html#transformer 滚动到 Json Transformers 小节
【问题讨论】:
标签: java json spring-integration