[jboss-cvs] JBossAS SVN: r81534 - in projects/ejb3/trunk: proxy/src/main/java/org/jboss/ejb3/proxy/remoting and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 25 03:40:28 EST 2008


Author: ALRubinger
Date: 2008-11-25 03:40:28 -0500 (Tue, 25 Nov 2008)
New Revision: 81534

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameBean.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameRemoteBusiness.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/unit/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase.java
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/unit/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase-jboss-beans.xml
Modified:
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/remoting/ProxyRemotingUtils.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree994/StatefulBean.java
Log:
[EJBTHREE-1529][EJBTHREE-994] Implement @RemoteBinding.invokerName and fix regressing EJBTHREE-994 Integration Test

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-11-25 08:28:45 UTC (rev 81533)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -345,10 +345,35 @@
 
                // Get the client bind URL
                String clientBindUrl = defaultClientBindUrl;
+
+               // Override the client bind URL with that associated with @RemoteBinding.invokerName
+               String remoteBindingInvokerBindName = binding.getInvokerName();
+               boolean remoteBindingInvokerNameDefined = remoteBindingInvokerBindName != null
+                     && remoteBindingInvokerBindName.trim().length() > 0;
+               if (remoteBindingInvokerNameDefined)
+               {
+                  clientBindUrl = ProxyRemotingUtils.getClientBinding(remoteBindingInvokerBindName);
+                  log.debug("Using client bind URL of " + clientBindUrl + " as specified by invokerName "
+                        + remoteBindingInvokerBindName + " for EJB " + smd.getName() + " with JNDI Binding: "
+                        + remoteBindingJndiName);
+               }
+
+               // Override the client bind URL with that specified from @RemoteBinding.clientBindUrl
                String remoteBindingClientBindUrl = binding.getClientBindUrl();
                if (remoteBindingClientBindUrl != null && remoteBindingClientBindUrl.trim().length() > 0)
                {
                   clientBindUrl = remoteBindingClientBindUrl;
+                  log.debug("Using client bind URL of " + clientBindUrl + " as specified by clientBindUrl "
+                        + remoteBindingClientBindUrl + " for EJB " + smd.getName() + " with JNDI Binding: "
+                        + remoteBindingJndiName);
+
+                  // Warn the user if he's provided two overrides
+                  if (remoteBindingInvokerNameDefined)
+                  {
+                     log.warn("Both invokerName and clientBindUrl have been specified on "
+                           + RemoteBindingMetaData.class.getSimpleName() + " for EJB " + smd.getName()
+                           + "; clientBindUrl takes priority");
+                  }
                }
 
                // Get the interceptor stack

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/remoting/ProxyRemotingUtils.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/remoting/ProxyRemotingUtils.java	2008-11-25 08:28:45 UTC (rev 81533)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/remoting/ProxyRemotingUtils.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -59,7 +59,10 @@
    private static final String OBJECT_NAME_REMOTING_CONNECTOR = "org.jboss.ejb3.RemotingConnector";
 
    /**
-    * The default URL for InvokerLocator in the case @RemoteBinding does not specify it
+    * The default URL for InvokerLocator in the case @RemoteBinding 
+    * does not specify it
+    * 
+    * Synchronization policy on "this"
     */
    protected static String DEFAULT_CLIENT_BINDING;
 
