You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/03/22 19:15:40 UTC
[2/2] tomee git commit: implementing CDI Conversation Filter
implementing CDI Conversation Filter
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/f8d9492a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/f8d9492a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/f8d9492a
Branch: refs/heads/master
Commit: f8d9492aa3b99c2c7fb5afbcc6c912b7d542f093
Parents: 368e3fa
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sun Mar 22 19:15:27 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sun Mar 22 19:15:27 2015 +0100
----------------------------------------------------------------------
.../openejb/cdi/CdiAppContextsService.java | 9 ++++++++
.../server/httpd/EndWebBeansListener.java | 2 +-
.../tomee/catalina/OpenEJBContextConfig.java | 21 +++++++++++++++----
.../tomee/catalina/TomcatWebAppBuilder.java | 22 +++++++++++++-------
4 files changed, 42 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8d9492a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
index d4a1d06..7b0f4fe 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
@@ -97,6 +97,7 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
}
};
+ private volatile boolean autoConversationCheck = true;
public CdiAppContextsService(final WebBeansContext wbc) {
this(wbc, wbc.getOpenWebBeansConfiguration().supportsConversation());
@@ -390,6 +391,10 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
}
}
+ public boolean isAutoConversationCheck() {
+ return autoConversationCheck;
+ }
+
public void checkConversationState() {
final ServletRequestContext rc = getRequestContext(false);
if (rc != null && rc.getServletRequest() != null && conversationService != null) {
@@ -742,6 +747,10 @@ public class CdiAppContextsService extends AbstractContextsService implements Co
return webContext;
}
+ public void setAutoConversationCheck(final boolean autoConversationCheck) {
+ this.autoConversationCheck = autoConversationCheck;
+ }
+
private boolean supportsConversation() {
return conversationContext != null;
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8d9492a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
index acfc7fd..65d15e1 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
@@ -72,7 +72,7 @@ public class EndWebBeansListener implements ServletContextListener, ServletReque
*/
@Override
public void requestInitialized(ServletRequestEvent event) {
- if (contextsService != null) {
+ if (contextsService != null && contextsService.isAutoConversationCheck()) {
contextsService.checkConversationState();
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8d9492a/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 8887a63..a2df62c 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
@@ -35,6 +35,7 @@ import org.apache.openejb.assembler.classic.ResourceInfo;
import org.apache.openejb.assembler.classic.ServletInfo;
import org.apache.openejb.assembler.classic.WebAppBuilder;
import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.cdi.CdiAppContextsService;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.NewLoaderLogic;
import org.apache.openejb.config.ServiceUtils;
@@ -59,6 +60,7 @@ 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.xbean.finder.IAnnotationFinder;
import javax.servlet.Filter;
@@ -372,13 +374,13 @@ public class OpenEJBContextConfig extends ContextConfig {
webXml.addFilterMapping(mapping);
}
- { // CDI spec forces it, TODO: use it to replace org.apache.openejb.cdi.CdiAppContextsService conversation boot logic
+ {
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(NoopFilter.class.getName());
+ filter.setFilterClass(ConversationFilter.class.getName());
webXml.addFilter(filter);
}
@@ -716,14 +718,25 @@ public class OpenEJBContextConfig extends ContextConfig {
return false;
}
- public static class NoopFilter implements Filter {
+ public static class ConversationFilter implements Filter {
+ private WebBeansContext wbc;
+ private CdiAppContextsService contextsService;
+
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
- // no-op
+ try {
+ wbc = WebBeansContext.currentInstance();
+ contextsService = CdiAppContextsService.class.cast(wbc.getContextsService());
+ } catch (final Exception e) {
+ // no-op
+ }
}
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ if (contextsService != null) {
+ contextsService.checkConversationState();
+ }
chain.doFilter(request, response);
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/f8d9492a/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 3052617..d89b5f3 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
@@ -78,6 +78,7 @@ import org.apache.openejb.assembler.classic.ServletInfo;
import org.apache.openejb.assembler.classic.WebAppBuilder;
import org.apache.openejb.assembler.classic.WebAppInfo;
import org.apache.openejb.assembler.classic.event.NewEjbAvailableAfterApplicationCreated;
+import org.apache.openejb.cdi.CdiAppContextsService;
import org.apache.openejb.cdi.CdiBuilder;
import org.apache.openejb.cdi.OpenEJBLifecycle;
import org.apache.openejb.cdi.Proxys;
@@ -1050,14 +1051,21 @@ public class TomcatWebAppBuilder implements WebAppBuilder, ContextListener, Pare
standardContext.setXmlValidation(Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.xml.validation", "false")));
}
- /**
- * {@inheritDoc}
- */
- // context class loader is now defined, but no classes should have been loaded
- @SuppressWarnings("unchecked")
@Override
public void start(final StandardContext standardContext) {
- // no-op
+ final WebContext webContext = WebContext.class.cast(standardContext.getServletContext().getAttribute("openejb.web.context"));
+ if (webContext == null) {
+ return;
+ }
+ for (final FilterMap map : standardContext.findFilterMaps()) {
+ if ("CDI Conversation Filter".equals(map.getFilterName()) && webContext.getWebBeansContext() != null) {
+ final CdiAppContextsService cdiAppContextsService = CdiAppContextsService.class.cast(webContext.getWebBeansContext().getContextsService());
+ if (cdiAppContextsService != null) {
+ cdiAppContextsService.setAutoConversationCheck(false);
+ }
+ break;
+ }
+ }
}
/**
@@ -1291,6 +1299,7 @@ public class TomcatWebAppBuilder implements WebAppBuilder, ContextListener, Pare
webContext.getInjections().addAll(injections);
appContext.getWebContexts().add(webContext);
cs.addWebContext(webContext);
+ standardContext.getServletContext().setAttribute("openejb.web.context", webContext);
if (!contextInfo.appInfo.webAppAlone) {
final List<BeanContext> beanContexts = assembler.initEjbs(classLoader, contextInfo.appInfo, appContext, injections, new ArrayList<BeanContext>(), webAppInfo.moduleId);
@@ -1321,7 +1330,6 @@ public class TomcatWebAppBuilder implements WebAppBuilder, ContextListener, Pare
standardContext.setInstanceManager(instanceManager);
instanceManagers.put(classLoader, instanceManager);
standardContext.getServletContext().setAttribute(InstanceManager.class.getName(), standardContext.getInstanceManager());
-
} catch (final Exception e) {
logger.error("Error merging Java EE JNDI entries in to war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
if (System.getProperty(TOMEE_EAT_EXCEPTION_PROP) == null) {