users@jersey.java.net

Re: [Jersey] Input and Output binary streams using JERSEY?

From: Tauren Mills <tauren_at_groovee.com>
Date: Mon, 16 Aug 2010 18:11:00 -0700

Tatu,

Thanks. It seemed like MessageBodyWriter complicated things. But I'm
still interested in how it would be done that way, since I haven't
been able to find any examples or information on how to use it.

I'll try just returning byte[], but think I should probably look into
StreamingOutput. The files I'm generating can get large and I'd rather
stream them.

Also, is it possible to have a single URL that can return either JSON
or a binary file? For instance, my webapp requests JSON data that it
uses to build a table structure in the DOM by passing a JSON object
that defines all of the filtering and sorting of the table. But I'd
like to also retrieve that same data in XLS format, filtered and
sorted the same.

Does it make more sense to have two different REST urls for this, or
can one url be used? If so, how would I do this?

Thanks,
Tauren


On Mon, Aug 16, 2010 at 12:11 PM, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
> On Mon, Aug 16, 2010 at 12:07 PM, Tauren Mills <tauren_at_groovee.com> wrote:
>> I just posted a Jersey related question on StackOverflow and then
>> realized I'd be better off sending it here instead. But if you wish to
>> answer it, the question is here:
>> http://stackoverflow.com/questions/3496209/input-and-output-binary-streams-using-jersey
>>
>> I'm using Jersey to implement a RESTful API that is primarily retrieve
>> and serve JSON encoded data. But I have some situations where I need
>> to accomplish the following:
>>
>> * Export downloadable documents, such as PDF, XLS, ZIP, or other binary files.
>
> I think easiest way would be to just return byte[], or if you don't
> want to read and buffer, create StreamingOutput instance that reads
> file (etc) and writes content directly to output.
>
> For input, one alternative to multi-part could be using Jackson's
> base64 support, assuming client could do base64 encoding. It is
> reasonably efficient for processing so should work ok for moderate
> file sizes (in megabytes at least).
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>