[jboss-cvs] JBossAS SVN: r88998 - in projects/ejb3/trunk: core/src/main/java/org/jboss/injection and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 18 03:45:54 EDT 2009


Author: jaikiran
Date: 2009-05-18 03:45:54 -0400 (Mon, 18 May 2009)
New Revision: 88998

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefRemote.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/unit/ResourceRefTestCase.java
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/META-INF/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/META-INF/jboss.xml
Modified:
   projects/ejb3/trunk/as-int/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
   projects/ejb3/trunk/ejb3/pom.xml
   projects/ejb3/trunk/plugin/pom.xml
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-1823 A resource-ref with a mappedName but without an res-type will now print out a WARN instead of the NPE

Modified: projects/ejb3/trunk/as-int/pom.xml
===================================================================
--- projects/ejb3/trunk/as-int/pom.xml	2009-05-18 06:03:15 UTC (rev 88997)
+++ projects/ejb3/trunk/as-int/pom.xml	2009-05-18 07:45:54 UTC (rev 88998)
@@ -29,7 +29,7 @@
     into the AS
     
      -->
-    <version.org.jboss.ejb3_jboss.ejb3>1.1.5</version.org.jboss.ejb3_jboss.ejb3>
+    <version.org.jboss.ejb3_jboss.ejb3>1.1.6-SNAPSHOT</version.org.jboss.ejb3_jboss.ejb3>
     <version.org.jboss.ejb3_mc.int>1.0.1</version.org.jboss.ejb3_mc.int>
   
   </properties>

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java	2009-05-18 06:03:15 UTC (rev 88997)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java	2009-05-18 07:45:54 UTC (rev 88998)
@@ -57,24 +57,24 @@
 public class ResourceHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
 {
    private static final Logger log = Logger.getLogger(ResourceHandler.class);
-   
+
    private boolean checkEncInjectors;
 
    public ResourceHandler()
    {
       this(true);
    }
-   
+
    public ResourceHandler(boolean checkEncInjectors)
    {
       this.checkEncInjectors = checkEncInjectors;
    }
-   
+
    private static void createURLInjector(String encName, String mappedName, InjectionContainer container)
    {
       assert encName.length() > 0 : "encName is empty";
       assert mappedName.length() > 0 : "mappedName is empty";
-      
+
       // Create a URL from the mappedName
       try
       {
@@ -86,7 +86,7 @@
          throw new RuntimeException(e);
       }
    }
-   
+
    private static void loadEnvEntry(InjectionContainer container, Collection<EnvironmentEntryMetaData> envEntries)
    {
       for (EnvironmentEntryMetaData envEntry : envEntries)
@@ -172,7 +172,7 @@
                else if (ORB.class.getName().equals(envRef.getType()))
                {
                   mappedName = "java:comp/ORB";
-               }            
+               }
                else
                {
                   throw new RuntimeException("mapped-name is required for " + envRef.getResourceRefName() + " of deployment " + container.getIdentifier());
@@ -182,10 +182,20 @@
          }
          else
          {
-            if(envRef.getType().equals(URL.class.getName()))
+            String resType = envRef.getType();
+            if(resType != null && resType.equals(URL.class.getName()))
+            {
                createURLInjector(encName, mappedName, container);
+            }
             else
+            {
+               if (resType == null)
+               {
+                  log.warn("EJBTHREE-1823 : <res-type> not specified for the <resource-ref> " + envRef.getResourceRefName() + " in bean " + container.getIdentifier());
+
+               }
                container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
+            }
          }
          InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
       }
@@ -285,7 +295,7 @@
          {
             throw new EJBException(e);
          }
-         
+
          String encName = "env/" + envRef.getResourceEnvRefName();
          if (container.getEncInjectors().containsKey(encName)) continue;
          if (mappedName == null || mappedName.equals(""))
@@ -396,7 +406,7 @@
       if (ref == null) return;
 
       log.trace("method " + method + " has @Resource");
-      
+
       handlePropertyAnnotation(ref, new MethodBeanProperty(method), container, injectors);
       /*
       String encName = ref.name();
@@ -486,14 +496,14 @@
       }
       */
    }
-   
+
    public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
       Resource ref = container.getAnnotation(Resource.class, field);
       if (ref == null) return;
 
       log.trace("field " + field + " has @Resource");
