tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: destroying session scope before session in some tomee lifecycles
Date Mon, 04 May 2015 16:26:12 GMT
Repository: tomee
Updated Branches:
  refs/heads/master de0c9893c -> bf1b6e58a


destroying session scope before session in some tomee lifecycles


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

Branch: refs/heads/master
Commit: bf1b6e58a22a4d5f261f9ac09539e09b704b079c
Parents: de0c989
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon May 4 18:25:48 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon May 4 18:25:48 2015 +0200

----------------------------------------------------------------------
 .../openejb/cdi/CdiAppContextsService.java      | 49 ++++++++++++--------
 tck/cdi-tomee/src/test/resources/failing.xml    |  2 +-
 .../tomee/catalina/TomEEContainerListener.java  |  2 +-
 3 files changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/bf1b6e58/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 d6a202e..02c190f 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
@@ -184,7 +184,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
             applicationContext.destroy();
             webBeansContext.getBeanManagerImpl().fireEvent(
                     appEvent,
-                    new EventMetadataImpl(null, ServletContext.class.isInstance(appEvent)
? ServletContext.class : Object.class,null, new Annotation[] { DestroyedLiteral.INSTANCE_APPLICATION_SCOPED
}, webBeansContext),
+                    new EventMetadataImpl(null, ServletContext.class.isInstance(appEvent)
? ServletContext.class : Object.class, null, new Annotation[]{DestroyedLiteral.INSTANCE_APPLICATION_SCOPED},
webBeansContext),
                     false);
             applicationContext.setActive(true);
 
@@ -199,6 +199,17 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
                 webBeansContext.getBeanManagerImpl().fireEvent(id, DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED);
             }
         }
+        for (final SessionContext sc : sessionCtxManager.getContextById().values()) { //
ensure to destroy session context in time at shutdown and not with session which can happen
later
+            final Object event = HttpSessionContextSessionAware.class.isInstance(sc) ? HttpSessionContextSessionAware.class.cast(sc).getSession()
: sc;
+            if (HttpSession.class.isInstance(event)) {
+                final HttpSession httpSession = HttpSession.class.cast(event);
+                if (httpSession.getId() == null) {
+                    continue;
+                }
+                initSessionContext(httpSession);
+            }
+            destroySessionContext(event);
+        }
         sessionCtxManager.getContextById().clear();
     }
 
@@ -244,12 +255,11 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
             } else {
                 if (logger.isWarningEnabled()) {
                     logger.warning("CDI-OpenWebBeans container in OpenEJB does not support
context scope "
-                        + scopeType.getSimpleName()
-                        + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton
are supported scope types");
+                            + scopeType.getSimpleName()
+                            + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and
@Singleton are supported scope types");
                 }
             }
         }
-
     }
 
     @Override
@@ -289,8 +299,8 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
             } else {
                 if (logger.isWarningEnabled()) {
                     logger.warning("CDI-OpenWebBeans container in OpenEJB does not support
context scope "
-                        + scopeType.getSimpleName()
-                        + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and @Singleton
are supported scope types");
+                            + scopeType.getSimpleName()
+                            + ". Scopes @Dependent, @RequestScoped, @ApplicationScoped and
@Singleton are supported scope types");
                 }
             }
         }
@@ -317,7 +327,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
             webBeansContext.getBeanManagerImpl().fireEvent(
                     appEvent,
                     new EventMetadataImpl(null,
-                            ServletContext.class.isInstance(appEvent) ? ServletContext.class
: Object.class, null, new Annotation[] { InitializedLiteral.INSTANCE_APPLICATION_SCOPED },
+                            ServletContext.class.isInstance(appEvent) ? ServletContext.class
: Object.class, null, new Annotation[]{InitializedLiteral.INSTANCE_APPLICATION_SCOPED},
                             webBeansContext),
                     false);
         }
