Http Gateways和Json Transformers:剥离的标题

使用Spring Integration 4.0.3.RELEASE和Jackson2,我试图将Json Transformers与http网关结合使用。

我的路径看起来类似于Spring Integration文档中引用的amqp适配器,但是使用http gateways(1):

…->对象到JSON-变压器 – > HTTP的出站网关—->

—-> HTTP的入站网关 – > JSON到对象的变压器 – >

客户:

 ...    

服务器:

    ...  

我得到的例外是(我认为相关的是粗体):

2014-08-22T23:58:21.640-0400 WARN [http-bio-8080-exec-2] osihiHttpRequestHandlingMessagingGateway网关发生故障sendAndReceive org.springframework.integration.transformer.MessageTransformationException:无法在org.springframework.integration上转换消息。 transform.AbstractTransformer.transform(AbstractTransformer.java:44)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:68)〜 [spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170)~ [spring-integration-core-4.0.3.RELEASE。 jar:na] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler。 MessageHandlerChain.ha ndleMessageInternal(MessageHandlerChain.java:131)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)〜[spring-integration -core-4.0.3.RELEASE.jar:na] at 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] at 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上的org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:144)〜[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE]。来自org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java)的messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:44)〜[spring-messaging-4.0.6.RELEASE.jar:4.0.6.RELEASE] :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] at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:224)[spring-i ntegration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.actualDoHandleRequest(HttpRequestHandlingEndpointSupport.java:473)[spring-integration-http-4.0.3.RELEASE.jar: na] at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:370)[spring-integration-http-4.0.3.RELEASE.jar:na] at 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)[在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) [spring-webmvc-4.0.6.RELEASE.jar: spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE] : 4.0.6.RELEASE]引起:java.lang.IllegalArgumentException:无法解析 ‘ja中的‘json__TypeId__’ vaTypes’。 在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] at org.springframework.integration.support.json.Jackson2JsonObjectMapper.extractJavaType(Jackson2JsonObjectMapper.java:44)〜 [spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.support.json.AbstractJacksonJsonObjectMapper.fromJson(AbstractJacksonJsonObjectMapper.java:60)〜[spring-integration-core-4.0.3。在org.springframework.integration的org.springframework.integration.json.JsonToObjectTransformer.doTransform(JsonToObjectTransformer.java:81)〜[spring-integration-core-4.0.3.RELEASE.jar:na]的RELEASE.jar:na]。 transformer.AbstractTransformer.transform(AbstractTransformer.java:33)〜[spring-integration-core-4.0.3。 RELEASE.jar:na] …省略了102个常用帧

当我调试时,我在客户端看到json__TypeId__标头已从传出消息中删除。 当我将JsonHeaders.HEADERS添加到DefaultHttpHeaderMapper并使用此映射器注入网关时,我看到当映射器工作完成时,Json头存在,但是当我最终返回RestTemplate.doWithRequestrequestHeaders不再包含Json那些。 当然,我得到了相同的exception服务器端。

也许我的配置是不正确的,但随着该标头被剥离,我不确定服务器端如何能够进行json-to-object转换。

我不希望明确指出特定Mappers上的类型,因为它们可以变化。 有没有办法配置我需要支持这个途径的组件?

– 参考 –

(1) http://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html#transformer滚动到Json变形金刚子部分

使用出站http适配器,用户头(在他的情况下是json类型信息)通过HTTP传送为X-

  POST /http/receiveGateway HTTP/1.1 Accept: text/plain, */* X-foo: bar 

在服务器端, X-未被删除,因此您必须将其映射到x …

  

然后,您需要在变换器之前的中设置来设置标题(减去’x – ‘)…

   ...  

(注意小写x )。

编辑:

或者,在发送方,您可以将映射器配置为NOT前缀自定义标头…