Announcement Announcement Module
Collapse
No announcement yet.
http inbound-gateway and returning PDF stream Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • http inbound-gateway and returning PDF stream

    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>
    Last edited by vbose; Feb 23rd, 2011, 03:25 PM.

  • #2
    I figured it out as to why I have been getting error in my client.

    I changed the ResponseType from Byte[].class to byte[].class in the exchange method and now I am getting the expected result.

    Bad Code:
    Code:
    ResponseEntity<Byte[]> rByteEntity = template.exchange(docUri, HttpMethod.GET, requestEntity, Byte[].class);
    Correct Code:
    Code:
    ResponseEntity<byte[]> rByteEntity = template.exchange(docUri, HttpMethod.GET, requestEntity, byte[].class);
    Last edited by vbose; Feb 23rd, 2011, 05:26 PM.

    Comment


    • #3
      So, everything is working ok now?

      Thanks for posting the update.

      Comment


      • #4
        Yes. it is working now and I hope our client will be able to convert the octet-stream/byte[] into a proper PDF for viewing. Our client is a PowerBuilder Desktop application. Thanks for checking the status Mark!. You guys rock.

        Comment


        • #5
          Have you considered setting the 'supportedMediaTypes' property on your ByteArrayHttpMessageConverter instance to "application/pdf"?

          Comment


          • #6
            Mark,

            I have two URLs that my client can try. One with application/pdf as the media type and the other one with the default application/octet-stream. But, I am not sure whether PowerBuilder client has any native support to convert it to the right document format from the HTTP response binary stream. So we are trying many options.

            Thanks,
            Vigil

            Comment


            • #7
              Okay. Please keep us posted on your progress. It sounds very interesting!

              Cheers,
              Mark

              Comment


              • #8
                Sure. I will keep you posted. The entire project is very interesting. I plan on writing an article based on my experience.

                Thanks,
                Vigil

                Comment


                • #9
                  Just a quick update on the progress...Our PowerBuilder client application is now able to retrieve and display PDF using Microsoft XmlHttp Object and OLE control. With this, we are now able to integrate Spring Integration and Spring MVC powered RESTFUL service with one of our desktop based clients. The client sets the accept header as application/pdf and the response media type is set accordingly.
                  Last edited by vbose; Feb 28th, 2011, 10:07 AM.

                  Comment


                  • #10
                    Glad to hear that! Thanks for the update. Let us know if you have any other feature requests or improvements to suggest.

                    Comment


                    • #11
                      Sure Mark. After the successful prototype task of returning PDF to our Desktop based client, we are now working on Document Scanning feature of the project. This includes moving files from a shared clustered file system storage (Linux Global File System) that is accessible to different client offices from their desktop based applications using SMB protocol to a permanent storage in DB2 on mainframe. We are going to use file inbound adapter for this and I will use a different thread to post any challenges we come across. I proposed MongoDB or Alfresco for doc repository but our client is in favor of using mainframe.
                      Last edited by vbose; Feb 28th, 2011, 11:06 AM.

                      Comment

                      Working...
                      X