dev@jsr311.java.net

Re: JSR311: default EJBExceptionMapper in spec...

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 21 Aug 2009 10:10:20 -0400

On Aug 20, 2009, at 5:40 AM, Paul Sandoz wrote:
>
> I too have encountered the same issue. Marc and I were discussing
> it, and we concluded that WebAppliationException should be allowed
> to pass through, but i guess why not any RuntimeException?
>
> I was scratching my head trying to work out a solution dependent on
> EJB APIs but it is not possible and the spec states that only
> Runtime exceptions in the war/ear annotated with
> ApplicationException will be recognized. Thus it will not be
> portable for a JAX-RS implementation distributed as part of an app
> server.
>
> Thus i think what you propose is a good one. Now i can fix a bug :-)
>
The current changelog has the following:

- In a product that also supports EJB, an implementation MUST support
use of stateless and singleton session beans as root resource classes
and providers in a Web application. JAX-RS annotations MAY be applied
to a bean’s local interface or directly to a no-interface bean. A
WebApplicationException thrown by an EJB resource class or provider
method MUST be treated as an EJB application exception.

If we change that to:

- In a product that also supports EJB, an implementation MUST support
use of stateless and singleton session beans as root resource classes
and providers in a Web application. JAX-RS annotations MAY be applied
to a bean’s local interface or directly to a no-interface bean. If an
ExceptionMapper for a EJBException or subclass is not included with an
application then Exceptions thrown by an EJB resource class or
provider method MUST be treated as EJB application exceptions: the
embedded cause MUST be unwrapped and processed as described in section
3.3.4.

Does that cover it ?

Marc.

>
>
> 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());
>> }
>> }
>> }
>>
>> --
>> Bill Burke
>> JBoss, a division of Red Hat
>> http://bill.burkecentral.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
>> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>