What is the best strategy to return PDF binary stream as the response to an HTTP request. I used ByteArrayHttpMessageConverter to send back as octet-stream. But this did not work as I am getting error while extracting the data. I am using RestTemplate to consume the PDF binary stream and write the length of the contents in the log.
Error:
Could not extract response: no suitable HttpMessageConverter found for response type [[Ljava.lang.Byte;] and content type [application/octet-stream]
The DocumentService given in the example below return a reference to the PDF File Object as the input to the File to Bytes Trasformer which further gets send as the response to the http request.
Do I have to write a special http message converter to send back PDF stream as the response? Can someone throw some pointers.
My servlet-config.xml file is given below.
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.0.xsd" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-file="http://www.springframework.org/schema/integration/file" xmlns:int-http="http://www.springframework.org/schema/integration/http"> <int-http:inbound-gateway id="inboundDocGateway" name="/retrieveDococument.htm" supported-methods="GET, POST" request-channel="docReqChannel" reply-channel="docResChannel" convert-exceptions="true" message-converters="byteArrayMessageConverter" /> <int:channel id="docReqChannel"/> <int:channel id="docResChannel"/> <int:channel id="fileIn"/> <int:service-activator input-channel="docReqChannel" output-channel="fileIn" ref="docService" method="getFile" requires-reply="true" /> <bean id="docService" class="gov.dc.dmv.destiny.iis.DocumentService"/> <int-file:file-to-bytes-transformer input-channel="fileIn" output-channel="docResChannel" delete-files="false"/> <bean id="byteArrayMessageConverter" class="org.springframework.http.converter.ByteArrayHttpMessageConverter"> /bean> </beans>


Reply With Quote