tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: some cleanup to avoid to rely on WBC.currentInstance() to test if CDI is there
Date Wed, 24 Aug 2016 11:30:38 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 069385506 -> ae9700646


some cleanup to avoid to rely on WBC.currentInstance() to test if CDI is there


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

Branch: refs/heads/master
Commit: ae97006461eb755aefa90f779a3f2aa7ab90d85f
Parents: 0693855
Author: Romain manni-Bucau <rmannibucau@gmail.com>
Authored: Wed Aug 24 13:30:29 2016 +0200
Committer: Romain manni-Bucau <rmannibucau@gmail.com>
Committed: Wed Aug 24 13:30:29 2016 +0200

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java       |  3 ++-
 .../assembler/classic/ValidatorBuilder.java        |  4 +++-
 .../org/apache/openejb/cdi/CustomELAdapter.java    | 17 ++++++++++++++++-
 .../org/apache/openejb/cdi/OpenEJBLifecycle.java   | 10 +++++-----
 .../apache/openejb/cipher/CdiPasswordCipher.java   | 13 +++++++++----
 .../java/org/apache/openejb/config/AutoConfig.java | 10 +++++++++-
 .../core/webservices/HandlerResolverImpl.java      |  4 +++-
 .../testing/SingleApplicationComposerRunner.java   | 10 +++++++++-
 .../openejb/web/LightweightWebAppBuilder.java      |  9 ++++++++-
 .../openejb/server/cxf/pojo/PojoEndpoint.java      |  4 +++-
 .../openejb/server/httpd/HttpRequestImpl.java      |  4 +++-
 .../catalina/startup/OpenEJBContextConfig.java     |  3 ++-
 .../tomee/catalina/TomEEWebappClassLoader.java     |  5 ++++-
 .../embedded/junit/TomEEEmbeddedSingleRunner.java  | 10 +++++++++-
 .../myfaces/TomEEFacesConfigResourceProvider.java  |  4 +++-
 15 files changed, 88 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/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 76b161a..ae52f14 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
