Manos
Manos

Reputation: 21

return a pdf in browser from web service

i am relative new in java development.. I want to create a web service (jax-ws)/web application that will receive some input and generate pdf, and then open the pdf in the browser. I manage to create the pdf (using itext) and open it in the broswer using servlet (with FileInputStream etc). However i do not know, how to return the servlet from the web service. What should I do, so when I call the web service to receive a pdf via the servlet ?

Upvotes: 1

Views: 5973

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340793

If you've returned PDF from servlet, it means your servlet sent PDF stream as output and probably set content type as "application/pdf". This works fine in the browser and this is the right way to do it.

However, you cannot easily invoke web service (no matter whether it is JAX-WS or any other stack) from the browser. Web service call requires POST and strictly defined SOAP content. You can, however, use AJAX to call web service, but that is a different story (also look at REST).

If you want to return binary data from web service (please keep in mind that web-services are for machines, not for humans using web browsers), you have two options: either serialize the binary data using base64 or use multipart HTTP response (MTOM standard, see for instance: http://www.mkyong.com/webservices/jax-ws/jax-ws-attachment-with-mtom).

Upvotes: 1

Related Questions