【发布时间】:2016-02-28 16:27:34
【问题描述】:
在 Spring Integration 4.2.1.RELEASE 中创建 HTTP 代理。环境使用的是最新的2.0.0.RELEASE平台BOM,包括一个spring-webmvc层——运行在Tomcat7上。
调用是“application/json”,通过 Web 层传递到不同的 REST 服务器端点(setupUrl 方法重写 URL)。代码成功调用外部服务器,获得良好响应,然后在返回给调用者之前破坏响应。
@Bean
public IntegrationFlow httpProxyFlow() {
return IntegrationFlows
.from((MessagingGateways g) ->
g.httpGateway("/my-service/**")
.messageConverters(new MappingJackson2HttpMessageConverter())
.payloadFunction(httpEntity ->
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest()
.getQueryString())
.requestPayloadType(String.class))
.handleWithAdapter(a ->
a.httpGateway(this::setupUrl)
.httpMethodFunction(this::getMethodFunction)
.errorHandler(new PassThroughErrorHandler())
.encodeUri(false)
.expectedResponseType(String.class)
).get();
}
直接调用REST端点返回
{"affiliate":"test","producer":"TST","products"...
当通过 Spring Integration 的调用返回时
"{\"附属\":\"测试\",\"生产者\":\"TST\",\"产品\":[{\"
尝试了很多将 StringHttpMessageConverter 添加到出站适配器的组合。混淆编码(UTF-8 而不是 ISO-8859-1)。响应字符串有些混乱,似乎是在它离开 Spring Integration 之后,我可以告诉它。集成最后一次触及它是 HttpRequestHandlingMessagingGateway.handleRequest() 第 117 行。在那里的响应对象中看起来仍然正确。
问题可能真的出在 spring-mvc 上,这是我在调试中看到损坏的字符串的第一个地方。
【问题讨论】:
标签: java json spring spring-mvc spring-integration