users@jersey.java.net

RE: [Jersey] How to find out content-length *before* unmarshalling?

From: Markus Karg <markus.karg_at_gmx.net>
Date: Tue, 29 Dec 2009 15:20:24 +0100

Paul,

 

you're already back from Holidays? :-)

 

Thank you for your proposal, it sounds interesting, but unfortunately we
cannot use it since it is not part of JAX-RS. :-( Seems I should file
another RFE for JAX-RS 2.0. :-)

 

The content length is not really needed, it is just on a wish list: WebDAV
can return the size of a file (in byte) when doing a PROPFIND (i. e.
something like DOS's "DIR"). Currently our sample application always returns
0, but it would be smart to return the real size. Just because it would be
nice. No real need. I think there is no really good solution. In case we
have a directory containing thousands of files, it would just need too long
time to stream them to dev/null just to find out their size. Obviously this
cannot be prevented, unless JAXB would know something like a
"Marshaller.getSizeWithoutActualStreaming()" command. ;-)

 

Thanks

Markus

 

From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Dienstag, 29. Dezember 2009 11:29
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] How to find out content-length *before* unmarshalling?

 

 

On Dec 28, 2009, at 12:01 PM, Markus Karg wrote:





Tatu and Moises,

 

thank you for your ideas. It seems the idea of using a counting "dev/null
Stream" would be the most efficient one, since keeping the once streamed
result for a later request might clutter RAM with possibly never requested
String.

 

 

There is a Jersey specific solution: use a ContainerResponseFilter and adapt
the ContainerResponseWriter declared on the ContainerResponse to write to a
ByteArrayOutputStream the contents of which are written to the adapted
ContainerResponseWriter on finish.

 

Why do you need to know the length? for logging purposes or do you want to
set the Content-Length response header?

 

Paul.