dev@jsr311.java.net

Re: JSR311: default EJBExceptionMapper in spec...

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 20 Aug 2009 10:17:42 -0400

Paul Sandoz wrote:
>
> On Aug 19, 2009, at 7:33 PM, Bill Burke wrote:
>
>> I'm doing an EJB example in my book and came across the scenario of
>> EJBException. Maybe the spec should define a default ExceptionMapper
>> for it? Here's a simple one I did:
>>
>> @Provider
>> public class EJBExceptionMapper implements ExceptionMapper<EJBException>
>> {
>> @Context
>> private Providers providers;
>>
>> public Response toResponse(EJBException exception)
>> {
>> if (exception.getCausedByException() == null)
>> {
>> return Response.serverError().build();
>> }
>> Class cause = exception.getCausedByException().getClass();
>> ExceptionMapper mapper = providers.getExceptionMapper(cause);
>> if (mapper == null)
>> {
>> return Response.serverError().build();
>> }
>> else
>> {
>> return mapper.toResponse(exception.getCausedByException());
>> }
>> }
>> }
>
> Note that the above solution assumes that by default there is an
> exception mapper for WebApplicationException. Only instances
> WebApplicationException that have no entity should be mapped:
>

I am not following you. Don't see where WEbApplicationException comes
into play here.

>
> https://jsr311.dev.java.net/nonav/releases/1.0/spec/spec3.html#x3-280003.3.4
>
>
> Thus one cannot always assume that providers.getExceptionMapper for a
> cause class that is assignable to WebApplication will return a non-null
> value.
>

Ah, you're saying that if the cause is a WebApplicationException I need
to return the Response of the WAE if it exists.

Bill
-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com