users@jersey.java.net

Re: [Jersey] Error handling with Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 16 Dec 2009 21:41:05 +0100

On Dec 16, 2009, at 9:20 PM, Casper Bang wrote:

> Paul Sandoz wrote:
>>
>> You would like to annotate an ExceptionMapper with @Produces ?
>
> Not really. I would like to avoid having to write ExceptionMapper
> classes and rather just annotate a method with an exception (list), an
> error code and a viewable.

OK.


>>
>> Note that it should be possible to decide whether to return a
>> Viewable
>> entity or not by placing some logic in the toResponse method using
>> the
>> JAX-RS variant features. Or you can inject HttpContext and get the
>> Content-Header set on the response.
>
> Right. But how come building a Response with a non-200 status message
> and providing a viewable entity gives an exception?
>

You found a regression!

The cause is because the status and headers have already been written
when the output stream is flushed, just before the forward to the JSP,
and the finish method is not correctly detecting that status and
headers have already been written. I will fix that tomorrow.

Paul.