tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: when using default http session try to find contextual listener for session.invalidate
Date Mon, 29 Dec 2014 14:19:32 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop cfbc84335 -> bf851e2b5


when using default http session try to find contextual listener for session.invalidate


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

Branch: refs/heads/develop
Commit: bf851e2b58eb4bd54070c8aa9f89010afcef6f1f
Parents: cfbc843
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Dec 29 15:19:02 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Dec 29 15:19:02 2014 +0100

----------------------------------------------------------------------
 .../server/httpd/HttpListenerRegistry.java      | 36 +++++++++++++++++++-
 tck/cdi-embedded/src/test/resources/failing.xml |  2 +-
 2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/bf851e2b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpListenerRegistry.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpListenerRegistry.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpListenerRegistry.java
index 819a43a..aff3759 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpListenerRegistry.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpListenerRegistry.java
@@ -16,14 +16,21 @@
  */
 package org.apache.openejb.server.httpd;
 
+import org.apache.openejb.AppContext;
+import org.apache.openejb.assembler.classic.WebAppBuilder;
 import org.apache.openejb.cdi.CdiAppContextsService;
 import org.apache.openejb.cdi.Proxys;
+import org.apache.openejb.core.WebContext;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.AppFinder;
+import org.apache.openejb.web.LightweightWebAppBuilder;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.spi.ContextsService;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -58,7 +65,34 @@ public class HttpListenerRegistry implements HttpListener {
             systemInstance.setComponent(HttpServletRequest.class, Proxys.threadLocalProxy(HttpServletRequest.class,
request, mock));
         }
         if (systemInstance.getComponent(HttpSession.class) == null) {
-            systemInstance.setComponent(javax.servlet.http.HttpSession.class, Proxys.threadLocalRequestSessionProxy(request,
mock != null ? mock.getSession() : null));
+            final javax.servlet.http.HttpSession delegate = mock != null ? mock.getSession()
: null;
+            systemInstance.setComponent(javax.servlet.http.HttpSession.class, Proxys.threadLocalRequestSessionProxy(request,
new ServletSessionAdapter(delegate) {
+                @Override
+                public void invalidate() {
+                    final Object web = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(),
AppFinder.AppOrWebContextTransformer.INSTANCE);
+                    if (WebContext.class.isInstance(web)) {
+                        doInvokeSpecificListeners(WebContext.class.cast(web).getContextRoot());
+                    } else if (AppContext.class.isInstance(web)) {
+                        doInvokeSpecificListeners(AppContext.class.cast(web).getId());
+                    }
+                    super.invalidate();
+                }
+
+                private void doInvokeSpecificListeners(final String web) {
+                    final WebAppBuilder wab = SystemInstance.get().getComponent(WebAppBuilder.class);
+                    if (LightweightWebAppBuilder.class.isInstance(wab)) {
+                        final Collection<HttpSessionListener> listeners = LightweightWebAppBuilderListenerExtractor.findByTypeForContext(web,
HttpSessionListener.class);
+                        final HttpSessionEvent event = new HttpSessionEvent(this);
+                        for (final HttpSessionListener o : listeners) {
+                            try {
+                                o.sessionDestroyed(event);
+                            } catch (final Throwable th) {
+                                // ignore, may be undeployed
+                            }
+                        }
+                    }
+                }
+            }));
         }
         if (systemInstance.getComponent(ServletContext.class) == null) { // a poor impl but
at least we set something
             systemInstance.setComponent(ServletContext.class, new EmbeddedServletContext());

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf851e2b/tck/cdi-embedded/src/test/resources/failing.xml
----------------------------------------------------------------------
diff --git a/tck/cdi-embedded/src/test/resources/failing.xml b/tck/cdi-embedded/src/test/resources/failing.xml
index fbbb50c..0dfccb1 100644
--- a/tck/cdi-embedded/src/test/resources/failing.xml
+++ b/tck/cdi-embedded/src/test/resources/failing.xml
@@ -26,7 +26,7 @@
     -Dopenejb.deploymentId.format={appId}/{ejbJarId}/{ejbName}
     -->
     <classes>
-      <class name="org.jboss.cdi.tck.tests.decorators.builtin.http.servletcontext.BuiltinServletContextDecoratorTest"
/>
+      <class name="org.jboss.cdi.tck.tests.decorators.builtin.http.session.BuiltinHttpSessionDecoratorTest"
/>
     </classes>
   </test>
 </suite>


Mime
View raw message