Repository: tomee
Updated Branches:
  refs/heads/master 43581f489 -> 60a2e64f6


skipping cdi if not used at all (resources apps for instance)


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

Branch: refs/heads/master
Commit: 60a2e64f600938561182969868440e74f223adba
Parents: ac8c659
Author: Romain Manni-Bucau <rmannibu...@apache.org>
Authored: Tue Jun 16 10:34:01 2015 +0200
Committer: Romain Manni-Bucau <rmannibu...@apache.org>
Committed: Tue Jun 16 10:34:38 2015 +0200

----------------------------------------------------------------------
 .../common/enrichment/OpenEJBEnricher.java      | 24 ++++++----
 .../openejb/OpenEJBDeployableContainer.java     |  4 +-
 .../openejb/OpenEJBInjectionEnricher.java       |  3 ++
 .../embedded/EmbeddedTomEEContainer.java        |  4 +-
 .../main/java/org/apache/openejb/Injector.java  | 14 +++---
 .../org/apache/openejb/OpenEjbContainer.java    | 28 ++++++-----
 .../openejb/assembler/classic/Assembler.java    | 30 ++++++++----
 .../openejb/testing/ApplicationComposers.java   | 13 ++++--
 .../tomee/catalina/OpenEJBContextConfig.java    | 49 +++++++++++---------
 .../tomee/catalina/TomcatJndiBuilder.java       |  6 ++-
 .../tomee/catalina/TomcatWebAppBuilder.java     |  1 +
 11 files changed, 109 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/arquillian/arquillian-common/src/main/java/org/apache/openejb/arquillian/common/enrichment/OpenEJBEnricher.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-common/src/main/java/org/apache/openejb/arquillian/common/enrichment/OpenEJBEnricher.java
 
