openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject svn commit: r1479646 - in /openwebbeans/branches/owb_1.1.x: webbeans-impl/src/main/java/org/apache/webbeans/conversation/ webbeans-web/src/main/java/org/apache/webbeans/servlet/ webbeans-web/src/main/java/org/apache/webbeans/web/context/
Date Mon, 06 May 2013 17:18:12 GMT
Author: tandraschko
Date: Mon May  6 17:18:12 2013
New Revision: 1479646

URL: http://svn.apache.org/r1479646
Log:
OWB-841 - "Could NOT lazily initialize session context because of null RequestContext" always
occur on session expire 

Modified:
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
    openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationHttpSessionListener.java
    openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
    openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
    openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java?rev=1479646&r1=1479645&r2=1479646&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
Mon May  6 17:18:12 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.conversation;
 
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -117,7 +116,30 @@ public class ConversationManager
         return map;
     }
     
-
+    /**
+     * Return all conversation/context associated with sessionid.
+     * 
+     * @param sessionId
+     * @return
+     */
+    public Map<Conversation, ConversationContext> getAndRemoveConversationMapWithSessionId(String
sessionId) 
+    {
+        Asserts.assertNotNull(sessionId,"sessionId parameter can not be null");
+        Set<Conversation> set = conversations.keySet();
+        Iterator<Conversation> it = set.iterator();
+        ConversationImpl conv = null;
+        Map<Conversation, ConversationContext> map = new HashMap<Conversation, ConversationContext>();
+        while (it.hasNext())
+        {
+            conv = (ConversationImpl) it.next();
+            if (conv.getSessionId().equals(sessionId))
+            {
+                map.put(conv, conversations.remove(conv));
+            }
+        }
+        return map;
+    }
+    
     /**
      * Remove given conversation.
      * @param conversation conversation instance
@@ -173,6 +195,7 @@ public class ConversationManager
      * Destroy conversations with given session id.
      * @param sessionId session id
      */
+    @Deprecated
     public void destroyConversationContextWithSessionId(String sessionId)
     {
         Asserts.assertNotNull(sessionId, "sessionId parameter can not be null");
@@ -243,22 +266,9 @@ public class ConversationManager
             }
         }
     }
-
-    /**
-     * Destroys all conversations
-     */
-    public void destroyAllConversations()
+    
+    public Map<Conversation, ConversationContext> getAllConversationContexts()
     {
-        Collection<ConversationContext> collection = conversations.values();
-        if(collection != null && collection.size() > 0)
-        {
-            for (ConversationContext context : collection) 
-            {
-                context.destroy();
-            }            
-        }
-        
-        //Clear conversations
-        conversations.clear();
+        return this.conversations;
     }
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationHttpSessionListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationHttpSessionListener.java?rev=1479646&r1=1479645&r2=1479646&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationHttpSessionListener.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationHttpSessionListener.java
Mon May  6 17:18:12 2013
@@ -18,14 +18,13 @@
  */
 package org.apache.webbeans.servlet;
 
-
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.ContainerLifecycle;
 import org.apache.webbeans.util.WebBeansUtil;
 
+import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.SessionScoped;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
@@ -77,8 +76,6 @@ public class WebBeansConfigurationHttpSe
             logger.log(Level.FINE, "Destroying a session with session id : [{0}]", event.getSession().getId());
         }
         this.lifeCycle.getContextService().endContext(SessionScoped.class, event.getSession());
-
-        ConversationManager conversationManager = WebBeansContext.getInstance().getConversationManager();
-        conversationManager.destroyConversationContextWithSessionId(event.getSession().getId());
+        this.lifeCycle.getContextService().endContext(ConversationScoped.class, event.getSession());
     }
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1479646&r1=1479645&r2=1479646&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
Mon May  6 17:18:12 2013
@@ -21,7 +21,6 @@ package org.apache.webbeans.servlet;
 import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.ContainerLifecycle;
@@ -30,6 +29,7 @@ import org.apache.webbeans.util.WebBeans
 import org.apache.webbeans.web.context.WebContextsService;
 import org.apache.webbeans.web.util.ServletCompatibilityUtil;
 
+import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
 import javax.servlet.ServletContextEvent;
@@ -195,8 +195,6 @@ public class WebBeansConfigurationListen
             logger.log(Level.FINE, "Destroying a session with session id : [{0}]", event.getSession().getId());
         }
         this.lifeCycle.getContextService().endContext(SessionScoped.class, event.getSession());
-
-        ConversationManager conversationManager = WebBeansContext.getInstance().getConversationManager();
-        conversationManager.destroyConversationContextWithSessionId(event.getSession().getId());
+        this.lifeCycle.getContextService().endContext(ConversationScoped.class, event.getSession());
     }
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java?rev=1479646&r1=1479645&r2=1479646&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/SessionContextManager.java
Mon May  6 17:18:12 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.web.context;
 
