[webbeans-commits] Webbeans SVN: r2404 - ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Apr 14 17:11:34 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-04-14 17:11:33 -0400 (Tue, 14 Apr 2009)
New Revision: 2404
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/HttpRequestSessionBeanStore.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
Log:
WBRI-85
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/HttpRequestSessionBeanStore.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/HttpRequestSessionBeanStore.java (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/HttpRequestSessionBeanStore.java 2009-04-14 21:11:33 UTC (rev 2404)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.webbeans.servlet;
+
+import java.util.Collections;
+import java.util.Enumeration;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.jboss.webbeans.context.SessionContext;
+import org.jboss.webbeans.context.beanstore.AbstractAttributeBackedBeanStore;
+import org.jboss.webbeans.context.beanstore.BeanStoreNamingScheme;
+import org.jboss.webbeans.context.beanstore.PrefixBeanStoreNamingScheme;
+
+/**
+ * Abstracts the servlet API specific session context
+ * as a BeanStore. Actual sessions are created lazily.
+ *
+ * @author Gavin King
+ */
+public class HttpRequestSessionBeanStore extends AbstractAttributeBackedBeanStore
+{
+ // The HTTP session context to use as backing map
+ private final HttpServletRequest request;
+
+ /**
+ * Constructor
+ *
+ * @param session The HTTP session
+ */
+ public HttpRequestSessionBeanStore(HttpServletRequest request)
+ {
+ super();
+ this.request = request;
+ }
+
+ /**
+ * @see org.jboss.webbeans.context.beanstore.AbstractAttributeBackedBeanStore#getAttribute()
+ */
+ @Override
+ protected Object getAttribute(String key)
+ {
+ HttpSession session = request.getSession(false);
+ return session==null ? null : session.getAttribute( key );
+ }
+
+ /**
+ * @see org.jboss.webbeans.context.beanstore.AbstractAttributeBackedBeanStore#getAttributeNames()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Enumeration<String> getAttributeNames()
+ {
+ HttpSession session = request.getSession(false);
+ if (session != null)
+ {
+ return session.getAttributeNames();
+ }
+ else
+ {
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+ }
+
+ /**
+ * @see org.jboss.webbeans.context.beanstore.AbstractAttributeBackedBeanStore#removeAttributes()
+ */
+ @Override
+ protected void removeAttribute(String key)
+ {
+ HttpSession session = request.getSession(false);
+ if (session != null)
+ {
+ session.removeAttribute( key );
+ }
+ }
+
+ /**
+ * @see org.jboss.webbeans.context.beanstore.AbstractAttributeBackedBeanStore#setAttribute()
+ */
+ @Override
+ protected void setAttribute(String key, Object instance)
+ {
+ HttpSession session = request.getSession(true);
+ session.setAttribute(key, instance);
+ }
+
+ @Override
+ protected BeanStoreNamingScheme getNamingScheme()
+ {
+ return new PrefixBeanStoreNamingScheme(SessionContext.class.getName(), "#");
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/HttpRequestSessionBeanStore.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2009-04-14 17:54:36 UTC (rev 2403)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2009-04-14 21:11:33 UTC (rev 2404)
@@ -82,19 +82,24 @@
* @param session
* @return the session bean store
*/
+ protected BeanStore restoreSessionContext(HttpServletRequest request)
+ {
+ BeanStore sessionBeanStore = new HttpRequestSessionBeanStore(request);
+ HttpSession session = request.getSession(false);
+ super.restoreSession(session == null ? "Inactive session" : session.getId(), sessionBeanStore);
+ if (session != null)
+ {
+ CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
+ }
+ return sessionBeanStore;
+ }
+
protected BeanStore restoreSessionContext(HttpSession session)
{
- if (session != null)
- {
- BeanStore sessionBeanStore = new HttpSessionBeanStore(session);
- super.restoreSession(session.getId(), sessionBeanStore);
- CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
- return sessionBeanStore;
- }
- else
- {
- return null;
- }
+ BeanStore beanStore = new HttpSessionBeanStore(session);
+ super.restoreSession(session.getId(), beanStore);
+ CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
+ return beanStore;
}
/**
@@ -111,7 +116,7 @@
BeanStore beanStore = new ConcurrentHashMapBeanStore();
request.setAttribute(REQUEST_ATTRIBUTE_NAME, beanStore);
super.beginRequest(request.getRequestURI(), beanStore);
- restoreSessionContext(request.getSession(false));
+ restoreSessionContext(request);
}
}
More information about the weld-commits
mailing list