Creating an HTTP proxy in Spring Integration 4.2.1.RELEASE. Environment is using the latest 2.0.0.RELEASE platform BOM, including a spring-webmvc layer - running on Tomcat7.
Calls are "application/json", passed through the web layer to a different REST server endpoint (the setupUrl method rewrites the URL). The code successfully calls the external server, gets good response, then mangles the response before it returns to the caller.
@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();
}
The call directly to the REST endpoint returns
{"affiliate":"test","producer":"TST","products"...
While the call through Spring Integration returns
"{\"affiliate\":\"test\",\"producer\":\"TST\",\"products\":[{\"
Tried a lot of combinations of adding StringHttpMessageConverter to the outbound adapter. Messing with the encodings (UTF-8 rather than ISO-8859-1). Something is messing with the response string, and it seems to be AFTER it leaves Spring Integration as near as I can tell. The last time Integration touches it is HttpRequestHandlingMessagingGateway.handleRequest() line 117. It still looks correct in the response object there.
It's possible the issue is really with spring-mvc, that is the first place I see the mangled string in debugging.