JBoss Community

Re: Why application exceptions are wrapped in EJBException on AS 6.1?

created by spangaer in EJB3 - View the full discussion

Ive put in in  jboss\server\default\lib in a jar. And my a small modification to respect inheritence.

 

public class BMTTxInterceptorFactoryCustom extends BMTTxInterceptorFactory {

 

    @SuppressWarnings("unused")

    private static final Logger log = Logger.getLogger(BMTTxInterceptorFactoryCustom.class);

 

    public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) {

        // We have to do this until AOP supports matching based on annotation attributes

        TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);

        if (type != TransactionManagementType.BEAN)

            return new NullInterceptor();

        TransactionManager tm = TxUtil.getTransactionManager();

        boolean stateful = advisor.resolveAnnotation(Stateful.class) != null;

        // Both MessageDriven and Stateless are stateless

        if (stateful)

            return new StatefulBMTInterceptor(tm);

        else

            return new StatelessBMTInterceptor(tm) {

                @SuppressWarnings("unused")

                protected void handleException(Invocation invocation, Exception ex) throws Exception {

                    if (ex == null) {

                        return;

                    }

                    ApplicationException ae = (ApplicationException) invocation.getAdvisor()

                            .resolveAnnotation(ApplicationException.class);

                    // it's an application exception, so just throw it back as-is

                    if (ae != null || ex.getClass().isAnnotationPresent(ApplicationException.class)

                            || isApplicationExceptionPresentInParent(ex.getClass().getSuperclass())) {

                        throw ex;

                    }

                    if (ex instanceof EJBException) {

                        throw (EJBException) ex;

                    } else {

                        throw new EJBException(ex);

                    }

                }

            };

    }

 

    private boolean isApplicationExceptionPresentInParent(Class<?> parent) {

        if (Object.class.equals(parent))

            return false;

 

        ApplicationException anot = parent.getAnnotation(ApplicationException.class);

 

        if (anot != null)

            return anot.inherited();

        else

            return isApplicationExceptionPresentInParent(parent.getSuperclass());

 

    }

 

}

Reply to this message by going to Community

Start a new discussion in EJB3 at Community