Author: pete.muir(a)jboss.org
Date: 2010-09-03 12:49:24 -0400 (Fri, 03 Sep 2010)
New Revision: 13718
Added:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/Servlet3EventBridge.java
Modified:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridge.java
modules/servlet/trunk/impl/src/main/resources/META-INF/web-fragment.xml
modules/servlet/trunk/pom.xml
Log:
SEAMSERVLET-10, and gracefully degrade if BeanManager is not available
Added:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java
===================================================================
---
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java
(rev 0)
+++
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java 2010-09-03
16:49:24 UTC (rev 13718)
@@ -0,0 +1,33 @@
+package org.jboss.seam.servlet.event;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+import org.jboss.weld.extensions.beanManager.BeanManagerAware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AbstractServletEventBridge extends BeanManagerAware
+{
+
+ private transient Logger log =
LoggerFactory.getLogger(AbstractServletEventBridge.class);
+
+ protected void fireEvent(final Object payload, final Annotation... qualifiers)
+ {
+ if (isBeanManagerAvailable())
+ {
+ /*
+ * We can't always guarantee the BeanManager will be available,
+ * especially in environemnts where we don't control bootstrap order
+ * that well (e.g. Servlet containers)
+ */
+ log.trace("Firing event #0 with qualifiers #1", payload,
Arrays.asList(qualifiers));
+ getBeanManager().fireEvent(payload, qualifiers);
+ }
+ else
+ {
+ log.debug("BeanManager can't be found so not sending event " +
payload + " with qualifiers " + Arrays.asList(qualifiers));
+ }
+ }
+
+}
\ No newline at end of file
Property changes on:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/Servlet3EventBridge.java
===================================================================
---
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/Servlet3EventBridge.java
(rev 0)
+++
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/Servlet3EventBridge.java 2010-09-03
16:49:24 UTC (rev 13718)
@@ -0,0 +1,108 @@
+/*
+ * 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.event;
+
+import java.io.IOException;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.servlet.AsyncEvent;
+import javax.servlet.AsyncListener;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletRequestAttributeEvent;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.jboss.seam.servlet.event.qualifier.Added;
+import org.jboss.seam.servlet.event.qualifier.Attribute;
+import org.jboss.seam.servlet.event.qualifier.Bound;
+import org.jboss.seam.servlet.event.qualifier.Completed;
+import org.jboss.seam.servlet.event.qualifier.Created;
+import org.jboss.seam.servlet.event.qualifier.Destroyed;
+import org.jboss.seam.servlet.event.qualifier.DidActivate;
+import org.jboss.seam.servlet.event.qualifier.Error;
+import org.jboss.seam.servlet.event.qualifier.Initialized;
+import org.jboss.seam.servlet.event.qualifier.Removed;
+import org.jboss.seam.servlet.event.qualifier.Replaced;
+import org.jboss.seam.servlet.event.qualifier.StartAsync;
+import org.jboss.seam.servlet.event.qualifier.Timeout;
+import org.jboss.seam.servlet.event.qualifier.Unbound;
+import org.jboss.seam.servlet.event.qualifier.Value;
+import org.jboss.seam.servlet.event.qualifier.WillPassivate;
+
+/**
+ * A servlet listener that propagates the events to the current CDI Bean Manager
+ * event queue.
+ *
+ * This interface handles listeners that were added in Servlet 3 to preserve
+ * compatibility with Servlet 2.5
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class Servlet3EventBridge extends AbstractServletEventBridge implements
AsyncListener
+{
+ /**
+ * Asynchronous events
+ */
+
+ public void onComplete(final AsyncEvent e) throws IOException
+ {
+ fireEvent(e, COMPLETED);
+ }
+
+ public void onError(final AsyncEvent e) throws IOException
+ {
+ fireEvent(e, ERROR);
+ }
+
+ public void onStartAsync(final AsyncEvent e) throws IOException
+ {
+ fireEvent(e, STARTASYNCH);
+ }
+
+ public void onTimeout(final AsyncEvent e) throws IOException
+ {
+ fireEvent(e, TIMEOUT);
+ }
+
+ private static final AnnotationLiteral<Completed> COMPLETED = new
AnnotationLiteral<Completed>()
+ {
+ private static final long serialVersionUID = -1610281796509557441L;
+ };
+
+ private static final AnnotationLiteral<Error> ERROR = new
AnnotationLiteral<Error>()
+ {
+ private static final long serialVersionUID = -1610281796509557441L;
+ };
+
+ private static final AnnotationLiteral<StartAsync> STARTASYNCH = new
AnnotationLiteral<StartAsync>()
+ {
+ private static final long serialVersionUID = -1610281796509557441L;
+ };
+
+ private static final AnnotationLiteral<Timeout> TIMEOUT = new
AnnotationLiteral<Timeout>()
+ {
+ private static final long serialVersionUID = -1610281796509557441L;
+ };
+}
Property changes on:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/Servlet3EventBridge.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridge.java
===================================================================
---
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridge.java 2010-09-03
11:43:41 UTC (rev 13717)
+++
modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridge.java 2010-09-03
16:49:24 UTC (rev 13718)
@@ -21,14 +21,7 @@
*/
package org.jboss.seam.servlet.event;
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-
-import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Inject;
-import javax.servlet.AsyncEvent;
-import javax.servlet.AsyncListener;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
@@ -47,20 +40,15 @@
import org.jboss.seam.servlet.event.qualifier.Added;
import org.jboss.seam.servlet.event.qualifier.Attribute;
import org.jboss.seam.servlet.event.qualifier.Bound;
-import org.jboss.seam.servlet.event.qualifier.Completed;
import org.jboss.seam.servlet.event.qualifier.Created;
import org.jboss.seam.servlet.event.qualifier.Destroyed;
import org.jboss.seam.servlet.event.qualifier.DidActivate;
-import org.jboss.seam.servlet.event.qualifier.Error;
import org.jboss.seam.servlet.event.qualifier.Initialized;
import org.jboss.seam.servlet.event.qualifier.Removed;
import org.jboss.seam.servlet.event.qualifier.Replaced;
-import org.jboss.seam.servlet.event.qualifier.StartAsync;
-import org.jboss.seam.servlet.event.qualifier.Timeout;
import org.jboss.seam.servlet.event.qualifier.Unbound;
import org.jboss.seam.servlet.event.qualifier.Value;
import org.jboss.seam.servlet.event.qualifier.WillPassivate;
-import org.slf4j.Logger;
/**
* A servlet listener that propagates the events to the current CDI Bean Manager
@@ -69,18 +57,9 @@
* @author Nicklas Karlsson
*
*/
-public class ServletEventBridge implements HttpSessionActivationListener,
HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionListener,
ServletContextListener, ServletContextAttributeListener, ServletRequestListener,
ServletRequestAttributeListener, AsyncListener
+public class ServletEventBridge extends AbstractServletEventBridge implements
HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener,
HttpSessionListener, ServletContextListener, ServletContextAttributeListener,
ServletRequestListener, ServletRequestAttributeListener
{
- @Inject
- private BeanManager beanManager;
- @Inject
- private Logger log;
-
- public ServletEventBridge()
- {
- }
-
/**
* Session activated / passivated events
*/
@@ -204,36 +183,6 @@
fireEvent(e, REPLACED, new AttributeLiteral(e.getName()));
}
- /**
- * Asynchronous events
- */
-
- public void onComplete(final AsyncEvent e) throws IOException
- {
- fireEvent(e, COMPLETED);
- }
-
- public void onError(final AsyncEvent e) throws IOException
- {
- fireEvent(e, ERROR);
- }
-
- public void onStartAsync(final AsyncEvent e) throws IOException
- {
- fireEvent(e, STARTASYNCH);
- }
-
- public void onTimeout(final AsyncEvent e) throws IOException
- {
- fireEvent(e, TIMEOUT);
- }
-
- private void fireEvent(final Object payload, final Annotation... qualifiers)
- {
- log.trace("Firing event #0 with qualifiers #1", payload, qualifiers);
- beanManager.fireEvent(payload, qualifiers);
- }
-
/*
* Annotation Literal Constants
*/
@@ -287,26 +236,6 @@
private static final long serialVersionUID = -1610281796509557441L;
};
- private static final AnnotationLiteral<Completed> COMPLETED = new
AnnotationLiteral<Completed>()
- {
- private static final long serialVersionUID = -1610281796509557441L;
- };
-
- private static final AnnotationLiteral<Error> ERROR = new
AnnotationLiteral<Error>()
- {
- private static final long serialVersionUID = -1610281796509557441L;
- };
-
- private static final AnnotationLiteral<StartAsync> STARTASYNCH = new
AnnotationLiteral<StartAsync>()
- {
- private static final long serialVersionUID = -1610281796509557441L;
- };
-
- private static final AnnotationLiteral<Timeout> TIMEOUT = new
AnnotationLiteral<Timeout>()
- {
- private static final long serialVersionUID = -1610281796509557441L;
- };
-
private class AttributeLiteral extends AnnotationLiteral<Attribute> implements
Attribute
{
private static final long serialVersionUID = -7137081215123043985L;
Modified: modules/servlet/trunk/impl/src/main/resources/META-INF/web-fragment.xml
===================================================================
--- modules/servlet/trunk/impl/src/main/resources/META-INF/web-fragment.xml 2010-09-03
11:43:41 UTC (rev 13717)
+++ modules/servlet/trunk/impl/src/main/resources/META-INF/web-fragment.xml 2010-09-03
16:49:24 UTC (rev 13718)
@@ -7,5 +7,9 @@
<listener>
<listener-class>org.jboss.seam.servlet.event.ServletEventBridge</listener-class>
</listener>
+
+ <listener>
+
<listener-class>org.jboss.seam.servlet.event.Servlet3EventBridge</listener-class>
+ </listener>
</web-fragment>
Modified: modules/servlet/trunk/pom.xml
===================================================================
--- modules/servlet/trunk/pom.xml 2010-09-03 11:43:41 UTC (rev 13717)
+++ modules/servlet/trunk/pom.xml 2010-09-03 16:49:24 UTC (rev 13718)
@@ -53,6 +53,12 @@
<artifactId>seam-servlet-api</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</dependencyManagement>