You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/09/22 17:58:24 UTC

svn commit: r1174232 - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/cdi/ container/openejb-core/src/main/java/org/apache/openejb/config/ tck/cdi-tomee-embedded/src/test/resources/ tck/cdi-tomee/src/test/resources/

Author: dblevins
Date: Thu Sep 22 15:58:24 2011
New Revision: 1174232

URL: http://svn.apache.org/viewvc?rev=1174232&view=rev
Log:
Deploy the CDI beans in ear/lib/ directory
Attempt a JNDI lookup directly against the 'comp' BeanContext before trying other methods

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
    openejb/trunk/openejb3/tck/cdi-tomee-embedded/src/test/resources/passing.xml
    openejb/trunk/openejb3/tck/cdi-tomee/src/test/resources/passing.xml

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java?rev=1174232&r1=1174231&r2=1174232&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java Thu Sep 22 15:58:24 2011
@@ -109,33 +109,7 @@ public class CdiResourceInjectionService
             for (Injection injection : beanContext.getInjections()) {
                 if (!injection.getTarget().isAssignableFrom(clazz)) continue;
                 try {
-                    String jndiName = injection.getJndiName();
-
-                    if (!jndiName.startsWith("java:")) {
-                        jndiName = "java:" + jndiName;
-                    }
-
-                    Object value;
-                    try {
-                        value = InjectionProcessor.unwrap(beanContext.getJndiContext()).lookup(jndiName);
-                    } catch (NamingException e) {
-                        // Fallback and try the Context on the current thread
-                        //
-                        // We attempt to create a Context instance for each
-                        // individual CDI bean.  This isn't really accurate
-                        // however, and in a webapp all the beans will share
-                        // the same JNDI Context.  This fallback will cover
-                        // the situation where we did not accurately create
-                        // a Context for each bean and instead the Context
-                        // on the thread (the webapp context) has the data
-                        // we need to lookup.
-
-                        try {
-                            value = new InitialContext().lookup(jndiName);
-                        } catch (NamingException e1) {
-                            throw e;
-                        }
-                    }
+                    Object value = lookup(beanContext, injection);
 
                     String prefix;
                     if (usePrefix) {
@@ -153,6 +127,43 @@ public class CdiResourceInjectionService
         }
     }
 
+    private Object lookup(BeanContext beanContext, Injection injection) throws NamingException {
+        String jndiName = injection.getJndiName();
+
+        try {
+            return beanContext.getJndiContext().lookup(jndiName);
+        } catch (NamingException e) {
+
+            if (!jndiName.startsWith("java:")) {
+                jndiName = "java:" + jndiName;
+            }
+
+            Object value;
+            try {
+
+                value = InjectionProcessor.unwrap(beanContext.getJndiContext()).lookup(jndiName);
+            } catch (NamingException e1) {
+                // Fallback and try the Context on the current thread
+                //
+                // We attempt to create a Context instance for each
+                // individual CDI bean.  This isn't really accurate
+                // however, and in a webapp all the beans will share
+                // the same JNDI Context.  This fallback will cover
+                // the situation where we did not accurately create
+                // a Context for each bean and instead the Context
+                // on the thread (the webapp context) has the data
+                // we need to lookup.
+
+                try {
+                    value = new InitialContext().lookup(jndiName);
+                } catch (NamingException e2) {
+                    throw e;
+                }
+            }
+            return value;
+        }
+    }
+
     @Override
     public void clear() {
         compContexts.clear();

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1174232&r1=1174231&r2=1174232&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Thu Sep 22 15:58:24 2011
@@ -1317,6 +1317,7 @@ public class AnnotationDeployer implemen
 
         private boolean hasBeansXml(URL url) {
             if (url.getPath().endsWith("WEB-INF/classes/")) return true;
+            if (url.getPath().endsWith("!/META-INF/beans.xml")) return true;
             try {
                 final URLClassLoader loader = new URLClassLoader(new URL[]{url});
                 String[] paths = {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1174232&r1=1174231&r2=1174232&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Thu Sep 22 15:58:24 2011
@@ -37,6 +37,7 @@ import org.apache.openejb.jee.TldTaglib;
 import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.jee.WebserviceDescription;
 import org.apache.openejb.jee.Webservices;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
 import org.apache.openejb.loader.FileUtils;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.AnnotationFinder;
@@ -48,6 +49,9 @@ import org.apache.openejb.util.UrlCache;
 import org.apache.xbean.finder.IAnnotationFinder;
 import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.finder.UrlSet;
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.CompositeArchive;
+import org.apache.xbean.finder.archive.JarArchive;
 import org.xml.sax.SAXException;
 
 import javax.xml.bind.JAXBException;
@@ -512,6 +516,9 @@ public class DeploymentLoader implements
                 }
             }
 
+
+            addBeansXmls(appModule);
+
             // Persistence Units
             Properties p = new Properties();
             p.put(appModule.getModuleId(), appModule.getJarLocation());
@@ -741,6 +748,53 @@ public class DeploymentLoader implements
         webModule.getAltDDs().put("beans.xml", complete);
     }
 
+    private void addBeansXmls(AppModule appModule) {
+        final List<URL> urls = appModule.getAdditionalLibraries();
+        final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
+
+        final ArrayList<URL> xmls;
+        try {
+            xmls = Collections.list(loader.getResources("META-INF/beans.xml"));
+        } catch (IOException e) {
+
+            return;
+        }
+
+        List<Archive> jars = new ArrayList<Archive>();
+
+        Beans complete = null;
+        for (URL url : xmls) {
+            if (url == null) continue;
+            try {
+
+                final Beans beans = ReadDescriptors.readBeans(url);
+
+                if (complete == null) {
+                    complete = beans;
+                } else {
+                    complete.getAlternativeClasses().addAll(beans.getAlternativeClasses());
+                    complete.getAlternativeStereotypes().addAll(beans.getAlternativeStereotypes());
+                    complete.getDecorators().addAll(beans.getDecorators());
+                    complete.getInterceptors().addAll(beans.getInterceptors());
+                }
+                File file = URLs.toFile(url);
+                jars.add(new JarArchive(appModule.getClassLoader(), url));
+//            } catch (MalformedURLException e) {
+//                logger.error("Unable to resolve jar path of beans.xml:"+ url.toExternalForm(), e);
+            } catch (OpenEJBException e) {
+                logger.error("Unable to read beans.xml from :"+ url.toExternalForm(), e);
+            }
+        }
+
+        if (complete == null) return;
+
+        EjbModule ejbModule = new EjbModule(appModule.getClassLoader(), "ear-scoped-cdi-beans", new EjbJar(), new OpenejbJar());
+        ejbModule.setBeans(complete);
+        ejbModule.setFinder(new org.apache.xbean.finder.AnnotationFinder(new AggregatedArchive(appModule.getClassLoader(), xmls)));
+
+        appModule.getEjbModules().add(ejbModule);
+    }
+
     protected String getContextRoot() {
         return null;
     }

Modified: openejb/trunk/openejb3/tck/cdi-tomee-embedded/src/test/resources/passing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-tomee-embedded/src/test/resources/passing.xml?rev=1174232&r1=1174231&r2=1174232&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-tomee-embedded/src/test/resources/passing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-tomee-embedded/src/test/resources/passing.xml Thu Sep 22 15:58:24 2011
@@ -19,7 +19,7 @@
 <suite name="CDI TCK" verbose="0">
   <test name="CDI TCK">
     <classes>
-      <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInWarTest"/>
+      <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInEarTest"/>
     </classes>
   </test>
 </suite>

Modified: openejb/trunk/openejb3/tck/cdi-tomee/src/test/resources/passing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-tomee/src/test/resources/passing.xml?rev=1174232&r1=1174231&r2=1174232&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-tomee/src/test/resources/passing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-tomee/src/test/resources/passing.xml Thu Sep 22 15:58:24 2011
@@ -38,20 +38,9 @@
           <exclude name="testEnterpriseBeanWithNonPassivatingDecoratorFails"/>
         </methods>
       </class>
-      <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInEarTest">
-        <methods>
-          <exclude name="test"/>
-        </methods>
-      </class>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle.EnterpriseBeanLifecycleTest">
         <methods>
           <exclude name="testCreateSFSB"/>
-          <exclude name="testSerializeSFSB"/>
-        </methods>
-      </class>
-      <class name="org.jboss.jsr299.tck.tests.interceptors.definition.enterprise.nonContextualReference.SessionBeanInterceptorOnNonContextualEjbReferenceTest">
-        <methods>
-          <exclude name="testNonContextualSessionBeanReferenceIsIntercepted"/>
         </methods>
       </class>
       <class name="org.jboss.jsr299.tck.tests.lookup.injection.non.contextual.ws.InjectionIntoWebServiceEndPointTest">
@@ -59,11 +48,6 @@
           <exclude name="testInjectionIntoWebServiceEndpoint"/>
         </methods>
       </class>
-      <class name="org.jboss.jsr299.tck.tests.lookup.injectionpoint.broken.not.bean.InjectionPointTest">
-        <methods>
-          <exclude name="testDefinitionErrorDetected"/>
-        </methods>
-      </class>
     </classes>
   </test>
 </suite>