[jboss-cvs] JBossAS SVN: r60814 - in trunk/ejb3/src: test/org/jboss/ejb3/test/jca/inflowmdb and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 22 21:23:57 EST 2007


Author: bill.burke at jboss.com
Date: 2007-02-22 21:23:56 -0500 (Thu, 22 Feb 2007)
New Revision: 60814

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/TestInterceptor.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/JMSMDBBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzMDBBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTest.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTestBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/unit/InflowUnitTestCase.java
Log:
Fix EJBTHREE-891

Modified: trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsFactory.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -18,13 +18,9 @@
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
+*/
 package org.jboss.ejb3.interceptor;
 
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import javax.jms.MessageListener;
 import org.jboss.annotation.ejb.Management;
 import org.jboss.annotation.ejb.Producer;
 import org.jboss.annotation.ejb.Producers;
@@ -40,6 +36,11 @@
 import org.jboss.logging.Logger;
 import org.jboss.util.MethodHashing;
 
+import javax.jms.MessageListener;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  * @version $Revision$
@@ -49,12 +50,13 @@
 
    static Logger log = Logger.getLogger(EJB3InterceptorsFactory.class);
    final static long MESSAGE_LISTENER_ON_MESSAGE;
-   static 
+
+   static
    {
       try
       {
          Class clazz = MessageListener.class;
-         Method m = clazz.getDeclaredMethod("onMessage", new Class[] {javax.jms.Message.class});
+         Method m = clazz.getDeclaredMethod("onMessage", new Class[]{javax.jms.Message.class});
          MESSAGE_LISTENER_ON_MESSAGE = MethodHashing.calculateHash(m);
       }
       catch (Exception e)
@@ -89,10 +91,10 @@
       {
          EJBContainer container = (EJBContainer) advisor;
          Class beanClass = container.getBeanClass();
-   
+
          try
          {
-            Method method =((MethodJoinpoint)jp).getMethod();
+            Method method = ((MethodJoinpoint) jp).getMethod();
             if (isBusinessMethod(container, method))
             {
                InterceptorInfo[] infos = container.getInterceptorRepository().getBusinessInterceptors(container, method);
@@ -103,7 +105,7 @@
          }
          catch (RuntimeException e)
          {
-            throw new RuntimeException("An exception occurred initialising interceptors for " + beanClass + "." + ((MethodJoinpoint)jp).getMethod().getName(), e);
+            throw new RuntimeException("An exception occurred initialising interceptors for " + beanClass + "." + ((MethodJoinpoint) jp).getMethod().getName(), e);
          }
       }
       return new EJB3InterceptorsInterceptor(new InterceptorInfo[0], null);
@@ -117,34 +119,27 @@
    private boolean isBusinessMethod(EJBContainer container, Method method)
    {
       long hash = MethodHashing.calculateHash(method);
-      if (container instanceof MDB)
+      ArrayList<Class> businessInterfaces = getBusinessInterfaces(container);
+      for (Class businessInterface : businessInterfaces)
       {
-         return hash == MESSAGE_LISTENER_ON_MESSAGE;
-      }
-      else
-      {
-         ArrayList<Class> businessInterfaces = getBusinessInterfaces(container);
-         for (Class businessInterface : businessInterfaces)
+         for (Method interfaceMethod : businessInterface.getMethods())
          {
-            for (Method interfaceMethod : businessInterface.getMethods())
+            if (MethodHashing.calculateHash(interfaceMethod) == hash)
             {
-               if (MethodHashing.calculateHash(interfaceMethod) == hash)
-               {
-                  return true;
-               }
+               return true;
             }
          }
       }
-      
+
       return false;
    }
-   
+
    private ArrayList<Class> getBusinessInterfaces(EJBContainer container)
    {
       ArrayList<Class> interfaces = new ArrayList<Class>();
       if (container instanceof ConsumerContainer)
       {
-         Producers producers = (Producers)container.resolveAnnotation(Producers.class);
+         Producers producers = (Producers) container.resolveAnnotation(Producers.class);
          if (producers != null)
          {
             for (Producer producer : producers.value())
@@ -152,13 +147,13 @@
                interfaces.add(producer.producer());
             }
          }
-         
-         Producer producer = (Producer)container.resolveAnnotation(Producer.class);
+
+         Producer producer = (Producer) container.resolveAnnotation(Producer.class);
          if (producer != null)
          {
             interfaces.add(producer.producer());
          }
-         
+
          for (Class implIf : container.getBeanClass().getInterfaces())
          {
             if (implIf.getAnnotation(Producer.class) != null)
@@ -167,6 +162,10 @@
             }
          }
       }
+      else if (container instanceof MDB)
+      {
+         interfaces.add(((MDB)container).getMessagingType());
+      }
       else
       {
          Class[] remotes = ProxyFactoryHelper.getRemoteInterfaces(container);
@@ -179,10 +178,10 @@
          {
             interfaces.addAll(Arrays.asList(locals));
          }
-         
+
          if (container instanceof ServiceContainer)
          {
-            Management man = (Management)container.resolveAnnotation(Management.class);
+            Management man = (Management) container.resolveAnnotation(Management.class);
             if (man != null)
             {
                Class iface = man.value();
@@ -191,7 +190,7 @@
                   interfaces.add(iface);
                }
             }
-            
+
             Class[] implIfaces = container.getBeanClass().getInterfaces();
             for (Class iface : implIfaces)
             {
@@ -202,8 +201,8 @@
             }
          }
       }
-      
+
       return interfaces;
    }
-   
+
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/JMSMDBBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/JMSMDBBean.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/JMSMDBBean.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -41,7 +41,8 @@
 @ActivationConfigProperty(propertyName="maxSession", propertyValue="1")
 })
 @ResourceAdapter("jms-ra.rar")
-public class JMSMDBBean implements MessageListener
+public class
+        JMSMDBBean implements MessageListener
 {
    private static final Logger log = Logger.getLogger(JMSMDBBean.class);
 

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzMDBBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzMDBBean.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzMDBBean.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -33,6 +33,7 @@
 import javax.ejb.ActivationConfigProperty;
 import javax.ejb.TransactionAttribute;
 import javax.ejb.TransactionAttributeType;
+import javax.interceptor.Interceptors;
 
 /**
  *
@@ -44,6 +45,7 @@
 @ActivationConfigProperty(propertyName="cronTrigger", propertyValue="0/2 * * * * ?")
 })
 @ResourceAdapter("quartz-ra.rar")
+ at Interceptors(TestInterceptor.class)
 public class QuartzMDBBean implements Job
 {
    private static final Logger log = Logger.getLogger(QuartzMDBBean.class);

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTest.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTest.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTest.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -35,4 +35,7 @@
    boolean wasCalled();
 
    void clearCalled();
+
+   boolean wasIntercepted()
+           ;
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTestBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTestBean.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/QuartzTestBean.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -37,6 +37,11 @@
       return QuartzMDBBean.called;
    }
 
+   public boolean wasIntercepted()
+   {
+      return TestInterceptor.wasConstructed && TestInterceptor.wasIntercepted;
+   }
+
    public void clearCalled()
    {
        QuartzMDBBean.called = false;

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/TestInterceptor.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/TestInterceptor.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/TestInterceptor.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.test.jca.inflowmdb;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
+import javax.interceptor.AroundInvoke;
+
+/**
+ * comment
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestInterceptor
+{
+   public static boolean wasIntercepted = false;
+   public static boolean wasConstructed = false;
+
+   @PostConstruct
+   public void postConstruct(InvocationContext ctx)
+   {
+      System.out.println("Post   Construct");
+      wasConstructed = true;
+   }
+
+   @AroundInvoke
+   public Object around(InvocationContext ctx) throws Exception
+   {
+      System.out.println("Around   invoke");
+      wasIntercepted = true;
+      return ctx.proceed();
+   }
+
+
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/unit/InflowUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/unit/InflowUnitTestCase.java	2007-02-23 02:04:59 UTC (rev 60813)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/jca/inflowmdb/unit/InflowUnitTestCase.java	2007-02-23 02:23:56 UTC (rev 60814)
@@ -67,6 +67,7 @@
       QuartzTest test = (QuartzTest)InitialContextFactory.getInitialContext().lookup("QuartzTestBean/remote");
       Thread.sleep(5000); // sleep so that quartz mdb runs.
       assertTrue(test.wasCalled());
+      assertTrue(test.wasIntercepted());
    }
    
    public void testJMS() throws Exception




More information about the jboss-cvs-commits mailing list