tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: few more contextual CDI fixes
Date Wed, 24 Aug 2016 12:39:58 GMT
Repository: tomee
Updated Branches:
  refs/heads/master ae9700646 -> 196acf3e4


few more contextual CDI fixes


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/196acf3e
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/196acf3e
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/196acf3e

Branch: refs/heads/master
Commit: 196acf3e44c4fe60e64ebc9ca6144908f056768c
Parents: ae97006
Author: Romain manni-Bucau <rmannibucau@gmail.com>
Authored: Wed Aug 24 14:39:36 2016 +0200
Committer: Romain manni-Bucau <rmannibucau@gmail.com>
Committed: Wed Aug 24 14:39:36 2016 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/openejb/OpenEJB.java     |  2 +-
 .../main/java/org/apache/openejb/cdi/CdiBuilder.java  |  4 ++--
 .../apache/openejb/testing/ApplicationComposers.java  |  5 +++++
 .../main/java/org/apache/openejb/util/AppFinder.java  | 10 +++++++++-
 .../apache/openejb/web/LightweightWebAppBuilder.java  | 14 ++++++++++++--
 .../org/apache/openejb/config/EarEjbButNoCdiTest.java |  9 +++++++--
 .../apache/catalina/startup/OpenEJBContextConfig.java |  1 -
 .../apache/tomee/catalina/TomEEWebappClassLoader.java |  1 -
 8 files changed, 36 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java b/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
