[seam-commits] Seam SVN: r12332 - in modules/servlet/trunk: src/main/java/org/jboss/seam/servlet and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Mar 30 16:34:51 EDT 2010
Author: nickarls
Date: 2010-03-30 16:34:51 -0400 (Tue, 30 Mar 2010)
New Revision: 12332
Added:
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/ContextualHttpRequest.java
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpParam.java
Removed:
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpManager.java
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpParam.java
Modified:
modules/servlet/trunk/pom.xml
Log:
Moved stuff
ContextualHttpRequest proto
Stuff a bit broken but hey, the module hasn't been officially announced yet ;-)
Modified: modules/servlet/trunk/pom.xml
===================================================================
--- modules/servlet/trunk/pom.xml 2010-03-30 16:25:44 UTC (rev 12331)
+++ modules/servlet/trunk/pom.xml 2010-03-30 20:34:51 UTC (rev 12332)
@@ -37,6 +37,7 @@
<properties>
<arquillian.version>1.0.0.Alpha1</arquillian.version>
+ <weld.version>1.0.1-Final</weld.version>
</properties>
<repositories>
@@ -77,6 +78,11 @@
<artifactId>weld-extensions</artifactId>
<version>1.0.0.Alpha1</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <version>${weld.version}</version>
+ </dependency>
<!-- Test Dependencies -->
<dependency>
Added: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/ContextualHttpRequest.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/ContextualHttpRequest.java (rev 0)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/ContextualHttpRequest.java 2010-03-30 20:34:51 UTC (rev 12332)
@@ -0,0 +1,49 @@
+package org.jboss.seam.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jboss.weld.Container;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.conversation.ConversationManager;
+import org.jboss.weld.servlet.ServletLifecycle;
+
+public abstract class ContextualHttpRequest
+{
+ private HttpServletRequest request;
+ private ServletLifecycle lifecycle;
+ private ConversationManager conversationManager;
+
+ public ContextualHttpRequest(HttpServletRequest request)
+ {
+ this.request = request;
+ lifecycle = new ServletLifecycle(Container.instance().services().get(ContextLifecycle.class));
+ }
+
+ public void run()
+ {
+ try
+ {
+ setup();
+ process();
+ }
+ finally
+ {
+ tearDown();
+ }
+ }
+
+ private void setup()
+ {
+ lifecycle.beginRequest(request);
+ String cid = request.getParameter("cid");
+ conversationManager.beginOrRestoreConversation(cid);
+ }
+
+ private void tearDown()
+ {
+ conversationManager.cleanupConversation();
+ lifecycle.endRequest(request);
+ }
+
+ protected abstract void process();
+}
Copied: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java (from rev 12262, modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpManager.java)
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java (rev 0)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java 2010-03-30 20:34:51 UTC (rev 12332)
@@ -0,0 +1,144 @@
+package org.jboss.seam.servlet;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.jboss.seam.servlet.event.qualifier.AttributeAdded;
+import org.jboss.seam.servlet.event.qualifier.AttributeRemoved;
+import org.jboss.seam.servlet.event.qualifier.AttributeReplaced;
+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.slf4j.Logger;
+
+/**
+ * A manager for acquiring HTTP artifacts
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+ at RequestScoped
+public class HttpManager
+{
+ private static final long serialVersionUID = 5191073522575178427L;
+
+ private HttpSession session;
+ private HttpServletRequest request;
+ private BeanManager beanManager;
+
+ @Inject
+ private Logger log;
+
+ protected void requestInitialized(@Observes @Initialized ServletRequestEvent e)
+ {
+ log.trace("Servlet request initialized with event #0", e);
+ request = (HttpServletRequest) e.getServletRequest();
+ }
+
+ protected void requestDestroyed(@Observes @Destroyed ServletRequestEvent e)
+ {
+ log.trace("Servlet request destroyed with event #0", e);
+ request = null;
+ }
+
+ protected void servletContextAttributeAdded(@Observes @AttributeAdded ServletContextAttributeEvent e)
+ {
+ if (BeanManager.class.getName().equals(e.getName()))
+ {
+ log.trace("Bean manager set in servlet context with event #0", e);
+ beanManager = (BeanManager) e.getValue();
+ }
+ }
+
+ protected void servletContextAttributeReplaced(@Observes @AttributeReplaced ServletContextAttributeEvent e)
+ {
+ if (BeanManager.class.getName().equals(e.getName()))
+ {
+ log.trace("Bean manager replaced in servlet context with event #0", e);
+ beanManager = (BeanManager) e.getValue();
+ }
+ }
+
+ protected void servletContextAttributeRemoved(@Observes @AttributeRemoved ServletContextAttributeEvent e)
+ {
+ if (BeanManager.class.getName().equals(e.getName()))
+ {
+ log.trace("Bean manager removed from servlet context with event #0", e);
+ beanManager = null;
+ }
+ }
+
+ protected void sessionInitialized(@Observes @Created HttpSessionEvent e)
+ {
+ log.trace("HTTP session initalized with event #0", e);
+ session = e.getSession();
+ }
+
+ protected void sessionDestroyed(@Observes @Destroyed HttpSessionEvent e)
+ {
+ log.trace("HTTP session destroyed with event #0", e);
+ session = null;
+ }
+
+ /**
+ * Returns the current HTTP session. Throws an {@link IllegalStateException}
+ * if the session is currently not set.
+ *
+ * @return The current HTTP session
+ */
+ public HttpSession getSession()
+ {
+ if (session == null)
+ {
+ throw new IllegalStateException("The HTTP session is currently not set");
+ }
+ return session;
+ }
+
+ /**
+ * Returns the current HTTP request. Throws an {@link IllegalStateException}
+ * if the request is currently not set.
+ *
+ * @return The current HTTP request
+ */
+ public HttpServletRequest getRequest()
+ {
+ if (request == null)
+ {
+ throw new IllegalStateException("The HTTP request is currently not set");
+ }
+ return request;
+ }
+
+ /**
+ * Returns the current CDI Bean Manager of the WAR. Throws an
+ * {@link IllegalStateException} if the manager is not set.
+ *
+ * @return The current HTTP request
+ */
+ public BeanManager getBeanManager()
+ {
+ if (beanManager == null)
+ {
+ throw new IllegalStateException("The Bean Manager is currently not set");
+ }
+ return beanManager;
+ }
+
+ @Produces
+ @HttpParam("")
+ String getParamValue(InjectionPoint ip)
+ {
+ return getRequest().getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
+ }
+
+}
Copied: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpParam.java (from rev 12262, modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpParam.java)
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpParam.java (rev 0)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpParam.java 2010-03-30 20:34:51 UTC (rev 12332)
@@ -0,0 +1,27 @@
+package org.jboss.seam.servlet;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifies injection points that should have their values fetched from a HTTP request attribute
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { FIELD, PARAMETER, METHOD })
+public @interface HttpParam
+{
+ @Nonbinding
+ public String value();
+}
\ No newline at end of file
Deleted: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpManager.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpManager.java 2010-03-30 16:25:44 UTC (rev 12331)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpManager.java 2010-03-30 20:34:51 UTC (rev 12332)
@@ -1,144 +0,0 @@
-package org.jboss.seam.servlet.event;
-
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.inject.Inject;
-import javax.servlet.ServletContextAttributeEvent;
-import javax.servlet.ServletRequestEvent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-
-import org.jboss.seam.servlet.event.qualifier.AttributeAdded;
-import org.jboss.seam.servlet.event.qualifier.AttributeRemoved;
-import org.jboss.seam.servlet.event.qualifier.AttributeReplaced;
-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.slf4j.Logger;
-
-/**
- * A manager for acquiring HTTP artifacts
- *
- * @author Nicklas Karlsson
- *
- */
- at RequestScoped
-public class HttpManager
-{
- private static final long serialVersionUID = 5191073522575178427L;
-
- private HttpSession session;
- private HttpServletRequest request;
- private BeanManager beanManager;
-
- @Inject
- private Logger log;
-
- protected void requestInitialized(@Observes @Initialized ServletRequestEvent e)
- {
- log.trace("Servlet request initialized with event #0", e);
- request = (HttpServletRequest) e.getServletRequest();
- }
-
- protected void requestDestroyed(@Observes @Destroyed ServletRequestEvent e)
- {
- log.trace("Servlet request destroyed with event #0", e);
- request = null;
- }
-
- protected void servletContextAttributeAdded(@Observes @AttributeAdded ServletContextAttributeEvent e)
- {
- if (BeanManager.class.getName().equals(e.getName()))
- {
- log.trace("Bean manager set in servlet context with event #0", e);
- beanManager = (BeanManager) e.getValue();
- }
- }
-
- protected void servletContextAttributeReplaced(@Observes @AttributeReplaced ServletContextAttributeEvent e)
- {
- if (BeanManager.class.getName().equals(e.getName()))
- {
- log.trace("Bean manager replaced in servlet context with event #0", e);
- beanManager = (BeanManager) e.getValue();
- }
- }
-
- protected void servletContextAttributeRemoved(@Observes @AttributeRemoved ServletContextAttributeEvent e)
- {
- if (BeanManager.class.getName().equals(e.getName()))
- {
- log.trace("Bean manager removed from servlet context with event #0", e);
- beanManager = null;
- }
- }
-
- protected void sessionInitialized(@Observes @Created HttpSessionEvent e)
- {
- log.trace("HTTP session initalized with event #0", e);
- session = e.getSession();
- }
-
- protected void sessionDestroyed(@Observes @Destroyed HttpSessionEvent e)
- {
- log.trace("HTTP session destroyed with event #0", e);
- session = null;
- }
-
- /**
- * Returns the current HTTP session. Throws an {@link IllegalStateException}
- * if the session is currently not set.
- *
- * @return The current HTTP session
- */
- public HttpSession getSession()
- {
- if (session == null)
- {
- throw new IllegalStateException("The HTTP session is currently not set");
- }
- return session;
- }
-
- /**
- * Returns the current HTTP request. Throws an {@link IllegalStateException}
- * if the request is currently not set.
- *
- * @return The current HTTP request
- */
- public HttpServletRequest getRequest()
- {
- if (request == null)
- {
- throw new IllegalStateException("The HTTP request is currently not set");
- }
- return request;
- }
-
- /**
- * Returns the current CDI Bean Manager of the WAR. Throws an
- * {@link IllegalStateException} if the manager is not set.
- *
- * @return The current HTTP request
- */
- public BeanManager getBeanManager()
- {
- if (beanManager == null)
- {
- throw new IllegalStateException("The Bean Manager is currently not set");
- }
- return beanManager;
- }
-
- @Produces
- @HttpParam("")
- String getParamValue(InjectionPoint ip)
- {
- return getRequest().getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
- }
-
-}
Deleted: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpParam.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpParam.java 2010-03-30 16:25:44 UTC (rev 12331)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/HttpParam.java 2010-03-30 20:34:51 UTC (rev 12332)
@@ -1,27 +0,0 @@
-package org.jboss.seam.servlet.event;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.enterprise.util.Nonbinding;
-import javax.inject.Qualifier;
-
-/**
- * Qualifies injection points that should have their values fetched from a HTTP request attribute
- *
- * @author Nicklas Karlsson
- *
- */
- at Qualifier
- at Retention(RUNTIME)
- at Target( { FIELD, PARAMETER, METHOD })
-public @interface HttpParam
-{
- @Nonbinding
- public String value();
-}
\ No newline at end of file
More information about the seam-commits
mailing list