goldm [http://community.jboss.org/people/goldm] created the discussion

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

To view the discussion, visit: http://community.jboss.org/message/635878#635878

--------------------------------------------------------------
Hi,

yes, there is one. You can extend BMTTxInterceptorFactory and override method 
createPerJoinpoint. In returned instance of StatelessBMTInterceptor, override 
handleException method - check if ApplicationException annotation is present on 
exception class.

Something like this:

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) {
             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))
               {
                  throw ex;
               }
               if (ex instanceof EJBException)
               {
                  throw (EJBException) ex;
               }
               else
               {
                  throw new EJBException(ex);
               }
             }
         };
   }
}

Then you have to use BMTTxInterceptorFactoryCustom instead of 
BMTTxInterceptorFactory (configured in ejb3-interceptors-aop.xml and 
singleton-container-aop.xml)
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/635878#635878]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to