You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Kockert, Timo" <ti...@adesso-mobile.de> on 2010/05/17 18:45:01 UTC

BinaryDataProvider

Hello everyone,

I am using JAX-RS and implemented a method that returns files from disk. The response is handled by the BinaryDataProvider because its isWriteable() method returns true for File objects. However getSize() only returns a useful length for byte arrays. I was wondering why that is?

I am asking because without the size, the response is getting chunked which results in at least two requests by the browser for the same file and that causes - imho - unnecessary load on my application.

Greetings from Germany,
Timo

AW: BinaryDataProvider

Posted by "Kockert, Timo" <ti...@adesso-mobile.de>.
Hi,

I finally decided it would make more sense to implement MessageBodyWriter<File> directly instead of extending BinaryDataProvider (which implements MessageBodyWriter<Object>). Here is my code, if anyone is interested:

http://pastie.org/965300

Most of it is copied from BinaryDataProvider. Finally, I added my custom provider using Spring via <jaxrs:providers>. Works like a charm :-)

Greetings,
Timo


Von: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
Gesendet: Dienstag, 18. Mai 2010 13:09
An: Kockert, Timo
Cc: users@cxf.apache.org
Betreff: Re: BinaryDataProvider

Hi
On Tue, May 18, 2010 at 8:31 AM, Kockert, Timo <ti...@adesso-mobile.de>> wrote:
Hi,

thanks for the answer!
no probs :-)

I was already thinking about extending BinaryDataProvider. But how to I tell the framework which provider to use for File objects, if there is more than one?

Custom providers are checked before the ones shipped with the implementation...

cheers, Sergey

Greetings,
Timo


-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyozkin@gmail.com<ma...@gmail.com>]
Gesendet: Montag, 17. Mai 2010 19:17
An: users@cxf.apache.org<ma...@cxf.apache.org>
Betreff: Re: BinaryDataProvider

Hi

On Mon, May 17, 2010 at 5:45 PM, Kockert, Timo <
timo.kockert@adesso-mobile.de<ma...@adesso-mobile.de>> wrote:

> Hello everyone,
>
> I am using JAX-RS and implemented a method that returns files from disk.
> The response is handled by the BinaryDataProvider because its isWriteable()
> method returns true for File objects. However getSize() only returns a
> useful length for byte arrays. I was wondering why that is?
>
> it is an omission


> I am asking because without the size, the response is getting chunked which
> results in at least two requests by the browser for the same file and that
> causes - imho - unnecessary load on my application.
>
> the workaround is to extend BinaryProvider and overwrite its getSize()
method or even create a custom provider for writing Files only which can be
more optimized, etc...

hope it helps, Sergey


> Greetings from Germany,
> Timo
>


Re: BinaryDataProvider

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Tue, May 18, 2010 at 8:31 AM, Kockert, Timo <
timo.kockert@adesso-mobile.de> wrote:

> Hi,
>
> thanks for the answer!
>
> no probs :-)


> I was already thinking about extending BinaryDataProvider. But how to I
> tell the framework which provider to use for File objects, if there is more
> than one?
>
>
Custom providers are checked before the ones shipped with the
implementation...

cheers, Sergey


> Greetings,
> Timo
>
>
> -----Ursprüngliche Nachricht-----
> Von: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> Gesendet: Montag, 17. Mai 2010 19:17
> An: users@cxf.apache.org
> Betreff: Re: BinaryDataProvider
>
> Hi
>
> On Mon, May 17, 2010 at 5:45 PM, Kockert, Timo <
> timo.kockert@adesso-mobile.de> wrote:
>
> > Hello everyone,
> >
> > I am using JAX-RS and implemented a method that returns files from disk.
> > The response is handled by the BinaryDataProvider because its
> isWriteable()
> > method returns true for File objects. However getSize() only returns a
> > useful length for byte arrays. I was wondering why that is?
> >
> > it is an omission
>
>
> > I am asking because without the size, the response is getting chunked
> which
> > results in at least two requests by the browser for the same file and
> that
> > causes - imho - unnecessary load on my application.
> >
> > the workaround is to extend BinaryProvider and overwrite its getSize()
> method or even create a custom provider for writing Files only which can be
> more optimized, etc...
>
> hope it helps, Sergey
>
>
> > Greetings from Germany,
> > Timo
> >
>

AW: BinaryDataProvider

Posted by "Kockert, Timo" <ti...@adesso-mobile.de>.
Hi,

thanks for the answer!

I was already thinking about extending BinaryDataProvider. But how to I tell the framework which provider to use for File objects, if there is more than one?

Greetings,
Timo


-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyozkin@gmail.com] 
Gesendet: Montag, 17. Mai 2010 19:17
An: users@cxf.apache.org
Betreff: Re: BinaryDataProvider

Hi

On Mon, May 17, 2010 at 5:45 PM, Kockert, Timo <
timo.kockert@adesso-mobile.de> wrote:

> Hello everyone,
>
> I am using JAX-RS and implemented a method that returns files from disk.
> The response is handled by the BinaryDataProvider because its isWriteable()
> method returns true for File objects. However getSize() only returns a
> useful length for byte arrays. I was wondering why that is?
>
> it is an omission


> I am asking because without the size, the response is getting chunked which
> results in at least two requests by the browser for the same file and that
> causes - imho - unnecessary load on my application.
>
> the workaround is to extend BinaryProvider and overwrite its getSize()
method or even create a custom provider for writing Files only which can be
more optimized, etc...

hope it helps, Sergey


> Greetings from Germany,
> Timo
>

Re: BinaryDataProvider

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Mon, May 17, 2010 at 5:45 PM, Kockert, Timo <
timo.kockert@adesso-mobile.de> wrote:

> Hello everyone,
>
> I am using JAX-RS and implemented a method that returns files from disk.
> The response is handled by the BinaryDataProvider because its isWriteable()
> method returns true for File objects. However getSize() only returns a
> useful length for byte arrays. I was wondering why that is?
>
> it is an omission


> I am asking because without the size, the response is getting chunked which
> results in at least two requests by the browser for the same file and that
> causes - imho - unnecessary load on my application.
>
> the workaround is to extend BinaryProvider and overwrite its getSize()
method or even create a custom provider for writing Files only which can be
more optimized, etc...

hope it helps, Sergey


> Greetings from Germany,
> Timo
>