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());
}
}
}
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com