Author: chris.laprun(a)jboss.com
Date: 2010-02-19 10:16:44 -0500 (Fri, 19 Feb 2010)
New Revision: 1785
Modified:
portal/trunk/component/wsrp/pom.xml
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
Log:
- GTNPORTAL-646: use a WCI WebAppListener to inject services needed by the WSRP admin GUI.
This should really be done with CDI.
Modified: portal/trunk/component/wsrp/pom.xml
===================================================================
--- portal/trunk/component/wsrp/pom.xml 2010-02-19 14:52:25 UTC (rev 1784)
+++ portal/trunk/component/wsrp/pom.xml 2010-02-19 15:16:44 UTC (rev 1785)
@@ -1,6 +1,6 @@
<!--
~ JBoss, a division of Red Hat
- ~ Copyright 2009, Red Hat Middleware, LLC, and individual
+ ~ Copyright 2010, Red Hat Middleware, LLC, and individual
~ contributors as indicated by the @authors tag. See the
~ copyright.txt in the distribution for a full listing of
~ individual contributors.
@@ -21,7 +21,8 @@
~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component</artifactId>
@@ -110,6 +111,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.gatein.wci</groupId>
+ <artifactId>wci-wci</artifactId>
+ <version>${org.gatein.wci.version}</version>
+ </dependency>
</dependencies>
<build>
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-02-19
14:52:25 UTC (rev 1784)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-02-19
15:16:44 UTC (rev 1785)
@@ -43,6 +43,13 @@
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.impl.RegistrationManagerImpl;
+import org.gatein.wci.ServletContainer;
+import org.gatein.wci.ServletContainerFactory;
+import org.gatein.wci.WebApp;
+import org.gatein.wci.WebAppEvent;
+import org.gatein.wci.WebAppLifeCycleEvent;
+import org.gatein.wci.WebAppListener;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wsrp.api.SessionEvent;
import org.gatein.wsrp.api.SessionEventBroadcaster;
import org.gatein.wsrp.api.SessionEventListener;
@@ -53,6 +60,7 @@
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.picocontainer.Startable;
+import javax.servlet.ServletContext;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -61,7 +69,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class ExoKernelIntegration implements Startable
+public class ExoKernelIntegration implements Startable, WebAppListener
{
private static final Logger log =
LoggerFactory.getLogger(ExoKernelIntegration.class);
@@ -76,6 +84,7 @@
private ConsumerRegistry consumerRegistry;
private ExoContainer container;
private final boolean bypass;
+ private static final String WSRP_ADMIN_GUI_CONTEXT_PATH =
"/wsrp-admin-gui";
public ExoKernelIntegration(ExoContainerContext context, InitParams params,
ConfigurationManager configurationManager,
org.exoplatform.portal.pc.ExoKernelIntegration pc) throws
Exception
@@ -123,6 +132,12 @@
{
startProducer();
startConsumers();
+
+ // listen for web app events so that we can inject services into WSRP admin UI
"cleanly"
+ // todo: this service injection should really be done using CDI... :/
+ ServletContainerFactory factory = DefaultServletContainerFactory.getInstance();
+ ServletContainer servletContainer = factory.getServletContainer();
+ servletContainer.addWebAppListener(this);
}
}
@@ -213,6 +228,11 @@
{
if (!bypass)
{
+ // stop listening to web app events
+ ServletContainerFactory factory = DefaultServletContainerFactory.getInstance();
+ ServletContainer servletContainer = factory.getServletContainer();
+ servletContainer.removeWebAppListener(this);
+
stopProducer();
stopConsumers();
}
@@ -239,6 +259,33 @@
consumerRegistry = null;
}
+ public void onEvent(WebAppEvent event)
+ {
+ if (event instanceof WebAppLifeCycleEvent)
+ {
+ WebAppLifeCycleEvent lifeCycleEvent = (WebAppLifeCycleEvent)event;
+ WebApp webApp = event.getWebApp();
+ ServletContext context = webApp.getServletContext();
+
+ // if we see the WSRP admin GUI being deployed or undeployed, inject or remove
services
+ if (WSRP_ADMIN_GUI_CONTEXT_PATH.equals(webApp.getContextPath()))
+ {
+ switch (lifeCycleEvent.getType())
+ {
+ case WebAppLifeCycleEvent.ADDED:
+
+ context.setAttribute("ConsumerRegistry", consumerRegistry);
+ context.setAttribute("ProducerConfigurationService",
producer.getConfigurationService());
+ break;
+ case WebAppLifeCycleEvent.REMOVED:
+ context.removeAttribute("ConsumerRegistry");
+ context.removeAttribute("ProducerConfigurationService");
+ break;
+ }
+ }
+ }
+ }
+
private static class SimpleSessionEventBroadcaster implements SessionEventBroadcaster
{
private Map<String, SessionEventListener> listeners = new
ConcurrentHashMap<String, SessionEventListener>();