users@jersey.java.net

Re: [Jersey] Jersey EJB exception

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 28 Aug 2009 16:39:15 +0200

On Aug 28, 2009, at 4:33 PM, Herak Sen wrote:

> Hi Paul,
>
> I just tested and it's working.

Great, thanks for verifying.


> I was just wondering how did you fix it?
>

Jersey registered an ExceptiionMapper for EJBException:

public class EJBExceptionMapper implements
ExceptionMapper<EJBException> {

     private final Providers providers;

     public EJBExceptionMapper(@Context Providers providers) {
         this.providers = providers;
     }

     public Response toResponse(EJBException exception) {
         final Exception cause = exception.getCausedByException();
         if (cause != null) {
             final ExceptionMapper mapper =
providers.getExceptionMapper(cause.getClass());
             if (mapper != null) {
                 return mapper.toResponse(cause);
             } else if (cause instanceof WebApplicationException) {
                 return ((WebApplicationException)cause).getResponse();
             }
         }

         return Response.serverError().build();
     }
}

Kudo goes to Bill Burke happend to propose such a solution on the 311
EG mailing list.

Paul.