[jboss-cvs] JBossAS SVN: r65238 - in branches/JBPAPP_4_2/ejb3: src/main/org/jboss/ejb3 and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 7 14:03:46 EDT 2007


Author: bdecoste
Date: 2007-09-07 14:03:46 -0400 (Fri, 07 Sep 2007)
New Revision: 65238

Added:
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/JndiUtil.java
Modified:
   branches/JBPAPP_4_2/ejb3/build-test.xml
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiPropertyInjector.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/QueueTestMDB.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/unit/MDBUnitTestCase.java
Log:
[JBPAPP-260] merge from JBPAPP_4_2_0_GA_CP

Modified: branches/JBPAPP_4_2/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2/ejb3/build-test.xml	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/build-test.xml	2007-09-07 18:03:46 UTC (rev 65238)
@@ -4217,20 +4217,19 @@
             <include name="deploy-hasingleton/**"/>
          </patternset>
       </create-config>
-      <create-config baseconf="all" newconf="clusteredjms2">
+      <create-config baseconf="clusteredjms" newconf="clusteredjms2">
          <patternset>
 	        <include name="conf/**"/>
 	        <include name="deploy*/**"/>
 	        <include name="lib/**"/>
             <include name="deploy-hasingleton/**"/>
-            <exclude name="deploy-hasingleton/mdbtest-service.xml"/>
          </patternset>
       </create-config>
       
-      <start-jboss conf="clusteredjms" host="${node0}" jvmargs="${ejb3.jboss.jvmargs}"/>
-	  <start-jboss conf="clusteredjms2" host="${node1}" jvmargs="${ejb3.jboss.jvmargs}"/>
-	  
-	  <antcall target="tests-clustering-wait"/> 
+   	  <start-jboss conf="clusteredjms2" host="${node1}" jboss.dist="${ejb3.dist}" jvmargs="${ejb3.jboss.jvmargs}"/>
+   	  <antcall target="tests-clusteredjms2-wait"/> 
+   	  <start-jboss conf="clusteredjms" host="${node0}" jboss.dist="${ejb3.dist}" jvmargs="${ejb3.jboss.jvmargs}"/>	 
+   	  <antcall target="tests-clusteredjms-wait"/>
 	
 	  <antcall target="test-with-jvmargs" inheritRefs="true">
          <param name="test" value="clusteredjms"/>
@@ -4255,6 +4254,30 @@
       <echo message="Nodes have started, waiting for cluster to stablize..."/>
    </target>
 	
+   <target name="tests-clusteredjms-wait" unless="${tests.clustering.skip.startup}">
+      <echo message="Waiting for node to start..."/>
+      <waitfor maxwait="120" maxwaitunit="second"
+         checkevery="5" checkeveryunit="second" timeoutproperty="cluster.timeout">
+         <and>
+            <http url="${node0.http.url}"/>
+         </and>
+      </waitfor>
+      <fail message="Timeout waiting for nodes to start" if="cluster.timeout"/>
+      <echo message="Nodes have started, waiting for cluster to stablize..."/>
+   </target>
+	
+   <target name="tests-clusteredjms2-wait" unless="${tests.clustering.skip.startup}">
+      <echo message="Waiting for node to start..."/>
+      <waitfor maxwait="120" maxwaitunit="second"
+         checkevery="5" checkeveryunit="second" timeoutproperty="cluster.timeout">
+         <and>
+            <http url="${node1.http.url}"/>
+         </and>
+      </waitfor>
+      <fail message="Timeout waiting for nodes to start" if="cluster.timeout"/>
+      <echo message="Nodes have started, waiting for cluster to stablize..."/>
+   </target>
+	
    <target name="tests-multi-instance-wait" unless="${tests.clustering.skip.startup}">
       <echo message="Waiting for nodes to start..."/>
       <waitfor maxwait="120" maxwaitunit="second"

