dev@jsr311.java.net

Re: JSR311: default EJBExceptionMapper in spec...

From: Stephan Koops <Stephan.Koops_at_web.de>
Date: Thu, 20 Aug 2009 09:29:04 +0200

Hi Bill,

sounds very good. But only for environments supporting EJBs.

best regards
   Stephan
> 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());
> }
> }
> }
>