dev@jsr311.java.net

Re: JSR311: default EJBExceptionMapper in spec...

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 20 Aug 2009 09:07:47 -0400

I was thinking of adding it to the EE section of the spec.

Stephan Koops wrote:
> 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());
>> }
>> }
>> }
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>

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