Added: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/JndiUtil.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/JndiUtil.java	                        (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/JndiUtil.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class JndiUtil
+{
+   private static final Logger log = Logger.getLogger(JndiUtil.class);
+   
+   public static Object lookup(Context jndiContext, String binding)
+      throws NamingException
+   {
+      Object object = null;
+
+      try
+      {
+         object = jndiContext.lookup(binding);
+      }
+      catch (NameNotFoundException e)
+      {
+         Context haCtx = InitialContextFactory.getHAContext(jndiContext);
+         object = haCtx.lookup(binding);
+      }
+      
+      return object;
+   }
+}
+
+


Property changes on: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/JndiUtil.java
___________________________________________________________________
Name: svn:executable
   + *

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -28,6 +28,7 @@
 import org.jboss.logging.Logger;
 
 import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.JndiUtil;
 
 /**
  * Comment
@@ -78,7 +79,7 @@
 
       try
       {
-         dependency = ctx.lookup(jndiName);
+         dependency = JndiUtil.lookup(ctx, jndiName);
 
          if (dependency instanceof javax.xml.rpc.Service && !field.isAssignableFrom(javax.xml.rpc.Service.class))
          {

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -26,6 +26,7 @@
 import javax.naming.Context;
 import javax.naming.NamingException;
 import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.JndiUtil;
 import org.jboss.logging.Logger;
 
 /**
@@ -68,7 +69,7 @@
       
       try
       {
-         dependency = ctx.lookup(jndiName);
+         dependency = JndiUtil.lookup(ctx, jndiName);
       }
       catch (NamingException e)
       {

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiPropertyInjector.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiPropertyInjector.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/JndiPropertyInjector.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -25,6 +25,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.JndiUtil;
 import org.jboss.injection.lang.reflect.BeanProperty;
 import org.jboss.logging.Logger;
 
@@ -41,6 +42,7 @@
    private static final Logger log = Logger.getLogger(JndiPropertyInjector.class);
    
    private String jndiName;
+   private String mappedName;
    private Context ctx;
 
    public JndiPropertyInjector(BeanProperty property, String jndiName, Context ctx)
@@ -49,6 +51,14 @@
       this.jndiName = jndiName;
       this.ctx = ctx;
    }
+   
+   public JndiPropertyInjector(BeanProperty property, String jndiName, String mappedName, Context ctx)
+   {
+      super(property);
+      this.jndiName = jndiName;
+      this.mappedName = mappedName;
+      this.ctx = ctx;
+   }
 
    public void inject(BeanContext bctx)
    {
@@ -66,13 +76,27 @@
       
       try
       {
-         dependency = ctx.lookup(jndiName);
+         dependency = JndiUtil.lookup(ctx, jndiName);
       }
       catch (NamingException e)
       {
-         Throwable cause = e;
+         if (mappedName != null)
+         {
+            try
+            {
+               dependency = JndiUtil.lookup(ctx, mappedName);
+               return dependency;
+            }
+            catch (NamingException e1)
+            {   
+               log.info("Unable to lookup jndi dependency from mappedName " + mappedName);
+            }
+         }
+         
+         Throwable cause = e; 
          while(cause.getCause() != null)
             cause = cause.getCause();
+      
          throw new RuntimeException("Unable to inject jndi dependency: " + jndiName + " into property " + property + ": " + cause.getMessage(), e);
       }
       return dependency;

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -507,7 +507,7 @@
             }
             container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
          }
-         injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
+         injectors.put(accObj, new JndiPropertyInjector(property, encName, ref.mappedName(), container.getEnc()));
       }      
    }
 }

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/QueueTestMDB.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/QueueTestMDB.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/QueueTestMDB.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -52,12 +52,10 @@
 {
    private static final Logger log = Logger.getLogger(QueueTestMDB.class);
    
-   public int count = 0;
-
    public void onMessage(Message recvMsg)
    {
       ++TestStatusBean.queueRan;
       
-      System.out.println("+++ QueueTestMDB onMessage " + TestStatusBean.queueRan + " " + count + " " + this);
+      System.out.println("+++ QueueTestMDB onMessage " + TestStatusBean.queueRan + " " + this);
    }
 }

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/unit/MDBUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/unit/MDBUnitTestCase.java	2007-09-07 17:21:10 UTC (rev 65237)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredjms/unit/MDBUnitTestCase.java	2007-09-07 18:03:46 UTC (rev 65238)
@@ -55,20 +55,20 @@
    public void testQueue() throws Exception
    {
 
-      TestStatus status = (TestStatus) getInitialContext().lookup(
-            "TestStatusBean/remote");
+      TestStatus status = (TestStatus) new InitialContext().lookup(
+      "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
-
-      Queue queue = (Queue) getInitialContext().lookup("queue/mdbtest");
+      
+      Queue queue = (Queue) getHAInitialContext().lookup("queue/mdbtest");
       QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-
+      
       TextMessage msg = session.createTextMessage("Hello World");
-
+      
       sender = session.createSender(queue);
       sender.send(msg);
       sender.send(msg);
@@ -77,11 +77,12 @@
       sender.send(msg);
       session.close();
       cnn.close();
-
+      
       Thread.sleep(2000);
       assertEquals(5, status.queueFired());
       
-      assertEquals("queuetest", status.testInjection());
+      for (int i = 0 ; i < 100 ; ++i)
+         assertEquals("queuetest", status.testInjection());
    }
 
    protected QueueConnectionFactory getQueueConnectionFactory()
@@ -89,11 +90,11 @@
    {
       try
       {
-         return (QueueConnectionFactory) getInitialContext().lookup(
+         return (QueueConnectionFactory) getHAInitialContext().lookup(
                "ConnectionFactory");
       } catch (NamingException e)
       {
-         return (QueueConnectionFactory) getInitialContext().lookup(
+         return (QueueConnectionFactory) getHAInitialContext().lookup(
                "java:/ConnectionFactory");
       }
    }
@@ -117,12 +118,12 @@
       status.clear();
    }
    
-   protected InitialContext getInitialContext() throws Exception
+   protected InitialContext getHAInitialContext() throws Exception
    {
       Properties env = new Properties();
       env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
-      //env.put(Context.PROVIDER_URL, "localhost:1100");
+      env.put(Context.PROVIDER_URL, "localhost:1100");
       
       return new InitialContext(env);
    }




More information about the jboss-cvs-commits mailing list