@@ -2838,7 +2838,8 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
         return new LazyResource(new Callable<Object>() {
             @Override
             public Object call() throws Exception {
-                final boolean appClassLoader = "true".equals(serviceInfo.properties.remove("UseAppClassLoader"));
+                final boolean appClassLoader = "true".equals(serviceInfo.properties.remove("UseAppClassLoader"))
+                        || serviceInfo.originAppName != null;
 
                 final Thread thread = Thread.currentThread();
                 final ClassLoader old = thread.getContextClassLoader();

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
index 18a7dea..d5c11d0 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java
@@ -22,6 +22,7 @@ import org.apache.openejb.jee.bval.ExecutableValidationType;
 import org.apache.openejb.jee.bval.PropertyType;
 import org.apache.openejb.jee.bval.ValidationConfigType;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.WebBeansContext;
@@ -238,7 +239,8 @@ public final class ValidatorBuilder {
     }
 
     private static <T> T newInstance(final OpenEjbConfig config, final Class<T>
clazz) throws Exception {
-        final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+        final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
+                Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
         if (webBeansContext == null) {
             return clazz.newInstance();
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/cdi/CustomELAdapter.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CustomELAdapter.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CustomELAdapter.java
index 72bbff9..758142f 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CustomELAdapter.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CustomELAdapter.java
@@ -18,6 +18,7 @@
 package org.apache.openejb.cdi;
 
 import org.apache.openejb.AppContext;
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.el22.WebBeansELResolver;
 import org.apache.webbeans.el22.WrappedExpressionFactory;
 import org.apache.webbeans.spi.adaptor.ELAdaptor;
@@ -38,7 +39,21 @@ public class CustomELAdapter implements ELAdaptor {
 
     @Override
     public ELResolver getOwbELResolver() {
-        return new WebBeansELResolver();
+        WebBeansContext old = null;
+        boolean exit = false;
+        try { // just some safety around this but should be very very rare
+            WebBeansContext.currentInstance();
+        } catch (final IllegalStateException ise) {
+            old = ThreadSingletonServiceImpl.enter(appContext.getWebBeansContext());
+            exit = true;
+        }
+        try {
+            return new WebBeansELResolver();
+        } finally {
+            if (exit) {
+                ThreadSingletonServiceImpl.exit(old);
+            }
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
index 99ca039..61b7f1f 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
@@ -145,17 +145,17 @@ public class OpenEJBLifecycle implements ContainerLifecycle {
         try {
             Thread.currentThread().setContextClassLoader(stuff.getClassLoader());
 
+            final AppContext appContext = stuff.getAppContext();
+            if (stuff.getWebContext() == null) { // do it before any other things to keep
our singleton finder working
+                appContext.setWebBeansContext(webBeansContext);
+            }
+
             //Load all plugins
             webBeansContext.getPluginLoader().startUp();
 
             //Get Plugin
             final CdiPlugin cdiPlugin = (CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin();
 
-            final AppContext appContext = stuff.getAppContext();
-            if (stuff.getWebContext() == null) {
-                appContext.setWebBeansContext(webBeansContext);
-            }
-
             cdiPlugin.setClassLoader(stuff.getClassLoader());
             cdiPlugin.setWebBeansContext(webBeansContext);
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/cipher/CdiPasswordCipher.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cipher/CdiPasswordCipher.java
b/container/openejb-core/src/main/java/org/apache/openejb/cipher/CdiPasswordCipher.java
index 0e8077e..f51b5db 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cipher/CdiPasswordCipher.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cipher/CdiPasswordCipher.java
@@ -32,10 +32,15 @@ public final class CdiPasswordCipher implements PasswordCipher {
     @Override
     public String decrypt(final char[] encryptedPassword) {
         final String string = new String(encryptedPassword);
-        final WebBeansContext wbc = WebBeansContext.currentInstance();
-        final BeanManagerImpl mgr = wbc.getBeanManagerImpl();
-        if (!mgr.isInUse()) { // not yet the time to use CDI, container is not started
-            // would be cool to log a warning here but would pollute the logs with false
positives
+        final BeanManagerImpl mgr;
+        try {
+            final WebBeansContext wbc = WebBeansContext.currentInstance();
+            mgr = wbc.getBeanManagerImpl();
+            if (!mgr.isInUse()) { // not yet the time to use CDI, container is not started
+                // would be cool to log a warning here but would pollute the logs with false
positives
+                return "cipher:cdi:" + string;
+            }
+        } catch (final IllegalStateException ise) { // no cdi
             return "cipher:cdi:" + string;
         }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
index 71b0b9c..0653f4d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
@@ -947,7 +947,15 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
                 resource.setId(modulePrefix + replaceJavaAndSlash(originalId));
             }
             resource.setJndi(PropertyPlaceHolderHelper.value(resource.getJndi()));
-            resource.getProperties().putAll(PropertyPlaceHolderHelper.holds(resource.getProperties()));
+
+            final Thread thread = Thread.currentThread();
+            final ClassLoader oldCl = thread.getContextClassLoader();
+            thread.setContextClassLoader(module.getClassLoader());
+            try {
+                resource.getProperties().putAll(PropertyPlaceHolderHelper.holds(resource.getProperties()));
+            } finally {
+                thread.setContextClassLoader(oldCl);
+            }
 
             final Collection<String> aliases = resource.getAliases();
             if (!aliases.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
index 504ca01..b5962ea 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
@@ -38,6 +38,7 @@ import javax.xml.ws.handler.PortInfo;
 
 import org.apache.openejb.Injection;
 import org.apache.openejb.InjectionProcessor;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.WebBeansContext;
@@ -86,7 +87,8 @@ public class HandlerResolverImpl implements HandlerResolver {
 
         final List<Handler> handlers = new ArrayList<Handler>(handlerChain.getHandlers().size());
         for (final HandlerData handler : handlerChain.getHandlers()) {
-            final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+            final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
+                    Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
             if (webBeansContext != null) { // cdi
                 final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
                 if (bm.isInUse()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
index 6c40003..b0a36fe 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
@@ -171,7 +171,15 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner
{
     }
 
     private static void composerInject(final Object target) throws IllegalAccessException
{
-        OWBInjector.inject(WebBeansContext.currentInstance().getBeanManagerImpl(), target,
null);
+        WebBeansContext wbc = null;
+        try {
+            wbc = WebBeansContext.currentInstance();
+        } catch (final IllegalStateException ise) {
+            // no-op
+        }
+        if (wbc != null) {
+            OWBInjector.inject(wbc.getBeanManagerImpl(), target, null);
+        }
 
         final Object app = APP.get();
         final Class<?> aClass = target.getClass();

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/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 28b2ddf..504090f 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
@@ -230,7 +230,14 @@ public class LightweightWebAppBuilder implements WebAppBuilder {
             servletDeploymentInfo.put(webAppInfo, deployedWebObjects);
 
             if (webContext.getWebBeansContext() != null) {
-                OpenEJBLifecycle.class.cast(webContext.getWebBeansContext().getService(ContainerLifecycle.class)).startServletContext(sce.getServletContext());
+                final Thread thread = Thread.currentThread();
+                final ClassLoader old = thread.getContextClassLoader();
+                thread.setContextClassLoader(webContext.getClassLoader());
+                try {
+                    OpenEJBLifecycle.class.cast(webContext.getWebBeansContext().getService(ContainerLifecycle.class)).startServletContext(sce.getServletContext());
+                } finally {
+                    thread.setContextClassLoader(old);
+                }
             }
 
             if (addServletMethod == null) { // can't manage filter/servlets

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
index 97021a3..c564d73 100644
--- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
@@ -35,6 +35,7 @@ import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.cxf.CxfEndpoint;
 import org.apache.openejb.server.cxf.CxfServiceConfiguration;
 import org.apache.openejb.server.cxf.JaxWsImplementorInfoImpl;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.component.AbstractOwbBean;
@@ -106,7 +107,8 @@ public class PojoEndpoint extends CxfEndpoint {
         final ClassLoader old = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(loader);
         try {
-            final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+            final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
+                    Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
             final BeanManagerImpl bm = webBeansContext == null ? null : webBeansContext.getBeanManagerImpl();
             if (bm != null && bm.isInUse()) { // try cdi bean
                 if (JAXWS_AS_CDI_BEANS) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
index 129a4d7..42951cf 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
@@ -24,6 +24,7 @@ import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.httpd.part.CommonsFileUploadPartFactory;
 import org.apache.openejb.server.httpd.session.SessionManager;
 import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.ArrayEnumeration;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.WebBeansContext;
@@ -1037,7 +1038,8 @@ public class HttpRequestImpl implements HttpRequest {
         final OpenEJBAsyncContext asyncContext = new OpenEJBAsyncContext(HttpServletRequest.class.cast(servletRequest)
/* TODO */, servletResponse, contextPath);
         asyncContext.internalStartAsync();
         asyncStarted = true;
-        final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+        final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
+                Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
         return webBeansContext != null ?
                 new EEFilter.AsynContextWrapper(asyncContext, servletRequest, webBeansContext)
: asyncContext;
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/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 f54051a..2dee1ed 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
@@ -40,6 +40,7 @@ import org.apache.openejb.config.ServiceUtils;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.httpd.EEFilter;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
@@ -405,7 +406,7 @@ public class OpenEJBContextConfig extends ContextConfig {
             return;
         }
 
-        if (WebBeansContext.currentInstance() != null) {
+        if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE)
!= null) {
             final FilterDef asyncOwbFilter = new FilterDef();
             asyncOwbFilter.setAsyncSupported("true");
             asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped
in async tasks");

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/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 0ca7a1e..c778fac 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
@@ -34,6 +34,7 @@ import org.apache.openejb.config.QuickJarsTxtParser;
 import org.apache.openejb.core.ParentClassLoaderFinder;
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
@@ -467,7 +468,9 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader
{
         }
         if ("META-INF/faces-config.xml".equals(name)) { // mojarra workaround
             try {
-                if (WebBeansContext.currentInstance() == null && Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.jsf.ignore-owb",
"true"))) {
+                if (AppFinder.findAppContextOrWeb(
+                        Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE)
== null
+                        && Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.jsf.ignore-owb",
"true"))) {
                     final Collection<URL> list = new HashSet<>(Collections.list(super.getResources(name)));
                     final Iterator<URL> it = list.iterator();
                     while (it.hasNext()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
index dbc04a5..4a7f5fc 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
@@ -331,7 +331,15 @@ public class TomEEEmbeddedSingleRunner extends BlockJUnit4ClassRunner
{
     }
 
     private static void composerInject(final Object target) throws IllegalAccessException
{
-        OWBInjector.inject(WebBeansContext.currentInstance().getBeanManagerImpl(), target,
null);
+        WebBeansContext webBeansContext = null;
+        try {
+            webBeansContext = WebBeansContext.currentInstance();
+        } catch (final IllegalStateException ise) {
+            // no-op
+        }
+        if (webBeansContext != null) {
+            OWBInjector.inject(webBeansContext.getBeanManagerImpl(), target, null);
+        }
 
         final Object app = APP.get();
         final Class<?> aClass = target.getClass();

http://git-wip-us.apache.org/repos/asf/tomee/blob/ae970064/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
index 7053c7a..247e493 100644
--- a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
+++ b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
@@ -20,6 +20,7 @@ import org.apache.myfaces.config.DefaultFacesConfigResourceProvider;
 import org.apache.myfaces.shared.util.ClassUtils;
 import org.apache.openejb.config.NewLoaderLogic;
 import org.apache.openejb.loader.Files;
+import org.apache.openejb.util.AppFinder;
 import org.apache.openejb.util.URLs;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.xbean.finder.UrlSet;
@@ -126,7 +127,8 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource
         }
 
         try {
-            if (WebBeansContext.currentInstance() == null) {
+            if (AppFinder.findAppContextOrWeb(
+                    Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE)
== null) {
                 final Iterator<URL> toFilter = urlSet.iterator();
                 while (toFilter.hasNext()) {
                     final URL url = toFilter.next();


Mime
View raw message