[seam-commits] Seam SVN: r12536 - modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 20 16:51:09 EDT 2010


Author: nickarls
Date: 2010-04-20 16:51:08 -0400 (Tue, 20 Apr 2010)
New Revision: 12536

Modified:
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java
Log:
Tinkering with HTTP artifact producers

Modified: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java	2010-04-20 20:29:16 UTC (rev 12535)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java	2010-04-20 20:51:08 UTC (rev 12536)
@@ -23,22 +23,23 @@
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
 
+import org.jboss.seam.servlet.event.qualifier.Destroyed;
 import org.jboss.seam.servlet.event.qualifier.Initialized;
+import org.slf4j.Logger;
 
 /**
  * 
  * @author Nicklas Karlsson
  * 
  *         A source for HTTP artifacts. It observes for and stores the
- *         ServletContext, HttpServletRequest and HttpSession objects. It also
- *         produces the request values for @HttpParam
+ *         ServletContext and provides the HttpSession and ServletRequest
+ *         objects
  */
 @ApplicationScoped
 public class HttpArtifacts
@@ -46,61 +47,28 @@
    private ServletContext servletContext;
 
    @Inject
-   HttpUserArtifacts httpUserArtifacts;
-
-   @Inject
    BeanManager beanManager;
+   
+   @Inject Logger log;
 
-   protected void pickup(@Observes @Initialized ServletContextEvent e)
+   protected void contextInitialized(@Observes @Initialized ServletContextEvent e)
    {
+      log.debug("Servlet context initialized with event #0", e);
       servletContext = e.getServletContext();
       servletContext.setAttribute(BeanManager.class.getName(), beanManager);
    }
 
-   /**
-    * Gets the current servlet context
-    * 
-    * @throws IllegalStateException if the servlet context has not been set
-    * @return The servlet context
-    */
+   protected void contextDestroyed(@Observes @Destroyed ServletContextEvent e)
+   {
+      log.debug("Servlet context destroyed with event #0", e);
+      servletContext = null;
+   }
+   
+   @Produces
+   @ApplicationScoped
    public ServletContext getServletContext()
    {
-      if (servletContext == null)
-      {
-         throw new IllegalStateException("Servlet Context is not set");
-      }
       return servletContext;
    }
 
-   /**
-    * Gets the current HTTP servlet request
-    * 
-    * @throws IllegalStateException if the request has not been set
-    * @return the request
-    */
-   public HttpServletRequest getRequest()
-   {
-      HttpServletRequest request = httpUserArtifacts.getRequest();
-      if (request == null)
-      {
-         throw new IllegalStateException("HTTP servlet request is not set");
-      }
-      return request;
-   }
-
-   /**
-    * Gets the current HTTP session
-    * 
-    * @throws IllegalStateException if the session has not been set
-    * @return the session
-    */
-   public HttpSession getSession()
-   {
-      HttpSession session = httpUserArtifacts.getSession();
-      if (session == null)
-      {
-         throw new IllegalStateException("HTTP session is not set");
-      }
-      return session;
-   }
 }
\ No newline at end of file

Modified: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java	2010-04-20 20:29:16 UTC (rev 12535)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java	2010-04-20 20:51:08 UTC (rev 12536)
@@ -36,7 +36,6 @@
 import org.jboss.seam.servlet.event.qualifier.Created;
 import org.jboss.seam.servlet.event.qualifier.Destroyed;
 import org.jboss.seam.servlet.event.qualifier.Initialized;
-import org.jboss.seam.servlet.http.RequestParameter;
 import org.slf4j.Logger;
 
 /**
@@ -48,7 +47,7 @@
 @RequestScoped
 public class HttpUserArtifacts implements Serializable
 {
-   private static final long serialVersionUID = 5191073522575178427L;
+   private static final long serialVersionUID = 1L;
 
    private HttpSession session;
    private HttpServletRequest request;
@@ -60,7 +59,6 @@
    {
       log.trace("Servlet request initialized with event #0", e);
       request = (HttpServletRequest) e.getServletRequest();
-      session = request.getSession();
    }
 
    protected void requestDestroyed(@Observes @Destroyed ServletRequestEvent e)
@@ -81,11 +79,15 @@
       session = null;
    }
 
+   @Produces
+   @RequestScoped
    protected HttpSession getSession()
    {
       return session;
    }
 
+   @Produces
+   @RequestScoped
    protected HttpServletRequest getRequest()
    {
       return request;



More information about the seam-commits mailing list