14 Replies Latest reply on Apr 1, 2012 3:44 AM by spangaer

    Why application exceptions are wrapped in EJBException on AS 6.1?

    renz13

      Hello,

       

      I'm trying to deploy a Stateless Session Bean with Bean-Managed Transaction on JBoss AS 6.1 with the default configuration.

      Methods in that bean throws application exceptions, which are annotated with @ApplicationException.

       

      When a method throws an application exception, it's wrapped in an EJBException.

       

      If I use Container-Managed Transaction, application exceptions are not wrapped in EJBException.

       

      The Stateless Session Bean  (I use a very simple case as an example, but the problem is the same) :

       

      {code:java}package org.helloworld;

       

      import javax.ejb.Stateless;

      import javax.ejb.TransactionManagement;

      import javax.ejb.TransactionManagementType;

      import org.helloworld.exception.MyAppException;

       

      @Stateless

      @TransactionManagement(TransactionManagementType.BEAN)

      public class MyBean implements MyBeanRemote {

       

          public MyBean() { }

       

          @Override

          public void doSomething(boolean throwException) throws MyAppException {

              if (throwException) {

                  throw new MyAppException("Oops") ;

              }

              else {

                  return ;

              }

          }

       

      }{code}

       

      The remote interface :

       

      {code:java}package org.helloworld;

      import javax.ejb.Remote;

       

      import org.helloworld.exception.MyAppException;

       

      @Remote

      public interface MyBeanRemote {

       

          public void doSomething(boolean throwException) throws MyAppException;

       

      }{code}

       

      The application exception :

       

      {code:java}

      package org.helloworld.exception;

       

      import javax.ejb.ApplicationException;

       

      @ApplicationException

      public class MyAppException extends Exception {

       

          private static final long serialVersionUID = 1L;

       

          public MyAppException() {

              super();

          }

       

          public MyAppException(String arg0, Throwable arg1) {

              super(arg0, arg1);

          }

       

          public MyAppException(String arg0) {

              super(arg0);

          }

       

          public MyAppException(Throwable arg0) {

              super(arg0);

          }   

      }

      {code}

       

      The client program (java SE) :

       

      {code:java}

      package org.helloworld.client;

       

      import javax.naming.InitialContext;

       

      import org.helloworld.MyBeanRemote;

      import org.helloworld.exception.MyAppException;

       

      public class MyAppClient {

       

          public static void main(String[]  args){

              try {

                  InitialContext ctxt = new InitialContext() ;

                  MyBeanRemote myBean = (MyBeanRemote) ctxt.lookup("HelloworldEAR/MyBean/remote") ;

                  myBean.doSomething(true) ;

              }

              catch (MyAppException e) {

                  System.err.println("My App Exception Message : "+e.getMessage()) ;

              }

              catch(Exception e) {

                  e.printStackTrace() ;

              }

          }

      }

      {code}

       

      And here, the stacktrace, when I run the client code :

       

      {color:red}

      javax.ejb.EJBException: org.helloworld.exception.MyAppException: Oops

          at org.jboss.ejb3.tx.BMTInterceptor.handleException(BMTInterceptor.java:94)

          at org.jboss.ejb3.tx.StatelessBMTInterceptor.checkStatelessDone(StatelessBMTInterceptor.java:89)

          at org.jboss.ejb3.tx.StatelessBMTInterceptor.handleInvocation(StatelessBMTInterceptor.java:105)

          at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:57)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.tx2.aop.NoOpInterceptor.invoke(NoOpInterceptor.java:45)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:392)

          at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)

          at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)

          at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)

          at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:967)

          at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:791)

          at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:744)

          at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548)

          at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234)

      Caused by: org.helloworld.exception.MyAppException: Oops

          at org.helloworld.MyBean.doSomething(MyBean.java:20)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)

          at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72)

          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127)

          at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:151)

          at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doAroundInvoke(Jsr299BindingsInterceptor.java:122)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80)

          at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71)

          at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62)

          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127)

          at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:57)

          at org.jboss.weld.integration.deployer.metadata.WeldLifecycleInterceptor.doAroundInvoke(WeldLifecycleInterceptor.java:55)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80)

          at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71)

          at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62)

          at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)

          at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:74)

          at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_22758614.invoke(InvocationContextInterceptor_z_fillMethod_22758614.java)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:90)

          at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_22758614.invoke(InvocationContextInterceptor_z_setup_22758614.java)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor.invoke(AsynchronousServerInterceptor.java:128)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.tx.StatelessBMTInterceptor.handleInvocation(StatelessBMTInterceptor.java:100)

          at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:57)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.tx2.aop.NoOpInterceptor.invoke(NoOpInterceptor.java:45)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:392)

          at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)

          at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)

          at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)

          at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:967)

          at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:791)

          at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:744)

          at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548)

          at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234)

          at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:218)

          at org.jboss.remoting.Client.invoke(Client.java:2070)

          at org.jboss.remoting.Client.invoke(Client.java:879)

          at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor.invoke(AsynchronousClientInterceptor.java:143)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

          at $Proxy4.invoke(Unknown Source)

          at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185)

          at $Proxy3.doSomething(Unknown Source)

          at org.helloworld.client.MyAppClient.main(MyAppClient.java:14)

          at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor.invoke(AsynchronousClientInterceptor.java:143)

          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

          at $Proxy4.invoke(Unknown Source)

          at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185)

          at $Proxy3.doSomething(Unknown Source)

          at org.helloworld.client.MyAppClient.main(MyAppClient.java:14)

      {color}

       

       

      Is there something i made wrong?


      Thx

        • 1. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
          typek_pb

          we're facing the same problem on our project, and as EJBException wrapping is not acceptable for us (huge impact on bussines logic), is there any way to prevent it and have the good old behavior as in JBoss 6.0.0?

          thanks

          • 2. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
            jaikiran

            Is this happening with Bean managed transactions? I'm not really sure what changed in 6.1.0.

            • 3. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
              wolfc

              Looks like EJBTHREE-2261.

              • 4. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                renz13

                If I use JBoss 6.0.0, application exceptions are wrapped into WeldException. I'm using CDI and it seems to be the same problem as : http://community.jboss.org/thread/169420

                 

                I'm using Bean Managed Transactions (@TransactionManagement(TransactionManagementType.BEAN)). I've tried with Container-Managed Transactions, and everything works perfectly, but I have to use Bean-Managed Transactions

                 

                Carlo, maybe it also looks like https://issues.jboss.org/browse/JBAS-9443 . Of course I'm not using Stateful Bean, so bean destruction is not a problem, but application exceptions are wrapped into EjbException in that bug as well.

                • 5. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                  goldm

                  Yes, it is happening exactly for beans with TransactionManagementType.BEAN, I guess its also visible in stacktrace submitted by renz13, I have attached sample project/app you can use to reproduce it. Is it possible that there will be any solution for 6.1?

                  • 6. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                    sbaust

                    hi,

                     

                    i'm having the same problem here, is there any workaround?

                    • 7. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                      goldm

                      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)

                      • 8. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                        wolfc

                        Nice work.

                         

                        You may want to use the ExtendedAdvisor:

                        if (ExtendedAdvisorHelper.getExtendedAdvisor(advisor).isAnnotationPresent(ex, ApplicationException.class))
                        {
                           throw ex;
                        }
                        

                         

                        The ExtendedAdvisor also takes descriptor metadata into account.

                        1 of 1 people found this helpful
                        • 9. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                          renz13

                          Thanks for your help.

                           

                          I don't know what to do with your class (but I understand its purpose) :

                          - pack it in my EAR?

                          - pack it in a jar and put it in the lib directory, in my server conf?

                          - something else?

                          • 10. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                            goldm

                            Just pack this custom class in jar (you will probably need to create simple maven module - pom file attached) and place jar in JBOSS_HOME/common/lib, then also replace class org.jboss.ejb3.tx.BMTTxInterceptorFactory in configuration files ejb3-interceptors-aop.xml and singleton-container-aop.xml with custom class.

                            1 of 1 people found this helpful
                            • 11. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                              renz13

                              Thank you for your help.

                              • 12. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                                spangaer

                                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());

                                 

                                    }

                                 

                                }

                                • 13. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                                  typek_pb

                                  sounds like there should be bug filled to make sure it can be fixed upstream.

                                  Any volunteer?

                                  • 14. Re: Why application exceptions are wrapped in EJBException on AS 6.1?
                                    spangaer