@@ -86,17 +89,12 @@
       // If the binding has not yet been set
       if (DEFAULT_CLIENT_BINDING == null)
       {
-
          try
          {
-            // Lookup the Connector in MC
-            Connector connector = Ejb3RegistrarLocator.locateRegistrar().lookup(OBJECT_NAME_REMOTING_CONNECTOR,
-                  Connector.class);
-
             // Use the binding specified by the Connector
             try
             {
-               DEFAULT_CLIENT_BINDING = connector.getInvokerLocator();
+               DEFAULT_CLIENT_BINDING = getClientBinding(OBJECT_NAME_REMOTING_CONNECTOR);
             }
             catch (Exception e)
             {
@@ -122,6 +120,48 @@
    }
 
    /**
+    * Obtains the client binding for the specified 
+    * invokerName (supplied as the Object Store bind name in
+    * MC)
+    * 
+    * @param invokerName
+    * @return
+    * @throws NotBoundException If the specified invokerName is not bound in MC
+    */
+   public static String getClientBinding(String invokerName) throws NotBoundException
+   {
+      // Initialize
+      String url = null;
+      Connector connector = null;
+
+      // Lookup the Connector in MC
+      try
+      {
+         connector = Ejb3RegistrarLocator.locateRegistrar().lookup(invokerName, Connector.class);
+      }
+      catch (NotBoundException nbe)
+      {
+         // Log and rethrow
+         log.warn("Could not find the remoting connector for the specified invoker name, " + invokerName + " in MC");
+         throw nbe;
+      }
+
+      // Use the binding specified by the Connector
+      try
+      {
+         url = connector.getInvokerLocator();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Could not obtain " + InvokerLocator.class.getSimpleName()
+               + " from EJB3 Remoting Connector", e);
+      }
+
+      // Return
+      return url;
+   }
+
+   /**
     * Creates a remote proxy to the container using the specified
     * arguments.
     * 

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameBean.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameBean.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameBean.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -0,0 +1,55 @@
+/*
+ * 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.proxy.ejbthree1529;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+
+/**
+ * ExplicitInvokerNameBean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(ExplicitInvokerNameRemoteBusiness.class)
+ at RemoteBinding(invokerName = ExplicitInvokerNameRemoteBusiness.MC_NAME_INVOKER, jndiBinding = ExplicitInvokerNameRemoteBusiness.JNDI_NAME_EXPLICIT_INVOKER_NAME)
+public class ExplicitInvokerNameBean implements ExplicitInvokerNameRemoteBusiness
+{
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Returns the contracted RETURN_VALUE
+    * 
+    * @return
+    */
+   public String invoke()
+   {
+      return ExplicitInvokerNameRemoteBusiness.RETURN_VALUE;
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameRemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameRemoteBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/ExplicitInvokerNameRemoteBusiness.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -0,0 +1,55 @@
+/*
+ * 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.proxy.ejbthree1529;
+
+/**
+ * ExplicitInvokerNameRemoteBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ExplicitInvokerNameRemoteBusiness
+{
+   // --------------------------------------------------------------------------------||
+   // Constants ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   String RETURN_VALUE = "Hip hip hurray!";
+
+   /**
+    * Name of the invoker in MC as defined by the MC *-jboss-beans.xml
+    */
+   String MC_NAME_INVOKER = "ejbthree1529.Connector";
+
+   String JNDI_NAME_EXPLICIT_INVOKER_NAME = "ExplicitInvokerName";
+
+   // --------------------------------------------------------------------------------||
+   // Contracts ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Returns the contracted RETURN_VALUE
+    * 
+    * @return
+    */
+   String invoke();
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -0,0 +1,140 @@
+/*
+ * 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.proxy.ejbthree1529.unit;
+
+import java.lang.reflect.Proxy;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.proxy.handler.session.stateless.StatelessRemoteProxyInvocationHandler;
+import org.jboss.ejb3.proxy.remoting.ProxyRemotingUtils;
+import org.jboss.ejb3.test.proxy.common.SessionTestCaseBase;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.SessionContainer;
+import org.jboss.ejb3.test.proxy.ejbthree1529.ExplicitInvokerNameBean;
+import org.jboss.ejb3.test.proxy.ejbthree1529.ExplicitInvokerNameRemoteBusiness;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * RemoteBindingInvokerNameTestCase
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class RemoteBindingInvokerNameTestCase extends SessionTestCaseBase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(RemoteBindingInvokerNameTestCase.class);
+
+   protected static Context context = null;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Tests that a bean defined with an explicit @RemoteBinding.invokerName
+    * is able to be reached via its clientBindUrl (InvokerLocator)
+    */
+   @Test
+   public void testExplicitInvokerName() throws Throwable
+   {
+      // Initialize
+      String jndiName = ExplicitInvokerNameRemoteBusiness.JNDI_NAME_EXPLICIT_INVOKER_NAME;
+
+      // Get the bean
+      ExplicitInvokerNameRemoteBusiness bean = (ExplicitInvokerNameRemoteBusiness) context.lookup(jndiName);
+
+      /*
+       * Break into Proxy internals to assure we've got the right clientBindUrl
+       * associated w/ the invoker name
+       */
+
+      // Get the expected bind URL
+      String invokerName = ExplicitInvokerNameRemoteBusiness.MC_NAME_INVOKER;
+      String expectedClientBindUrl = ProxyRemotingUtils.getClientBinding(invokerName);
+
+      // Get the clientBindUrl from the Proxy itself
+      Class<?> proxyClass = bean.getClass();
+      assert Proxy.isProxyClass(proxyClass) : "Stub from JNDI was not a " + Proxy.class.getName();
+      StatelessRemoteProxyInvocationHandler handler = (StatelessRemoteProxyInvocationHandler) Proxy
+            .getInvocationHandler(bean);
+      String clientBindUrl = handler.getUrl();
+
+      // Ensure the expected value is what we've got in the proxy
+      TestCase.assertEquals("clientBindUrls are not equal", expectedClientBindUrl, clientBindUrl);
+
+      // Invoke
+      String returnValue = bean.invoke();
+
+      // Test return value
+      TestCase.assertEquals("Didn't get expected return value", ExplicitInvokerNameRemoteBusiness.RETURN_VALUE,
+            returnValue);
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+   /**
+    * Perform setup before any tests
+    * 
+    * @throws Throwable
+    */
+   @BeforeClass
+   public static void setUpBeforeClass() throws Throwable
+   {
+      // Create Bootstrap and Deploy
+      SessionTestCaseBase.setUpBeforeClass();
+
+      // Deploy MC Beans
+      bootstrap.deploy(SessionTestCaseBase.class);
+      bootstrap.deploy(RemoteBindingInvokerNameTestCase.class);
+
+      // Create container
+      SessionContainer container = Utils.createSlsb(ExplicitInvokerNameBean.class);
+
+      // Install
+      Ejb3RegistrarLocator.locateRegistrar().bind(container.getName(), container);
+
+      // Set Naming COntext
+      context = new InitialContext(); // Props from jndi.properties
+   }
+
+   @AfterClass
+   public static void tearDownAfterClass() throws Exception
+   {
+      if (bootstrap != null)
+         bootstrap.shutdown();
+      bootstrap = null;
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase-jboss-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/ejbthree1529/unit/RemoteBindingInvokerNameTestCase-jboss-beans.xml	2008-11-25 08:40:28 UTC (rev 81534)
@@ -0,0 +1,14 @@
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+  xmlns="urn:jboss:bean-deployer:2.0">
+
+  <!-- Define an additional Remoting Connector -->
+  <bean name="ejbthree1529.Connector"
+    class="org.jboss.remoting.transport.Connector">
+    <property name="invokerLocator">socket://0.0.0.0:3874</property>
+    <property name="serverConfiguration">
+      <inject bean="ServerConfiguration" />
+    </property>
+  </bean>
+
+</deployment>
\ No newline at end of file

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree994/StatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree994/StatefulBean.java	2008-11-25 08:28:45 UTC (rev 81533)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree994/StatefulBean.java	2008-11-25 08:40:28 UTC (rev 81534)
@@ -35,7 +35,7 @@
 @RemoteBindings({
    @RemoteBinding(clientBindUrl="socket://0.0.0.0:3873", jndiBinding="Stateful3873"),
    @RemoteBinding(clientBindUrl="socket://0.0.0.0:3874", jndiBinding="Stateful3874"),
-   @RemoteBinding(invokerName="jboss.remoting.test:type=Connector,name=Ejbthree994TestEjb3Connector,handler=ejb3", jndiBinding="Stateful3875")
+   @RemoteBinding(invokerName="org.jboss.ejb3.RemotingConnector-EJBTHREE994-3", jndiBinding="Stateful3875")
 })
 @Remote(BusinessInterface.class)
 public class StatefulBean implements BusinessInterface




More information about the jboss-cvs-commits mailing list