Question

I've to implements Grails RESTful Web Services for both consumer and provider. Provider has to return pdf document and consumer has to process it and save it to the db. As a provider how to return pdf document using grails rest services. I used MTOM in soap web services to achieve this but not sure how to implement in Grails rest services.

Please suggest me how to achieve this with some example code.

Thanks

Was it helpful?

Solution

this is what I did and this is what you can do for the producer

>  def boas = callservicetogenerateReport // this should return an
> byteArray
>         // setting the content type
>         response.setContentType("application/pdf");
>         response.setHeader("Content-Disposition", "attachment;filename=sample.pdf")
>         response.setContentLength(boas.size());
>         // write ByteArrayOutputStream to the ServletOutputStream
>         response.outputStream << boas.toByteArray()
>         response.outputStream.flush()
>         response.outputStream.close()

For Consumer this is what i did in a rest call which actually handles a user submitting a file via post.

request.multiFileMap."files[]".each {file ->
                def newFile = new Expando(name: file.originalFilename, size: file.size)
                callServicetoAddFileToDB(file)
  }

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top