Author: dallen6
Date: 2010-03-06 16:09:27 -0500 (Sat, 06 Mar 2010)
New Revision: 6013
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpSessionBeanStore.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
Log:
Fixed problem where ServletContext was lost with invalidated sessions for cleaning up the
conversation store.
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpSessionBeanStore.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpSessionBeanStore.java 2010-03-06
06:25:30 UTC (rev 6012)
+++
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpSessionBeanStore.java 2010-03-06
21:09:27 UTC (rev 6013)
@@ -18,6 +18,7 @@
import java.util.Enumeration;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.jboss.weld.context.SessionContext;
@@ -36,8 +37,10 @@
private static final NamingScheme NAMING_SCHEME = new
NamingScheme(SessionContext.class.getName(), "#");
- // The HTTP session context to use as backing map
+ // The HTTP session to use as backing map
private HttpSession session;
+ // The ServletContext associated with the session
+ private ServletContext servletContext;
/**
* Attaches this bean store to a session dynamically. This allows the session
@@ -50,6 +53,7 @@
public void attachToSession(HttpSession session)
{
this.session = session;
+ this.servletContext = session.getServletContext();
}
/**
@@ -100,4 +104,9 @@
return NAMING_SCHEME;
}
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-03-06
06:25:30 UTC (rev 6012)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-03-06
21:09:27 UTC (rev 6013)
@@ -22,10 +22,12 @@
*/
package org.jboss.weld.servlet;
+import static org.jboss.weld.jsf.JsfHelper.getServletContext;
import static
org.jboss.weld.logging.messages.ServletMessage.REQUEST_SCOPE_BEAN_STORE_MISSING;
import static org.jboss.weld.servlet.BeanProvider.conversationManager;
import static org.jboss.weld.servlet.BeanProvider.httpSessionManager;
+import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@@ -172,38 +174,24 @@
*/
public void endRequest(HttpServletRequest request)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
+ if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) != null)
{
- return;
+ HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
+ if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
+ {
+ conversationManager(sessionBeanStore.getServletContext()).teardownContext();
+ lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
+ }
+ lifecycle.getSessionContext().setActive(false);
+ lifecycle.getSessionContext().setBeanStore(null);
+ BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
+ if (beanStore == null)
+ {
+ throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ }
+ lifecycle.endRequest(request.getRequestURI(), beanStore);
+ request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
}
- teardownSession(request);
- teardownRequest(request);
- lifecycle.getConversationContext().setBeanStore(null);
- lifecycle.getConversationContext().setActive(false);
}
-
- private void teardownSession(HttpServletRequest request)
- {
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
- if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
- {
-
conversationManager(request.getSession().getServletContext()).teardownContext();
- lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
- }
- lifecycle.getSessionContext().setActive(false);
- lifecycle.getSessionContext().setBeanStore(null);
-
- }
-
- private void teardownRequest(HttpServletRequest request)
- {
- BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
- if (beanStore == null)
- {
- throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
- }
- lifecycle.endRequest(request.getRequestURI(), beanStore);
- request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
- }
}
Show replies by date