b/arquillian/arquillian-common/src/main/java/org/apache/openejb/arquillian/common/enrichment/OpenEJBEnricher.java
index aa7eb7e..446482d 100644
--- 
a/arquillian/arquillian-common/src/main/java/org/apache/openejb/arquillian/common/enrichment/OpenEJBEnricher.java
+++ 
b/arquillian/arquillian-common/src/main/java/org/apache/openejb/arquillian/common/enrichment/OpenEJBEnricher.java
@@ -76,11 +76,14 @@ public final class OpenEJBEnricher {
         final BeanContext context = 
SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext(ctx.getId()
 + "_" + testInstance.getClass().getName());
 
         final WebBeansContext appWBC = ctx.getWebBeansContext();
-        final BeanManagerImpl bm = appWBC.getBeanManagerImpl();
+        final BeanManagerImpl bm = appWBC == null ? null : 
appWBC.getBeanManagerImpl();
 
         boolean ok = false;
         for (final WebContext web : ctx.getWebContexts()) {
             final WebBeansContext webBeansContext = web.getWebBeansContext();
+            if (webBeansContext == null) {
+                continue;
+            }
             final BeanManagerImpl webAppBm = 
webBeansContext.getBeanManagerImpl();
             if (webBeansContext != appWBC && webAppBm.isInUse()) {
                 try {
@@ -130,6 +133,9 @@ public final class OpenEJBEnricher {
 
     private static BeanManagerImpl findBeanManager(final AppContext ctx) {
         if (ctx != null) {
+            if (ctx.getWebBeansContext() == null) {
+                return null;
+            }
             return ctx.getWebBeansContext().getBeanManagerImpl();
         }
 
@@ -152,13 +158,15 @@ public final class OpenEJBEnricher {
         final List<BeanManager> beanManagers = new ArrayList<>();
         final BeanManager bm = findBeanManager(appContext);
         if (bm != null) {
-            if (appContext != null) { // then add web bean manager first, 
TODO: selection of the webapp containing the test?
-                for (final WebContext web : appContext.getWebContexts()) {
-                    final WebBeansContext webBeansContext = 
web.getWebBeansContext();
-                    final BeanManagerImpl webAppBm = 
webBeansContext.getBeanManagerImpl();
-                    if (bm != webAppBm) {
-                        beanManagers.add(webAppBm);
-                    }
+            // then add web bean manager first, TODO: selection of the webapp 
containing the test?
+            for (final WebContext web : appContext.getWebContexts()) {
+                final WebBeansContext webBeansContext = 
web.getWebBeansContext();
+                if (webBeansContext == null) {
+                    continue;
+                }
+                final BeanManagerImpl webAppBm = 
webBeansContext.getBeanManagerImpl();
+                if (bm != webAppBm) {
+                    beanManagers.add(webAppBm);
                 }
             }
             beanManagers.add(bm);

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
 
b/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
index f999c20..a267c99 100644
--- 
a/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
+++ 
b/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
@@ -334,7 +334,7 @@ public class OpenEJBDeployableContainer implements 
DeployableContainer<OpenEJBCo
                 final ServletContext appServletContext = new 
MockServletContext();
                 final HttpSession appSession = new MockHttpSession();
 
-                if (configuration.isStartDefaultScopes()) {
+                if (configuration.isStartDefaultScopes() && 
appCtx.getWebBeansContext() != null) {
                     
startContexts(appCtx.getWebBeansContext().getContextsService(), 
appServletContext, appSession);
                 }
 
@@ -375,7 +375,7 @@ public class OpenEJBDeployableContainer implements 
DeployableContainer<OpenEJBCo
             if 
(!configuration.isSingleDeploymentByArchiveName(archive.getName())) {
                 assembler.destroyApplication(info.get().path);
             }
-            if (configuration.isStartDefaultScopes()) {
+            if (configuration.isStartDefaultScopes() && 
ctx.getWebBeansContext() != null) {
                 stopContexts(ctx.getWebBeansContext().getContextsService(), 
servletContext.get(), session.get());
             }
         } catch (final Exception e) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBInjectionEnricher.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBInjectionEnricher.java
 
b/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBInjectionEnricher.java
index a571381..c60aaff 100644
--- 
a/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBInjectionEnricher.java
+++ 
b/arquillian/arquillian-openejb-embedded/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBInjectionEnricher.java
@@ -55,6 +55,9 @@ public class OpenEJBInjectionEnricher implements TestEnricher 
{
             final List<AppContext> appContexts = 
SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts();
             final Class<?> clazz = testInstance.getClass();
             for (final AppContext appContext : appContexts) {
+                if (appContext.getWebBeansContext() == null) {
+                    continue;
+                }
                 try {
                     final BeanManager bm = 
appContext.getWebBeansContext().getBeanManagerImpl();
                     final AnnotatedType<?> at = bm.createAnnotatedType(clazz);

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
 
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
index 3478732..4428d1e 100644
--- 
a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
+++ 
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
@@ -196,7 +196,7 @@ public class EmbeddedTomEEContainer extends 
TomEEContainer<EmbeddedTomEEConfigur
 
     private void startCdiContexts(final String name) {
         final WebBeansContext wbc = 
this.container.getAppContexts(name).getWebBeansContext();
-        if (wbc.getBeanManagerImpl().isInUse()) {
+        if (wbc != null && wbc.getBeanManagerImpl().isInUse()) {
             final MockHttpSession session = new MockHttpSession();
             wbc.getContextsService().startContext(RequestScoped.class, null);
             wbc.getContextsService().startContext(SessionScoped.class, 
session);
@@ -211,7 +211,7 @@ public class EmbeddedTomEEContainer extends 
TomEEContainer<EmbeddedTomEEConfigur
             final HttpSession session = SESSIONS.remove(name);
             if (session != null) {
                 final WebBeansContext wbc = 
container.getAppContexts(container.getInfo(name).appId).getWebBeansContext();
-                if (wbc.getBeanManagerImpl().isInUse()) {
+                if (wbc != null && wbc.getBeanManagerImpl().isInUse()) {
                     wbc.getContextsService().startContext(RequestScoped.class, 
null);
                     wbc.getContextsService().startContext(SessionScoped.class, 
session);
                     
wbc.getContextsService().startContext(ConversationScoped.class, null);

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/Injector.java 
b/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
index b00e99e..db44d9e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
@@ -64,19 +64,19 @@ public class Injector {
     }
 
     private static <T> void cdiInjections(final BeanContext context, final T 
object) {
-        ThreadContext oldContext = null;
-        if (context != null) {
-            final ThreadContext callContext = new ThreadContext(context, null, 
Operation.INJECTION);
-            oldContext = ThreadContext.enter(callContext);
+        if (context.getWebBeansContext() == null) {
+            return;
         }
+
+        ThreadContext oldContext = null;
+        final ThreadContext callContext = new ThreadContext(context, null, 
Operation.INJECTION);
+        oldContext = ThreadContext.enter(callContext);
         try {
             
OWBInjector.inject(context.getWebBeansContext().getBeanManagerImpl(), object, 
null);
         } catch (final Throwable t) {
             logger().warning("an error occured while injecting the class '" + 
object.getClass().getName() + "': " + t.getMessage());
         } finally {
-            if (context != null) {
-                ThreadContext.exit(oldContext);
-            }
+            ThreadContext.exit(oldContext);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java 
b/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
index 99aaba3..8039dce 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
@@ -118,8 +118,8 @@ public final class OpenEjbContainer extends EJBContainer {
     private final Options options;
     private final OpenEjbContainer.GlobalContext globalJndiContext;
     private final WebBeansContext webBeanContext;
-    private final ServletContext servletContext;
-    private final HttpSession session;
+    private volatile ServletContext servletContext;
+    private volatile HttpSession session;
 
     private OpenEjbContainer(final Map<?, ?> map, final AppContext appContext) 
{
         webBeanContext = appContext.getWebBeansContext();
@@ -132,12 +132,14 @@ public final class OpenEjbContainer extends EJBContainer {
 
         startNetworkServices();
 
-        servletContext = new MockServletContext();
-        session = new MockHttpSession();
-        try {
-            startContexts(webBeanContext.getContextsService(), servletContext, 
session);
-        } catch (final Exception e) {
-            logger().warning("can't start all CDI contexts", e);
+        if (webBeanContext != null) {
+            servletContext = new MockServletContext();
+            session = new MockHttpSession();
+            try {
+                startContexts(webBeanContext.getContextsService(), 
servletContext, session);
+            } catch (final Exception e) {
+                logger().warning("can't start all CDI contexts", e);
+            }
         }
     }
 
@@ -178,10 +180,12 @@ public final class OpenEjbContainer extends EJBContainer {
             }
         }
 
-        try {
-            stopContexts(webBeanContext.getContextsService(), servletContext, 
session);
-        } catch (final Exception e) {
-            logger().warning("can't stop all CDI contexts", e);
+        if (webBeanContext != null) {
+            try {
+                stopContexts(webBeanContext.getContextsService(), 
servletContext, session);
+            } catch (final Exception e) {
+                logger().warning("can't stop all CDI contexts", e);
+            }
         }
 
         logger().info("Destroying OpenEJB container");

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index e495f68..be712b4 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -886,11 +886,13 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
                 propagateApplicationExceptions(appInfo, classLoader, 
allDeployments);
             }
 
-            if 
("true".equalsIgnoreCase(appInfo.properties.getProperty("openejb.cdi.activated",
 "true"))) {
+            if (shouldStartCdi(appInfo)) {
                 new CdiBuilder().build(appInfo, appContext, allDeployments);
                 ensureWebBeansContext(appContext);
                 appJndiContext.bind("app/BeanManager", 
appContext.getBeanManager());
                 appContext.getBindings().put("app/BeanManager", 
appContext.getBeanManager());
+            } else { // ensure we can reuse it in tomcat to remove OWB filters
+                appInfo.properties.setProperty("openejb.cdi.activated", 
"false");
             }
 
             // now cdi is started we can try to bind real validator factory 
and validator
@@ -1005,9 +1007,7 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
             logger.info("createApplication.success", appInfo.path);
 
             return appContext;
-        } catch (final ValidationException ve) {
-            throw ve;
-        } catch (final DeploymentException ve) {
+        } catch (final ValidationException | DeploymentException ve) {
             throw ve;
         } catch (final Throwable t) {
             try {
@@ -1019,7 +1019,22 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
         }
     }
 
+    private boolean shouldStartCdi(final AppInfo appInfo) {
+        if 
(!"true".equalsIgnoreCase(appInfo.properties.getProperty("openejb.cdi.activated",
 "true"))) {
+            return false;
+        }
+        for (final EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
+            if (ejbJarInfo.beans != null && !ejbJarInfo.beans.bdas.isEmpty()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void validateCdiResourceProducers(final AppContext appContext, 
final AppInfo info) {
+        if (appContext.getWebBeansContext() == null) {
+            return;
+        }
         // validate @Produces @Resource/@PersistenceX/@EJB once all is bound 
to JNDI - best case - or with our model
         if (appContext.isStandaloneModule() && 
!appContext.getProperties().containsKey("openejb.cdi.skip-resource-validation"))
 {
             final Map<String, Object> bindings =
@@ -1159,7 +1174,7 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
 
                         try {
                             // wire up CDI
-                            if (appContext != null) {
+                            if (appContext != null && 
appContext.getWebBeansContext() != null) {
                                 final BeanManagerImpl beanManager = 
appContext.getWebBeansContext().getBeanManagerImpl();
                                 if (beanManager.isInUse()) {
                                     creationalContext = 
beanManager.createCreationalContext(null);
@@ -1614,10 +1629,9 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
         if (webBeansContext == null) {
             webBeansContext = appContext.getWebBeansContext();
         }else{
-            if(null == appContext.getWebBeansContext()){
+            if (null == appContext.getWebBeansContext()){
                 appContext.setWebBeansContext(webBeansContext);
-        }
-
+            }
             return;
         }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/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 495e7e9..8c6f1a0 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
@@ -710,7 +710,7 @@ public class ApplicationComposers {
         appInfo = 
SystemInstance.get().getComponent(ConfigurationFactory.class).configureApplication(appModule);
         appContext = assembler.createApplication(appInfo);
 
-        if (mockCdiContexts()) {
+        if (mockCdiContexts() && appContext.getWebBeansContext() != null) {
             
ScopeHelper.startContexts(appContext.getWebBeansContext().getContextsService(), 
servletContext, session);
         }
 
@@ -899,11 +899,16 @@ public class ApplicationComposers {
 
             Throwable error = null;
             try {
-                OWBInjector.inject(appContext.getBeanManager(), 
inputTestInstance, null);
+                if (appContext.getBeanManager() != null) {
+                    OWBInjector.inject(appContext.getBeanManager(), 
inputTestInstance, null);
+                }
             } catch (final Throwable t) {
                 error = t;
             }
             for (final WebContext web : appContext.getWebContexts()) {
+                if (web.getWebBeansContext() == null) {
+                    continue;
+                }
                 try {
                     
OWBInjector.inject(web.getWebBeansContext().getBeanManagerImpl(), 
inputTestInstance, null);
                     // hourra, we enriched correctly the test then cleanup 
error state and quit
@@ -1036,7 +1041,7 @@ public class ApplicationComposers {
     }
 
     public void stopApplication() throws NamingException {
-        if (appContext != null) {
+        if (appContext != null && appContext.getWebBeansContext() != null) {
             final ContextsService contextsService = 
appContext.getWebBeansContext().getContextsService();
             // No need to stop the ConversationContext manually as it gets 
stored inside the SessionContext as Bean
             contextsService.endContext(SessionScoped.class, session);
@@ -1063,7 +1068,7 @@ public class ApplicationComposers {
 
         globalJndiEntries.clear();
 
-        if (mockCdiContexts() && appContext != null) {
+        if (mockCdiContexts() && appContext != null && 
appContext.getWebBeansContext() != null) {
             try {
                 
ScopeHelper.stopContexts(appContext.getWebBeansContext().getContextsService(), 
servletContext, session);
             } catch (final Exception e) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
index c9169d3..e5c163a 100644
--- 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
+++ 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
@@ -351,29 +351,32 @@ public class OpenEJBContextConfig extends ContextConfig {
             }
         }
 
-        {
-            final FilterDef filter = new FilterDef();
-            filter.setAsyncSupported("true");
-            filter.setDescription("OpenEJB CDI Filter - to propagate 
@RequestScoped in async tasks");
-            filter.setDisplayName("OpenEJB CDI");
-            filter.setFilterClass(WebBeansFilter.class.getName());
-            filter.setFilterName(WebBeansFilter.class.getName());
-            webXml.addFilter(filter);
-
-            final FilterMap mapping = new FilterMap();
-            mapping.setFilterName(filter.getFilterName());
-            mapping.addURLPattern("/*");
-            webXml.addFilterMapping(mapping);
-        }
-
-        {
-            final FilterDef filter = new FilterDef();
-            filter.setAsyncSupported("true");
-            filter.setDescription("CDI Conversation Filter");
-            filter.setDisplayName("CDI Conversation Filter");
-            filter.setFilterName("CDI Conversation Filter");
-            filter.setFilterClass(WebConversationFilter.class.getName());
-            webXml.addFilter(filter);
+        final AppInfo app = info.app();
+        if (app == null || 
!"false".equals(app.properties.getProperty("openejb.cdi.activated"))) {
+            {
+                final FilterDef filter = new FilterDef();
+                filter.setAsyncSupported("true");
+                filter.setDescription("OpenEJB CDI Filter - to propagate 
@RequestScoped in async tasks");
+                filter.setDisplayName("OpenEJB CDI");
+                filter.setFilterClass(WebBeansFilter.class.getName());
+                filter.setFilterName(WebBeansFilter.class.getName());
+                webXml.addFilter(filter);
+
+                final FilterMap mapping = new FilterMap();
+                mapping.setFilterName(filter.getFilterName());
+                mapping.addURLPattern("/*");
+                webXml.addFilterMapping(mapping);
+            }
+
+            {
+                final FilterDef filter = new FilterDef();
+                filter.setAsyncSupported("true");
+                filter.setDescription("CDI Conversation Filter");
+                filter.setDisplayName("CDI Conversation Filter");
+                filter.setFilterName("CDI Conversation Filter");
+                filter.setFilterClass(WebConversationFilter.class.getName());
+                webXml.addFilter(filter);
+            }
         }
 
         return webXml;

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
index cb8c774..35b8adb 100644
--- 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
+++ 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
@@ -65,6 +65,7 @@ import org.apache.tomee.common.ResourceFactory;
 import org.apache.tomee.common.SystemComponentFactory;
 import org.apache.tomee.common.UserTransactionFactory;
 import org.apache.tomee.common.WsFactory;
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.InjectableBeanManager;
 import org.omg.CORBA.ORB;
 
@@ -273,7 +274,10 @@ public class TomcatJndiBuilder {
             if (webContext != null && webContext.getWebbeansContext() != null) 
{
                 comp.rebind("BeanManager", new 
InjectableBeanManager(webContext.getWebbeansContext().getBeanManagerImpl()));
             } else if (contextInfo != null) {
-                comp.rebind("BeanManager", new 
InjectableBeanManager(cs.getAppContext(contextInfo.appInfo.appId).getWebBeansContext().getBeanManagerImpl()));
+                final WebBeansContext webBeansContext = 
cs.getAppContext(contextInfo.appInfo.appId).getWebBeansContext();
+                if (webBeansContext != null) { // can be null if cdi is 
inhibited
+                    comp.rebind("BeanManager", new 
InjectableBeanManager(webBeansContext.getBeanManagerImpl()));
+                }
             }
         } catch (final Exception ignored) {
             ignored.printStackTrace();

http://git-wip-us.apache.org/repos/asf/tomee/blob/60a2e64f/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
index 847f4f6..329106c 100644
--- 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
+++ 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
@@ -1183,6 +1183,7 @@ public class TomcatWebAppBuilder implements 
WebAppBuilder, ContextListener, Pare
                     contextInfo.standardContext = standardContext; // ensure 
to do it before an exception can be thrown
 
                     contextInfo.appInfo = 
configurationFactory.configureApplication(appModule);
+
                     final Boolean autoDeploy = DeployerEjb.AUTO_DEPLOY.get();
                     contextInfo.appInfo.autoDeploy = autoDeploy == null || 
autoDeploy;
                     DeployerEjb.AUTO_DEPLOY.remove();

Reply via email to