You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ueland <ha...@hueland.net> on 2008/09/09 23:51:22 UTC
RESTful WebService returning a binary document
Hi all,
I'm quite new on web services generally and CXF specially. I want to use CXF
to implement a RESTful webservice which should return binary data directly
in the response with a content type of image/jpeg for example. What I want
to do is to call http://<host>/services/document/<id> and get this document
returned, so that the right application or Save file dialog appears in the
browser. Is this possible using the RESTful libraries with CXF? I think I
could implement this with my own Servlet implementation and setting the
content type and binaray data directly in HttpServletResponse, but I would
like to take advantages of CXF.
I think something like this:
@Get
@HttpResource(location="/document/{id}")
public BinaryData getDocument(String id) {
...
}
But this will probably just return a XML document with the encoded binary
data inside?
Any suggestions?
Thanks in advance
Harald
--
View this message in context: http://www.nabble.com/RESTful-WebService-returning-a-binary-document-tp19402088p19402088.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful WebService returning a binary document
Posted by Sergey Beryozkin <se...@iona.com>.
Hi
With JAX-RS you can do
@Get
@Path("/document/{id}")
@ProduceMime("application/octet-stream") // or some other type
public BinaryData getDocument(String id) {
...
}
If BinaryData is a custom type then you'd need to create a custom JAX-RS MessagerBodyWriter which will know
how to marshal BinaryData. Alernatively you can just return byte[] or InputStream or Reader. JAX-RS StreamingOutput is also
supported...
Cheers, Sergey
>
> Hi all,
>
> I'm quite new on web services generally and CXF specially. I want to use CXF
> to implement a RESTful webservice which should return binary data directly
> in the response with a content type of image/jpeg for example. What I want
> to do is to call http://<host>/services/document/<id> and get this document
> returned, so that the right application or Save file dialog appears in the
> browser. Is this possible using the RESTful libraries with CXF? I think I
> could implement this with my own Servlet implementation and setting the
> content type and binaray data directly in HttpServletResponse, but I would
> like to take advantages of CXF.
>
> I think something like this:
>
> @Get
> @HttpResource(location="/document/{id}")
> public BinaryData getDocument(String id) {
> ...
> }
>
> But this will probably just return a XML document with the encoded binary
> data inside?
>
> Any suggestions?
>
>
> Thanks in advance
>
> Harald
>
> --
> View this message in context: http://www.nabble.com/RESTful-WebService-returning-a-binary-document-tp19402088p19402088.html
> Sent from the cxf-user mailing list archive at Nabble.com.
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland