[jboss-cvs] JBossAS SVN: r84715 - in projects/ejb3/trunk: core/src/main/java/org/jboss/ejb3/service and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 25 05:57:30 EST 2009


Author: jaikiran
Date: 2009-02-25 05:57:30 -0500 (Wed, 25 Feb 2009)
New Revision: 84715

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceManagement.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceWithOverloadedMethods.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/unit/ServiceTestCase.java
Modified:
   projects/ejb3/trunk/as-int/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceMBeanDelegate.java
   projects/ejb3/trunk/plugin/pom.xml
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-1677 Incorrect handling of overloaded methods in a @Service. Fixed the ServiceMBeanDelegate which was looking up an internal cache of Methods using the incorrect key

Modified: projects/ejb3/trunk/as-int/pom.xml
===================================================================
--- projects/ejb3/trunk/as-int/pom.xml	2009-02-25 10:54:58 UTC (rev 84714)
+++ projects/ejb3/trunk/as-int/pom.xml	2009-02-25 10:57:30 UTC (rev 84715)
@@ -29,7 +29,7 @@
     into the AS
     
      -->
-    <version.org.jboss.ejb3_core>1.1.1</version.org.jboss.ejb3_core>
+    <version.org.jboss.ejb3_core>1.1.2-SNAPSHOT</version.org.jboss.ejb3_core>
     <version.org.jboss.ejb3_deployers>1.0.0</version.org.jboss.ejb3_deployers>
     <version.org.jboss.ejb3_mc.int>1.0.0</version.org.jboss.ejb3_mc.int>
   

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceMBeanDelegate.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceMBeanDelegate.java	2009-02-25 10:54:58 UTC (rev 84714)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceMBeanDelegate.java	2009-02-25 10:57:30 UTC (rev 84715)
@@ -58,7 +58,7 @@
 public class ServiceMBeanDelegate implements DynamicMBean, XMBeanConstants
 {
    private static final Logger log = Logger.getLogger(ServiceMBeanDelegate.class);
-   
+
    MBeanServer server;
    ServiceContainer container;
    ObjectName serviceOn;
@@ -87,7 +87,7 @@
       }
       mbeanInfo = mbean.getMBeanInfo();
    }