index bb6b682..ccc1d7f 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
@@ -116,7 +116,7 @@ public final class OpenEJB {
             logger.info("openejb.base = " + system.getBase().getDirectory().getAbsolutePath());
 
             //OWB support.  The classloader has to be able to load all OWB components including
the ones supplied by OpenEjb.
-            CdiBuilder.initializeOWB(getClass().getClassLoader());
+            CdiBuilder.initializeOWB();
 
             final String className = system.getOptions().get("openejb.assembler", (String)
null);
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
index 8b32211..73818b5 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiBuilder.java
@@ -48,7 +48,7 @@ public class CdiBuilder {
         //TODO hack for tests.  Currently initialized in OpenEJB line 90.  cf alternative
in AccessTimeoutTest which would
         //presumably have to be replicated in about 70 other tests.
         if (singletonService == null) {
-            singletonService = initializeOWB(getClass().getClassLoader());
+            singletonService = initializeOWB();
         } else {
             logger.info("Existing thread singleton service in SystemInstance(): " + singletonService);
         }
@@ -60,7 +60,7 @@ public class CdiBuilder {
         singletonService.initialize(new StartupObject(appContext, appInfo, allDeployments,
webContext));
     }
 
-    public static synchronized ThreadSingletonService initializeOWB(final ClassLoader classLoader)
{
+    public static synchronized ThreadSingletonService initializeOWB() {
         logger.info("Created new singletonService " + SINGLETON_SERVICE);
         SystemInstance.get().setComponent(ThreadSingletonService.class, SINGLETON_SERVICE);
         try {

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index 4c33372..c698a8e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -28,9 +28,11 @@ import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
 import org.apache.openejb.assembler.classic.WebAppBuilder;
+import org.apache.openejb.cdi.CdiBuilder;
 import org.apache.openejb.cdi.CdiScanner;
 import org.apache.openejb.cdi.OptimizedLoaderService;
 import org.apache.openejb.cdi.ScopeHelper;
+import org.apache.openejb.cdi.ThreadSingletonService;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.ConnectorModule;
@@ -1376,6 +1378,9 @@ public class ApplicationComposers {
         }
 
         SystemInstance.init(configuration);
+        if (SystemInstance.get().getComponent(ThreadSingletonService.class) == null) {
+            CdiBuilder.initializeOWB();
+        }
         for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet())
{
             for (final Field field : finder.getValue().findAnnotatedFields(RandomPort.class))
{
                 if (!field.isAccessible()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/main/java/org/apache/openejb/util/AppFinder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/AppFinder.java b/container/openejb-core/src/main/java/org/apache/openejb/util/AppFinder.java
index b07657d..cd8cf81 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/AppFinder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/AppFinder.java
@@ -27,8 +27,13 @@ public final class AppFinder {
         final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
         for (final AppContext appContext : containerSystem.getAppContexts()) {
             final ClassLoader appContextClassLoader = appContext.getClassLoader();
+            boolean found = false;
             if (appContextClassLoader.equals(cl) || (cl != null && cl.equals(appContextClassLoader)))
{ // CxfContainerLoader is not symmetric
-                return transformer.from(appContext);
+                final T from = transformer.from(appContext);
+                found = true;
+                if (from != null) {
+                    return from;
+                }
             }
             for (final WebContext web : appContext.getWebContexts()) {
                 final ClassLoader webClassLoader = web.getClassLoader();
@@ -36,6 +41,9 @@ public final class AppFinder {
                     return transformer.from(web);
                 }
             }
+            if (found) { // for cases where app and webapp share the same classloader
+                break;
+            }
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
index 504090f..00267f7 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
@@ -24,6 +24,7 @@ import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
 import org.apache.openejb.assembler.classic.ClassListInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.assembler.classic.FilterInfo;
 import org.apache.openejb.assembler.classic.InjectionBuilder;
 import org.apache.openejb.assembler.classic.JndiEncBuilder;
@@ -173,7 +174,7 @@ public class LightweightWebAppBuilder implements WebAppBuilder {
             appContext.getWebContexts().add(webContext);
             cs.addWebContext(webContext);
 
-            if (!appInfo.webAppAlone) {
+            if (!appInfo.webAppAlone && hasCdi(appInfo)) {
                 final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
                 new CdiBuilder().build(appInfo, appContext, beanContexts, webContext);
                 assembler.startEjbs(true, beanContexts);
@@ -229,7 +230,7 @@ public class LightweightWebAppBuilder implements WebAppBuilder {
             deployedWebObjects.webContext = webContext;
             servletDeploymentInfo.put(webAppInfo, deployedWebObjects);
 
-            if (webContext.getWebBeansContext() != null) {
+            if (webContext.getWebBeansContext() != null && webContext.getWebBeansContext().getBeanManagerImpl().isInUse())
{
                 final Thread thread = Thread.currentThread();
                 final ClassLoader old = thread.getContextClassLoader();
                 thread.setContextClassLoader(webContext.getClassLoader());
@@ -376,6 +377,15 @@ public class LightweightWebAppBuilder implements WebAppBuilder {
         }
     }
 
+    private boolean hasCdi(final AppInfo appInfo) {
+        for (final EjbJarInfo jar : appInfo.ejbJars) {
+            if (jar.beans != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     // not thread safe but fine in embedded mode which is the only mode of this builder
     private void switchServletContextIfNeeded(final ServletContext sc, final Runnable runnable)
{
         if (sc == null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/container/openejb-core/src/test/java/org/apache/openejb/config/EarEjbButNoCdiTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/EarEjbButNoCdiTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/config/EarEjbButNoCdiTest.java
index efd7e7d..8ecd5b1 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/config/EarEjbButNoCdiTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/config/EarEjbButNoCdiTest.java
@@ -29,7 +29,7 @@ import javax.ejb.EJB;
 import javax.ejb.Stateless;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
 
 // not fully spec compliant but save a bunch of mem for legacy apps
 // + avoid to breaks existing ones so better than the opposite
@@ -53,7 +53,12 @@ public class EarEjbButNoCdiTest {
     @Test
     public void check() {
         assertEquals("1", b1.val());
-        assertNull(WebBeansContext.currentInstance());
+        try {
+            WebBeansContext.currentInstance();
+            fail();
+        } catch (final IllegalStateException ise) {
+            // ok
+        }
     }
 
     @Stateless

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/tomee/tomee-catalina/src/main/java/org/apache/catalina/startup/OpenEJBContextConfig.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/catalina/startup/OpenEJBContextConfig.java
b/tomee/tomee-catalina/src/main/java/org/apache/catalina/startup/OpenEJBContextConfig.java
index 2dee1ed..1dcbbd2 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/catalina/startup/OpenEJBContextConfig.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/catalina/startup/OpenEJBContextConfig.java
@@ -62,7 +62,6 @@ import org.apache.tomee.common.NamingUtil;
 import org.apache.tomee.common.ResourceFactory;
 import org.apache.tomee.jasper.TomEEJasperInitializer;
 import org.apache.tomee.loader.TomcatHelper;
-import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.web.context.WebConversationFilter;
 import org.apache.xbean.finder.IAnnotationFinder;
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/196acf3e/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
index c778fac..fd00a77 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
@@ -40,7 +40,6 @@ import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
 import org.apache.openejb.util.classloader.URLClassLoaderFirst;
 import org.apache.openejb.util.reflection.Reflections;
-import org.apache.webbeans.config.WebBeansContext;
 
 import java.io.File;
 import java.io.IOException;


Mime
View raw message