[seam-commits] Seam SVN: r12431 - in modules/servlet/trunk/src/main/java/org/jboss/seam/servlet: event and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Apr 12 04:04:48 EDT 2010
Author: nickarls
Date: 2010-04-12 04:04:47 -0400 (Mon, 12 Apr 2010)
New Revision: 12431
Added:
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpArtifacts.java
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpUserArtifacts.java
Removed:
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java
Modified:
modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/ServletEventListener.java
Log:
Registering ServletContext
Common HTTP artifacts
Added: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpArtifacts.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpArtifacts.java (rev 0)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpArtifacts.java 2010-04-12 08:04:47 UTC (rev 12431)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+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.Initialized;
+
+/**
+ *
+ * @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
+ */
+ at ApplicationScoped
+public class HttpArtifacts
+{
+ private ServletContext servletContext;
+
+ @Inject
+ HttpUserArtifacts httpUserArtifacts;
+
+ @Inject
+ BeanManager beanManager;
+
+ protected void pickup(@Observes @Initialized ServletContextEvent 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
+ */
+ 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
Deleted: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java 2010-04-12 07:21:35 UTC (rev 12430)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java 2010-04-12 08:04:47 UTC (rev 12431)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.servlet;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.SessionScoped;
-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.ServletRequestEvent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-
-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 SessionScoped
-public class HttpManager implements Serializable
-{
- 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 sessionInitialized(@Observes @Created HttpSessionEvent e)
- {
- log.trace("HTTP session initalized with event #0", e);
- session = e.getSession();
- beanManager = (BeanManager) session.getServletContext().getAttribute(BeanManager.class.getName());
- }
-
- protected void sessionDestroyed(@Observes @Destroyed HttpSessionEvent e)
- {
- log.trace("HTTP session destroyed with event #0", e);
- session = null;
- beanManager = 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/HttpUserArtifacts.java (from rev 12428, modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpManager.java)
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpUserArtifacts.java (rev 0)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/HttpUserArtifacts.java 2010-04-12 08:04:47 UTC (rev 12431)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+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.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 SessionScoped
+public class HttpUserArtifacts implements Serializable
+{
+ private static final long serialVersionUID = 5191073522575178427L;
+
+ private HttpSession session;
+ private HttpServletRequest request;
+
+ @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 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;
+ }
+
+ protected HttpSession getSession()
+ {
+ return session;
+ }
+
+ protected HttpServletRequest getRequest()
+ {
+ return request;
+ }
+
+ @Produces
+ @HttpParam("")
+ protected String getParamValue(InjectionPoint ip)
+ {
+ return getRequest().getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
+ }
+
+}
Modified: modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/ServletEventListener.java
===================================================================
--- modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/ServletEventListener.java 2010-04-12 07:21:35 UTC (rev 12430)
+++ modules/servlet/trunk/src/main/java/org/jboss/seam/servlet/event/ServletEventListener.java 2010-04-12 08:04:47 UTC (rev 12431)
@@ -23,13 +23,10 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import javax.inject.Inject;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletContextAttributeEvent;
@@ -75,50 +72,11 @@
@WebListener
public class ServletEventListener implements HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionListener, ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, AsyncListener
{
+ @Inject
private BeanManager beanManager;
private Logger log = LoggerFactory.getLogger(ServletEventListener.class);
- // FIXME: hack to work around invalid binding in JBoss AS 6 M2
- private static final List<String> beanManagerLocations = new ArrayList<String>()
- {
- private static final long serialVersionUID = 1L;
- {
- add("java:comp/BeanManager");
- add("java:app/BeanManager");
- }
- };
-
- public ServletEventListener()
- {
- beanManager = lookupBeanManager();
- }
-
- private BeanManager lookupBeanManager()
- {
- for (String location : beanManagerLocations)
- {
- try
- {
- log.trace("Looking for Bean Manager at JNDI location #0", location);
- return (BeanManager) new InitialContext().lookup(location);
- }
- catch (NamingException e)
- {
- // No panic, keep trying
- log.debug("Bean Manager not found at JNDI location #0", location);
- }
- }
- // OK, panic
- throw new IllegalArgumentException("Could not find BeanManager in " + beanManagerLocations);
- }
-
- private void fireEvent(Object payload, Annotation... qualifiers)
- {
- log.trace("Firing event #0 with qualifiers #1", payload, qualifiers);
- beanManager.fireEvent(payload, qualifiers);
- }
-
/**
* Session activated / passivated events
*/
@@ -335,4 +293,10 @@
});
}
+ private void fireEvent(Object payload, Annotation... qualifiers)
+ {
+ log.trace("Firing event #0 with qualifiers #1", payload, qualifiers);
+ beanManager.fireEvent(payload, qualifiers);
+ }
+
}
More information about the seam-commits
mailing list