-      
+
       handlePropertyAnnotation(ref, new FieldBeanProperty(field), container, injectors);
       /*
       String encName = ref.name();
@@ -588,7 +598,7 @@
       assert property != null;
       assert container != null;
       assert injectors != null;
-      
+
       String encName = ref.name();
       if (encName == null || encName.equals(""))
       {
@@ -601,13 +611,13 @@
       }
 
       AccessibleObject accObj = property.getAccessibleObject();
-      
+
       Class<?> type = property.getType();
       if (!ref.type().equals(Object.class))
       {
          type = ref.type();
       }
-      
+
       if (type.equals(UserTransaction.class))
       {
          injectors.put(accObj, new UserTransactionPropertyInjector(property, container));
@@ -686,6 +696,6 @@
             container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "@Resource"));
          }
          injectors.put(accObj, new JndiPropertyInjector(property, encName, container.getEnc()));
-      }      
+      }
    }
 }

Modified: projects/ejb3/trunk/ejb3/pom.xml
===================================================================
--- projects/ejb3/trunk/ejb3/pom.xml	2009-05-18 06:03:15 UTC (rev 88997)
+++ projects/ejb3/trunk/ejb3/pom.xml	2009-05-18 07:45:54 UTC (rev 88998)
@@ -34,7 +34,7 @@
     into the AS
     
      -->
-    <version.org.jboss.ejb3_core>1.1.5</version.org.jboss.ejb3_core>
+    <version.org.jboss.ejb3_core>1.1.6-SNAPSHOT</version.org.jboss.ejb3_core>
     <version.org.jboss.ejb3_deployers>1.0.0</version.org.jboss.ejb3_deployers>
   
   </properties>

Modified: projects/ejb3/trunk/plugin/pom.xml
===================================================================
--- projects/ejb3/trunk/plugin/pom.xml	2009-05-18 06:03:15 UTC (rev 88997)
+++ projects/ejb3/trunk/plugin/pom.xml	2009-05-18 07:45:54 UTC (rev 88998)
@@ -63,7 +63,7 @@
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-as-int</artifactId>
-      <version>1.1.5</version>
+      <version>1.1.6-SNAPSHOT</version>
       <optional>true</optional>
     </dependency>
 
@@ -79,14 +79,22 @@
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-core</artifactId>
       <classifier>client</classifier>
-      <version>1.1.5</version>
+      <version>1.1.6-SNAPSHOT</version>
       <optional>true</optional>
     </dependency>
-    
+
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-endpoint-deployer</artifactId>
       <version>0.1.3</version>
+      <!-- Prevent the EJB3 core dependency from being pulled in
+      from endpoint-deployers (which is relying on 1.1.5 of EJB3 core) -->
+      <exclusions>
+        <exclusion>
+            <groupId>org.jboss.ejb3</groupId>
+            <artifactId>jboss-ejb3-core</artifactId>
+        </exclusion>
+      </exclusions>
       <optional>true</optional>
     </dependency>
 
@@ -97,7 +105,7 @@
       <version>1.0.2</version>
       <optional>true</optional>
     </dependency>
-    
+
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-proxy-spi</artifactId>

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2009-05-18 06:03:15 UTC (rev 88997)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2009-05-18 07:45:54 UTC (rev 88998)
@@ -4274,6 +4274,7 @@
 	         </fileset>
 		</jar>
 	</target>
+    
 
    <target name="ejbthree1346">
 
@@ -4299,6 +4300,14 @@
   <target name="ejbthree1807">
      <build-simple-jar name="ejbthree1807"/>
   </target>
+  
+    <target name="ejbthree1823"
+          description="Builds the jar file(s) needed for testing EJBTHREE-1823."
+          >
+        <build-simple-jar name="ejbthree1823"/>
+          
+    </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,
@@ -4329,7 +4338,7 @@
       composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc,
       localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor,
       statelesscreation, changexml, externalrefscoped, singleton, ejbthree1671, ejbthree1677, ejbthree1629, 
-   	  ejbthree1807, ejbthree1346"/>
+   	  ejbthree1807, ejbthree1346, ejbthree1823"/>
 
    <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/ejbthree1823/ResourceRefBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefBean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefBean.java	2009-05-18 07:45:54 UTC (rev 88998)
@@ -0,0 +1,118 @@
+/*
+ * 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.ejbthree1823;
+
+import java.net.URL;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.injection.ResourceHandler;
+import org.jboss.logging.Logger;
+
+/**
+ * ResourceRefBean
+ *
+ *  This bean will be used to test the EJBTHREE-1823 issue.
+ *
+ *  Brief description of the issue: If a resource-ref entry is
+ *  available in jboss.xml, but there is no corresponding
+ *  resource-ref entry neither in ejb-jar.xml nor a @Resource
+ *  in the bean, then because of the non-availability of the "res-type"
+ *  information, a NullPointerException gets thrown when the
+ *  {@link ResourceHandler} tries to process the entries to be made
+ *  in ENC.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at RemoteBinding(jndiBinding = ResourceRefBean.JNDI_NAME)
+public class ResourceRefBean implements ResourceRefRemote
+{
+
+   private static Logger logger = Logger.getLogger(ResourceRefBean.class);
+
+   public static final String JNDI_NAME = "EJBTHREE-1823Bean";
+
+   @Resource (name="SomeURL", mappedName="http://www.jboss.org")
+   private URL someUrl;
+
+   /**
+    * Looks up a datasource within the ENC of this bean.
+    * The datasource is expected to be configured through the
+    * deployment descriptors and should be available at
+    * java:comp/env/EJBTHREE-1823_DS
+    *
+    * The "res-type" of this datasource resource-ref will not
+    * be provided through ejb-jar.xml nor through a @Resource
+    * annotation.
+    *
+    */
+   public boolean isDataSourceAvailableInEnc() throws NamingException
+   {
+      Context ctx = new InitialContext();
+      String encJndiName = "java:comp/env/EJBTHREE-1823_DS";
+      DataSource ds = (DataSource) ctx.lookup(encJndiName);
+      if (ds != null)
+      {
+         return true;
+      }
+      logger.info("Datasource not found in ENC at " + encJndiName);
+      return false;
+   }
+
+
+   /**
+    * Let's just lookup other resource-ref entries (like
+    * a resource-ref for a URL)
+    *
+    * @return
+    * @throws NamingException
+    */
+   public boolean areOtherResourcesAvailableInEnc() throws NamingException
+   {
+      Context ctx = new InitialContext();
+      String encJndiName = "java:comp/env/SomeURL";
+      URL urlInEnc = (URL) ctx.lookup(encJndiName);
+      if (urlInEnc == null)
+      {
+         logger.error("URL not found in ENC at " + encJndiName);
+         return false;
+      }
+
+      // also check if the resource was injected
+      if (this.someUrl == null)
+      {
+         logger.error("@Resource of type URL not injected");
+         return false;
+      }
+      return true;
+
+
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefRemote.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefRemote.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/ResourceRefRemote.java	2009-05-18 07:45:54 UTC (rev 88998)
@@ -0,0 +1,39 @@
+/*
+ * 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.ejbthree1823;
+
+import javax.ejb.Remote;
+import javax.naming.NamingException;
+
+/**
+ * ResourceRefRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Remote
+public interface ResourceRefRemote
+{
+   public boolean isDataSourceAvailableInEnc() throws NamingException;
+   
+   public boolean areOtherResourcesAvailableInEnc() throws NamingException;
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/unit/ResourceRefTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/unit/ResourceRefTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1823/unit/ResourceRefTestCase.java	2009-05-18 07:45:54 UTC (rev 88998)
@@ -0,0 +1,98 @@
+/*
+ * 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.ejbthree1823.unit;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.ejbthree1823.ResourceRefBean;
+import org.jboss.ejb3.test.ejbthree1823.ResourceRefRemote;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * ResourceRefTestCase
+ *
+ * Test case for EJBTHREE-1823.
+ * Tests that an resource-ref entry without a res-type
+ * does not fail the deployments with NPE.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ResourceRefTestCase extends JBossTestCase
+{
+
+   /**
+    * Constructor
+    * @param name
+    */
+   public ResourceRefTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Deploy the artifact
+    * @return
+    * @throws Exception
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ResourceRefTestCase.class, "ejbthree1823.jar");
+   }
+
+   /**
+    * Test that a resource-ref entry with a res-type does not throw an
+    * NPE. Furthermore, the test additional provides a mappedName for the resource-ref
+    * in which case the resource ref will be created in the ENC.
+    *
+    * @throws Exception
+    */
+   public void testResourceRefEntriesWithoutResType() throws Exception
+   {
+      // lookup the bean
+      ResourceRefRemote bean = (ResourceRefRemote) getInitialContext().lookup(ResourceRefBean.JNDI_NAME);
+      assertNotNull("Bean returned from JNDI is null", bean);
+
+      // test datasource resource-ref which does not have a res-type specified
+      boolean result = bean.isDataSourceAvailableInEnc();
+      assertTrue("Datasource not bound in ENC of the bean", result);
+   }
+
+   /**
+    * Test that resource-ref with proper res-type are correctly processed
+    * (i.e. no regression is caused by the EJBHTREE-1823 fix)
+    *
+    * @throws Exception
+    */
+   public void testResourceRefEntriesWithResType() throws Exception
+   {
+      // lookup the bean
+      ResourceRefRemote bean = (ResourceRefRemote) getInitialContext().lookup(ResourceRefBean.JNDI_NAME);
+      assertNotNull("Bean returned from JNDI is null", bean);
+
+      // test other resource-refs which have res-type specified
+      boolean result = bean.areOtherResourcesAvailableInEnc();
+      assertTrue("Not all resources bound in ENC of the bean", result);
+
+   }
+
+}

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/META-INF/jboss.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/META-INF/jboss.xml	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1823/META-INF/jboss.xml	2009-05-18 07:45:54 UTC (rev 88998)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<jboss
+        xmlns="http://www.jboss.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee
+                            http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+        version="3.0">
+      <enterprise-beans>
+
+         <session>
+            <ejb-name>ResourceRefBean</ejb-name>
+
+            <!-- This resource-ref has no corresponding res-type specified
+            neither in ejb-jar.xml nor in the bean as a @Resource (see EJBTHREE-1823
+            for the details) -->
+            <resource-ref>
+                <res-ref-name>EJBTHREE-1823_DS</res-ref-name>
+                <jndi-name>java:DefaultDS</jndi-name>
+            </resource-ref>
+
+
+
+         </session>
+
+
+      </enterprise-beans>
+   </jboss>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list