users@jersey.java.net

[Jersey] Re: content-length

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 09 May 2012 09:59:58 +0200

Hello Matt,

built in MessageBodyWriters for JAXB annotated types do not set content
length. Why? There is no simple way how to get this info prior
serialization, so all these providers are returning "-1" in getSize(...)
method implementation.

If you need this information in your response, you'll need to implement
your own MessageBodyWriter which would perform serialization during
getSize(...) call and cache result and use it in writeTo(...) method.
This is not usable for streamed XML and not practical for types with
large XML representation (well, depends on how much memory do you have)
but might be ok for your case.

Regards,
Pavel


On 5/8/12 12:19 AM, mbrown_at_hayneedle.com wrote:
> What is the generally accepted method for setting the content-length
> when using Jersey and JAXB?
>
> Seems like this should be simple but so far it has not been.
>
> Matt
>
>