-   
+
    public ServiceMBeanDelegate(MBeanServer server, ServiceContainer container, String xmbean, ObjectName on)
    {
       this.container = container;
@@ -201,7 +201,7 @@
    {
       if(log.isTraceEnabled())
          log.trace("invoke: " + actionName);
-      
+
       try
       {
          // EJBTHREE-655: intercept lifecycle methods
@@ -210,7 +210,7 @@
 //            invokeMagicLifecycleMethod(actionName);
 //            return null;
 //         }
-         
+
          Method operation = getOperation(actionName, signature);
          return container.localInvoke(operation, params);
       }
@@ -231,7 +231,7 @@
       //Not really the signature, just something unique
       StringBuffer sig = new StringBuffer();
       sig.append(actionName);
-      
+
       if (types != null)
       {
          for (int i = 0; i < types.length; i++)
@@ -358,7 +358,7 @@
    private Method getOperation(String actionName, String[] signature) throws ReflectionException
    {
       String opSig = getOperationSignature(actionName, signature);
-      Method operation = operations.get(actionName);
+      Method operation = operations.get(opSig);
 
       if (operation == null && !setterBlackList.contains(opSig))
       {
@@ -452,7 +452,7 @@
       else
          throw new IllegalArgumentException("can't invoke " + operationName);
    }
-   
+
    protected boolean isMagicLifecycleMethod(String methodName)
    {
       if(methodName.equals("create"))

Modified: projects/ejb3/trunk/plugin/pom.xml
===================================================================
--- projects/ejb3/trunk/plugin/pom.xml	2009-02-25 10:54:58 UTC (rev 84714)
+++ projects/ejb3/trunk/plugin/pom.xml	2009-02-25 10:57:30 UTC (rev 84715)
@@ -63,7 +63,7 @@
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-as-int</artifactId>
-      <version>1.1.1</version>
+      <version>1.1.2-SNAPSHOT</version>
       <optional>true</optional>
     </dependency>
 

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2009-02-25 10:54:58 UTC (rev 84714)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2009-02-25 10:57:30 UTC (rev 84715)
@@ -276,6 +276,12 @@
       <jvmarg value="${ejb3.jboss.jvmargs}" />
     </server>
 
+
+    <!-- ejbthree1677 -->
+    <server name="ejbthree1677" host="${node0}">
+      <jvmarg value="${ejb3.jboss.jvmargs}" />
+    </server>
+
   </server:config>
 
    <!-- =================== -->
@@ -4225,6 +4231,19 @@
          	</fileset>
       </jar>
 	</target>
+
+  <target name="ejbthree1677"
+      description="Builds all jar files required to test EJBTHREE-1677."
+      >
+	<delete file="${build.lib}/ejbthree1677.jar"/>
+      <mkdir dir="${build.lib}"/>
+
+      <jar jarfile="${build.lib}/ejbthree1677.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/ejbthree1677/*.class"/>
+         </fileset>
+      </jar>
+   </target>
    
    <target name="jars" depends="statefulproxyfactoryoverride, removedislocal, statelesscreation, defaultremotebindings, localfromremote, clusteredjms, entityoptimisticlocking, concurrentnaming, propertyreplacement, persistenceunits, appclient, tck5sec, invalidtxmdb, descriptortypo, libdeployment, homeinterface, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader,
       concurrent,
@@ -4254,7 +4273,7 @@
       timer, benchmark, entity, joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression,
       composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc,
       localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor,
-      statelesscreation, changexml, externalrefscoped, singleton, ejbthree1671"/>
+      statelesscreation, changexml, externalrefscoped, singleton, ejbthree1671, ejbthree1677"/>
 
    <target name="test" depends="init" if="test"
       description="Execute all tests in the given test directory.">

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceManagement.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceManagement.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceManagement.java	2009-02-25 10:57:30 UTC (rev 84715)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1677;
+
+/**
+ * ServiceManagement
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface ServiceManagement
+{
+
+   String sayHi(String name);
+
+   String sayHi();
+
+   String echoMessage(String message);
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceWithOverloadedMethods.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceWithOverloadedMethods.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/ServiceWithOverloadedMethods.java	2009-02-25 10:57:30 UTC (rev 84715)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1677;
+
+import javax.ejb.Remote;
+
+import org.jboss.ejb3.annotation.Management;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.annotation.Service;
+import org.jboss.ejb3.test.ejbthree1677.unit.ServiceTestCase;
+
+/**
+ * ServiceWithOverloadedMethods
+ *
+ * Meant for test EJBTHREE-1677. Used in
+ * {@link ServiceTestCase}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Service(objectName = ServiceWithOverloadedMethods.OBJECT_NAME)
+ at Management(ServiceManagement.class)
+ at Remote(ServiceManagement.class)
+ at RemoteBinding(jndiBinding = ServiceWithOverloadedMethods.JNDI_NAME)
+public class ServiceWithOverloadedMethods implements ServiceManagement
+{
+   public static final String OBJECT_NAME = "ejbthree1677:service=ServiceWithOverloadedMethods";
+
+   public static final String JNDI_NAME = "ejbthree1677/ServiceWithOverloadedMethods";
+
+   public String echoMessage(String message)
+   {
+      return message;
+   }
+
+   public String sayHi(String name)
+   {
+      return "Hi " + name;
+   }
+
+   public String sayHi()
+   {
+      return "Hi";
+   }
+
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/unit/ServiceTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/unit/ServiceTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1677/unit/ServiceTestCase.java	2009-02-25 10:57:30 UTC (rev 84715)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1677.unit;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.service.ServiceMBeanDelegate;
+import org.jboss.ejb3.test.ejbthree1677.ServiceManagement;
+import org.jboss.ejb3.test.ejbthree1677.ServiceWithOverloadedMethods;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * ServiceTestCase
+ *
+ * Tests the fix for EJBTHREE-1677.
+ *
+ * Original issue : If a @Service had overloaded methods
+ * (ex: one accepting no parameters and the other accepting a parameter),
+ * then when the service was invoked in the following sequence, an exception
+ * was thrown:
+ * 1) first invoke the overloaded method which does not accept the param
+ * 2) then invoke the overloaded method which accepts the param
+ * The issue was in the {@link ServiceMBeanDelegate} which has a cache of
+ * Method based on method name and signature. The cache was being requested for
+ * the corresponding method using only the method name, which resulted in this bug.
+ * Fixed appropriately to consult the cache using the entire method name and signature.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ServiceTestCase extends JBossTestCase
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(ServiceTestCase.class);
+
+   /**
+    * Constructor
+    *
+    * @param name
+    */
+   public ServiceTestCase(String name)
+   {
+      super(name);
+
+   }
+
+   /**
+    * Deploy our testable application
+    *
+    * @return
+    * @throws Exception
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ServiceTestCase.class, "ejbthree1677.jar");
+   }
+
+   /**
+    * Test that the overloaded methods on a @Service work fine when the
+    * service is invoked through a MBeanServer
+    *
+    * @throws Exception
+    */
+   public void testOverloadedMethodsAsMBean() throws Exception
+   {
+      Context ctx = new InitialContext();
+      MBeanServerConnection mbeanServer = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
+      ObjectName serviceObjectName = new ObjectName(ServiceWithOverloadedMethods.OBJECT_NAME);
+
+      // Invoke an overloaded method which does NOT accept param
+      String expectedGreeting = "Hi";
+      String greeting = (String) mbeanServer.invoke(serviceObjectName, "sayHi", new Object[0], new String[0]);
+
+      assertNotNull("Service did not say hi", greeting);
+      assertEquals("Service returned unexpected greeting", expectedGreeting, greeting);
+
+      // Now invoke the overloaded method which accepts params
+      String name = "jaikiran";
+      String anotherExpectedGreeting = "Hi " + name;
+      String[] paramForOverloadedMethod =
+      {name};
+      String[] signatureOfOverloadedMethod =
+      {"java.lang.String"};
+      String anotherGreeting = (String) mbeanServer.invoke(serviceObjectName, "sayHi", paramForOverloadedMethod,
+            signatureOfOverloadedMethod);
+      assertNotNull("Service did not say hi on overloaded method", anotherGreeting);
+      assertEquals("Service returned unexpected greeting from overloaded method", anotherExpectedGreeting,
+            anotherGreeting);
+
+      // Now invoke a totally unrelated method (just to ensure nothing breaks)
+      String message = "Welcome";
+      String[] paramForUnrelateMethod =
+      {message};
+      String[] signatureOfUnrelateMethod =
+      {"java.lang.String"};
+      String returnedMessage = (String) mbeanServer.invoke(serviceObjectName, "echoMessage", paramForUnrelateMethod,
+            signatureOfUnrelateMethod);
+      assertNotNull("Service did not echo back the message", returnedMessage);
+      assertEquals("Service returned unexpected echo", returnedMessage, message);
+
+
+   }
+
+   /**
+    * Test that the overloaded methods on a @Service work fine when the service
+    * methods are invoked using the corresponding management interface.
+    *
+    * @throws Exception
+    */
+   public void testAsEJB3Service() throws Exception
+   {
+      // lookup bean
+      Context ctx = new InitialContext();
+      ServiceManagement service = (ServiceManagement) ctx.lookup(ServiceWithOverloadedMethods.JNDI_NAME);
+
+      // call the relevant methods
+      String message = "hello";
+      String returnedMessage = service.echoMessage(message);
+
+      assertNotNull("Service did not echo back the message", returnedMessage);
+      assertEquals("Service returned unexpected echo", returnedMessage, message);
+
+      // overloaded method without param
+      String expectedGreeting = "Hi";
+      String returnedGreeting = service.sayHi();
+      assertNotNull("Service did not say hi", expectedGreeting);
+      assertEquals("Service returned unexpected greeting", expectedGreeting, returnedGreeting);
+
+      // now the overloaded method with param
+      String name = "newuser";
+      String anotherExpectedGreeting = "Hi " + name;
+      String anotherReturnedGreeting = service.sayHi(name);
+
+      assertNotNull("Service did not say hi on overloaded method", anotherReturnedGreeting);
+      assertEquals("Service returned unexpected greeting from overloaded method", anotherExpectedGreeting,
+            anotherReturnedGreeting);
+
+   }
+}




More information about the jboss-cvs-commits mailing list