dev@jsr311.java.net

Re: JSR311: Exception Handling

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 01 Apr 2008 12:51:13 -0400

Also note that any entity you put in the Response returned by the
mapper will then be written by a suitable MessageBodyWriter. So you
can do something like:

@Provider
public class ExceptionBackstop implements ExceptionMapper<Exception> {
   ...
   public Response map(Exception e) {return
Response.serverError().entity(e).build();}
}

@Provider
@ProduceMime("application/xml")
public class XmlExceptionWriter implements
MessageBodyWriter<Exception> {...}

@Provider
@ProduceMime("application/json")
public class JsonExceptionWriter implements
MessageBodyWriter<Exception> {...}

@Provider
@ProduceMime("text/plain")
public class TextExceptionWriter implements
MessageBodyWriter<Exception> {...}

The runtime will respect the Accept header when choosing the writer
for the response returned by the mapper and everything works as
expected.

Marc.

On Apr 1, 2008, at 11:06 AM, Stephan Koops wrote:
> Also good.
> But IMO it should also allow to use other ExceptionMappers for the
> given Exception, if no one for the given media type is available.
> For this I proposed a finer differentiation, and not only true and
> false.
>> I suppose we could also allow use of @ProduceMime on the provider
>> class so the runtime can pick a suitable one but that could be OTT.
> Stephan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.