-import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -73,34 +72,17 @@ public class SessionContextManager
     }
     
     /**
-     * Destroy session context with given id.
+     * Removes the {@link SessionContext} for the given id.
+     *
      * @param sessionId session id
      */
-    public void destroySessionContextWithSessionId(String sessionId)
+    public void removeSessionContextWithSessionId(String sessionId)
     {
-        SessionContext sessionContext = this.sessionContexts.remove(sessionId);
-        if(sessionContext != null)
-        {
-            sessionContext.destroy();
-        }
+        this.sessionContexts.remove(sessionId);
     }
     
-    /**
-     * Destroys all sessions.
-     */
-    public void destroyAllSessions()
+    public Map<String, SessionContext> getAllSessionContexts()
     {
-        //Destroy all contexts
-        Collection<SessionContext> allSessionContexts = this.sessionContexts.values();
-        if(allSessionContexts != null && allSessionContexts.size() > 0)
-        {
-            for(SessionContext sessionContext : allSessionContexts)
-            {
-                sessionContext.destroy();
-            }
-
-        //Clear map
-        allSessionContexts.clear();
-        }
+        return sessionContexts;
     }
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1479646&r1=1479645&r2=1479646&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Mon May  6 17:18:12 2013
@@ -48,7 +48,9 @@ import javax.servlet.ServletRequestEvent
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.lang.annotation.Annotation;
+import java.util.Collection;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -221,6 +223,11 @@ public class WebContextsService extends 
         }
         else if(supportsConversation && scopeType.equals(ConversationScoped.class))
         {
+            if (endParameters != null && endParameters instanceof HttpSession)
+            {
+                destoryAllConversationsForSession((HttpSession) endParameters);
+            }
+
             destroyConversationContext();
         }
         else if(scopeType.equals(Dependent.class))
@@ -481,6 +488,12 @@ public class WebContextsService extends 
             //Get current session context
             SessionContext context = sessionContexts.get();
 
+            if (context == null)
+            {
+                initSessionContext(session);
+                context = sessionContexts.get();
+            }
+
             //Destroy context
             if (context != null)
             {
@@ -492,7 +505,7 @@ public class WebContextsService extends 
             sessionContexts.remove();
 
             //Remove session from manager
-            sessionCtxManager.destroySessionContextWithSessionId(session.getId());
+            sessionCtxManager.removeSessionContextWithSessionId(session.getId());
         }
     }
 
@@ -564,10 +577,40 @@ public class WebContextsService extends 
         }
         
         //destroyDependents all sessions
-        sessionCtxManager.destroyAllSessions();
+        Collection<SessionContext> allSessionContexts = sessionCtxManager.getAllSessionContexts().values();
+        if (allSessionContexts != null && allSessionContexts.size() > 0)
+        {
+            for (SessionContext sessionContext : allSessionContexts)
+            {
+                sessionContexts.set(sessionContext);
+                
+                sessionContext.destroy();
+
+                sessionContexts.set(null);
+                sessionContexts.remove();
+            }
+
+            //Clear map
+            allSessionContexts.clear();
+        }
         
         //destroyDependents all conversations
-        conversationManager.destroyAllConversations();
+        Collection<ConversationContext> allConversationContexts = conversationManager.getAllConversationContexts().values();
+        if (allConversationContexts != null && allConversationContexts.size() >
0)
+        {
+            for (ConversationContext conversationContext : allConversationContexts) 
+            {
+                conversationContexts.set(conversationContext);
+                
+                conversationContext.destroy();
+
+                conversationContexts.set(null);
+                conversationContexts.remove();
+            }
+
+            //Clear conversations
+            allConversationContexts.clear();
+        }
 
         //Also clear application and singleton context
         applicationContexts.set(null);
@@ -688,6 +731,27 @@ public class WebContextsService extends 
     }
 
     /**
+     * Workaround for OWB-841
+     *
+     * @param session The current {@link HttpSession}
+     */
+    private void destoryAllConversationsForSession(HttpSession session)
+    {
+        Map<Conversation, ConversationContext> conversations =
+                conversationManager.getAndRemoveConversationMapWithSessionId(session.getId());
+
+        for (Entry<Conversation, ConversationContext> entry : conversations.entrySet())
+        {
+            conversationContexts.set(entry.getValue());
+
+            entry.getValue().destroy();
+            
+            conversationContexts.set(null);
+            conversationContexts.remove();
+        }
+    }
+    
+    /**
      * Get current request ctx.
      * @return request context
      */



Mime
View raw message