0 Replies Latest reply on Jul 28, 2009 8:57 AM by David Young

    Problems creating a Retry Interceptor

    David Young Newbie

      Hi, I want to create an interceptor to retry EJB that are using container managed transactions. I am using Jboss 4.2.2, I have written a sample app to attempt to intercept the exceptions from the CMT, but am having problems in getting it working. Any help would be greatly appreciated, or an alternative approach?

      Currently I am getting a Null Pointer Exception.

      13:48:37,750 WARN [ServiceController] Problem starting service jboss.j2ee:ear=RetryTest.ear,jar=RetryTest-ejb.jar,name=SimpleSessionBean,service=EJB3
      java.lang.NullPointerException
       at java.util.Arrays$ArrayList.<init>(Arrays.java:2355)
       at java.util.Arrays.asList(Arrays.java:2341)
       at org.jboss.ejb3.stateless.StatelessRemoteProxyFactory.getInterfaces(StatelessRemoteProxyFactory.java:76)
       at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.init(BaseStatelessProxyFactory.java:163)
       at org.jboss.ejb3.stateless.StatelessRemoteProxyFactory.init(StatelessRemoteProxyFactory.java:113)
       at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.start(BaseStatelessProxyFactory.java:212)
       at org.jboss.ejb3.stateless.StatelessRemoteProxyFactory.start(StatelessRemoteProxyFactory.java:120)
       at org.jboss.ejb3.ProxyDeployer.start(ProxyDeployer.java:83)
      
      


      This is my jboss.xml file

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss>
      
       <container-configuration extends="Standard Stateless SessionBean">
       <container-name>Retry</container-name>
       <container-interceptors>
       <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
       <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
       <interceptor>retrytest.RetryInterceptor</interceptor>
       <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
       <!-- CMT -->
       <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
       </container-interceptors>
       </container-configuration>
      
      
      
      <enterprise-beans>
       <session>
       <ejb-name>SimpleSessionBean</ejb-name>
       <jndi-name>RetryTest/SimpleSessionBean</jndi-name>
       <configuration-name>Retry</configuration-name>
       </session>
       </enterprise-beans>
      </jboss>
      


      This the Interceptor


      
      
      public class RetryInterceptor extends AbstractInterceptor
       {
       private static Log log = LogFactory.getLog(RetryInterceptor.class);
      
       @Override
       public Object invokeHome(final Invocation mi) throws Exception
       {
      
       System.out.println("INVOKE HOME retry INTERCEPTOR");
      
       Object o = null;
       //will wrap up with a retry loop
       try{
       o = getNext().invokeHome(mi);
       }catch(Exception e){
       log.info("RetryInterceptor: retry got an exception "+e);
       e.printStackTrace();
       }
      
       return o;
      
       }
      
       @Override
       public Object invoke(final Invocation mi) throws Exception
       {
       System.out.println("INVOKE retry INTERCEPTOR");
      
      
       Object o = null;
       //will wrap up with a retry loop
       try{
       o = getNext().invoke(mi);
       }catch(Exception e){
       log.debug("RetryInterceptor: retry got an exception "+e);
       e.printStackTrace();
       }
      
       return o;
       }
      }