@@ -326,12 +336,11 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
     @Override
     public boolean supportsContext(final Class<? extends Annotation> scopeType) {
         return scopeType.equals(RequestScoped.class)
-            || scopeType.equals(SessionScoped.class)
-            || scopeType.equals(ApplicationScoped.class)
-            || scopeType.equals(Dependent.class)
-            || scopeType.equals(Singleton.class)
-            || scopeType.equals(ConversationScoped.class) && supportsConversation();
-
+                || scopeType.equals(SessionScoped.class)
+                || scopeType.equals(ApplicationScoped.class)
+                || scopeType.equals(Dependent.class)
+                || scopeType.equals(Singleton.class)
+                || scopeType.equals(ConversationScoped.class) && supportsConversation();
     }
 
     private void initRequestContext(final Object event) {
@@ -403,7 +412,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
     }
 
     public void checkConversationState() {
-        final ServletRequestContext rc  = getRequestContext(false);
+        final ServletRequestContext rc = getRequestContext(false);
         if (rc != null && rc.getServletRequest() != null && conversationService
!= null) {
             final HttpSession session = rc.getServletRequest().getSession(false);
             if (session != null) {
@@ -536,7 +545,6 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
                 } catch (final Exception e) {
                     return (SessionContext) clazz.newInstance();
                 }
-
             } catch (final Exception e) {
                 logger.error("Can't instantiate " + classname + ", using default session
context", e);
             }
@@ -550,7 +558,7 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
      *
      * @param session http session object
      */
-    private void destroySessionContext(final HttpSession session) {
+    private void destroySessionContext(final Object session) {
         if (session != null) {
             final SessionContext context = sessionContext.get();
 
@@ -573,13 +581,15 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
             sessionContext.remove();
 
             //Remove session from manager
-            sessionCtxManager.removeSessionContextWithSessionId(session.getId());
+            if (HttpSession.class.isInstance(session)) {
+                sessionCtxManager.removeSessionContextWithSessionId(HttpSession.class.cast(session).getId());
+            }
         }
     }
 
-    private void doDestroySession(SessionContext context, HttpSession session) {
+    private void doDestroySession(final SessionContext context, final Object event) {
         context.destroy();
-        webBeansContext.getBeanManagerImpl().fireEvent(session, DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+        webBeansContext.getBeanManagerImpl().fireEvent(event, DestroyedLiteral.INSTANCE_SESSION_SCOPED);
     }
 
     //we don't have initApplicationContext
@@ -721,7 +731,6 @@ public class CdiAppContextsService extends AbstractContextsService implements
Co
                 } catch (final Exception e) {
                     logger.error(OWBLogConst.ERROR_0013, e);
                 }
-
             } else {
                 logger.warning("Could NOT lazily initialize session context because NO active
request context");
             }

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf1b6e58/tck/cdi-tomee/src/test/resources/failing.xml
----------------------------------------------------------------------
diff --git a/tck/cdi-tomee/src/test/resources/failing.xml b/tck/cdi-tomee/src/test/resources/failing.xml
index 6ec10c3..23ceda0 100644
--- a/tck/cdi-tomee/src/test/resources/failing.xml
+++ b/tck/cdi-tomee/src/test/resources/failing.xml
@@ -23,7 +23,7 @@
   -->
   <test name="CDI TCK for developers (debugging)">
     <classes>
-      <class name="org.jboss.cdi.tck.tests.context.request.ws.RequestContextTest" />
+      <class name="org.jboss.cdi.tck.tests.deployment.shutdown.ApplicationShutdownLifecycleTest"
/>
     </classes>
   </test>
 </suite>

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf1b6e58/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEContainerListener.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEContainerListener.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEContainerListener.java
index 048efa1..24fa536 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEContainerListener.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEContainerListener.java
@@ -33,7 +33,7 @@ public class TomEEContainerListener implements ContainerListener {
             context.set((StandardContext) event.getContainer());
         } else if ("afterContextInitialized".equals(event.getType())) {
             context.remove();
-        } else if (Context.CHANGE_SESSION_ID_EVENT.endsWith(event.getType())) {
+        } else if (Context.CHANGE_SESSION_ID_EVENT.endsWith(event.getType())) { // note:
we could use a javax.servlet.http.HttpSessionIdListener
             final String[] ids = (String[]) event.getData();
 
             final WebBeansContext wbc = WebBeansContext.currentInstance();


Mime
View raw message