Results 1 to 4 of 4

Thread: PDF RESTful or webservice

  1. #1

    Default PDF RESTful or webservice

    Hi,

    Maybe not a spring query but... using spring-3.0.5 REST api.

    Im trying to transfer a pdf document from server to client.
    I want to return a byte[] or similar, I want the client to tranform the byte[] to a pdf-file.
    Have tryed this with a RESTful approach using xtream and jettison but it fails, I seem to have a different length in my byte[] on the sending and receiving end, the pdf at the client side results in a "corrupt file" message...
    Don't really know why?

    Next I will try with webservice but It might be the same result...

    Anyone have experience transferrnig a pdf with RESTful or webservice without an "application/pdf" MIME type

  2. #2

    Default

    Hi,

    Did you implement the server side? If so, you can debug and see if it really returns the PDF you expect. If not, you could set up a dummy server which always returns the PDF you expect and see if you get it on your client side. That will give you an idea if the problem is on the server side or the client side.

    If the server side requires you to set specific headers, you should use RestTemplate.exchange() method, which works with RequestEntity.
    Last edited by guznik; Nov 8th, 2010 at 03:52 AM.
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

  3. #3

    Default

    Hi,

    My client method looks like this.

    Code:
    @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
        public void testClient(@PathVariable String userId) {
            try{
                Client c = Client.create();
                WebResource r=c.resource("http://localhost:8080/elecpay/user/s984323/pay/3);
                ClientResponse response = r.get(ClientResponse.class);
                String entity = response.getEntity(String.class);
                System.out.println("DONE1 = "+entity.length());
                System.out.println("DONE2 = "+entity.getBytes().length);
                this.convertByteArrayToPDF(entity.getBytes(), "newname");
            }catch(Exception e) {e.printStackTrace();}
        }
    My server code looks like this.
    Code:
    @RequestMapping(value = "/{userId}/pay/{pay}", method = RequestMethod.GET)
        public @ResponseBody byte[] getPay(@PathVariable String userId,
                                                    @PathVariable String pay,
                                                    ) {
            byte[] byteArray = null;
            try {
                byteArray = loadFile("/justa.pdf");
                System.out.println("ORIGINAL size = "+byteArray.length);
            } catch (IOException ex) {
                Logger.getLogger(ElecPayService.class.getName()).log(Level.SEVERE, null, ex);
            }
            return byteArray;
        }
    The ORIGINAL byteArray.length printout comes to 517828
    The DONE1 length is 495704 (client string)
    The DONE2 length is 495605 (client string.getBytes...)

    Cannot really see why the different in length in client/sever.
    The servermethod also gets called twice?

  4. #4

    Default

    I don't know your client technology, so I can't help you with that. Do you get the same result if you use Spring's RestTemplate?
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •