Hi,
I have some data which came from a HTTP Get.
The content type is application/octet-stream.
The data is not correctly converted:
Code:<int-http:outbound-gateway http-method="GET" expected-response-type="java.lang.String" url="${CACHE_SERVICE_PATH}{cacheKey}" request-factory="httpClientFactory" error-handler="cacheRequestErrorHandler"> <int-http:uri-variable name="cacheKey" expression="payload"/> </int-http:outbound-gateway>Code:2012 Sep 11 17:23:56 http-bio-7050-exec-3 springframework.web.client.RestTemplate : Created GET request for "HTTP://vlint-int.baba.com:7040/cache/v1/ac.baba.100000071001" 2012 Sep 11 17:23:56 http-bio-7050-exec-3 springframework.web.client.RestTemplate : Setting request Accept header to [text/plain, */*] 2012 Sep 11 17:23:56 http-bio-7050-exec-3 springframework.web.client.RestTemplate : GET request for "HTTP://vlint-int.baba.com:7040/cache/v1/ac.baba.100000071001" resulted in 200 (OK) 2012 Sep 11 17:23:56 http-bio-7050-exec-3 springframework.web.client.RestTemplate : Reading [java.lang.String] as "application/octet-stream" using [org.springframework.http.converter.StringHttpMessageConverter@40454ca3] 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.support.DefaultHttpHeaderMapper : inboundHeaderNames=[Accept-Ranges, Age, Allow, Cache-Control, Content-Encoding, Content-Language, Content-Length, Content-Location, Content-MD5, Content-Range, Content-Type, Date, ETag, Expires, Last-Modified, Location, Pragma, Proxy-Authenticate, Refresh, Retry-After, Server, Set-Cookie, Trailer, Transfer-Encoding, Vary, Via, Warning, WWW-Authenticate] : 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.support.DefaultHttpHeaderMapper : headerName=[Content-Type] WILL be mapped, matched pattern=Content-Type 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.support.DefaultHttpHeaderMapper : setting headerName=[Content-Type], value=application/octet-stream 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.support.DefaultHttpHeaderMapper : headerName=[Content-Length] WILL be mapped, matched pattern=Content-Length 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.support.DefaultHttpHeaderMapper : setting headerName=[Content-Length], value=18 : 2012 Sep 11 17:23:56 http-bio-7050-exec-3 integration.http.outbound.HttpRequestExecutingMessageHandler : handler 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#44d40c4e' sending reply Message: [Payload=’t 1408xxxxxxx][Headers={timestamp=1347409436426, id=b5a60612-0a2a-4ea0-9645-82d280ec5baf, errorChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@19d449fc, Authorization=baba, replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@19d449fc, Date=1347409436000, Content-Length=18, http_statusCode=200, Content-Type=application/octet-stream, Server=Apache-Coyote/1.1}]
The payload has extra bytes because it was stored with writeObject(). See the red highlight.
Without the message-converters set, StringHttpMessageConverter will just convert verbatim, hence with those extra bytes, which I don't want.
The question:
1. The expected data is String. Is using SerializingHttpMessageConverter the right way to do?
2. How to inject SerializingHttpMessageConverter? With the correct MediaType? Specifically, I need to call setSupportedMediaTypes().
Thanks so much!
Simon


Reply With Quote