Author: mwringe
Date: 2012-01-18 14:19:09 -0500 (Wed, 18 Jan 2012)
New Revision: 8301
Added:
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletRegistrations.java
Modified:
components/wci/trunk/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
components/wci/trunk/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
components/wci/trunk/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServlet.java
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletListener.java
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
Log:
GTNPC-76: allow for wars to specify they want to be skipped when using native wci. Add
option to manually deploy applications to wci native servletcontainercontexts.
Modified:
components/wci/trunk/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
===================================================================
---
components/wci/trunk/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -37,12 +37,15 @@
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
+import org.gatein.wci.api.GateInServlet;
+import org.gatein.wci.api.GateInServletRegistrations;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.TicketService;
import org.gatein.wci.command.CommandDispatcher;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
+import org.gatein.wci.spi.WebAppContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -50,7 +53,9 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -71,6 +76,9 @@
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
+
+ /** The monitored contexts which were manually added. */
+ private static Map<String, String> manualMonitoredContexts = new
HashMap<String, String>();
/** . */
private final Engine engine;
@@ -88,13 +96,23 @@
public Object include(ServletContext targetServletContext, HttpServletRequest request,
HttpServletResponse response,
RequestDispatchCallback callback, Object handback) throws ServletException,
IOException
- {
- return dispatcher.include(targetServletContext, request, response, callback,
handback);
- }
+ {
+ if
(manualMonitoredContexts.containsKey(targetServletContext.getServletContextName()))
+ {
+ String dispatherPath =
manualMonitoredContexts.get(targetServletContext.getServletContextName());
+ CommandDispatcher dispatcher = new CommandDispatcher(dispatherPath);
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ else
+ {
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ }
public void setCallback(Registration registration)
{
this.registration = registration;
+ GateInServletRegistrations.setServletContainerContext(this);
}
public void unsetCallback(Registration registration)
@@ -345,13 +363,18 @@
{
try
{
- log.debug("Context added " + context.getPath());
- JB6WebAppContext webAppContext = new JB6WebAppContext(context);
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
+ {
+ log.debug("Context added " + context.getPath());
+ JB6WebAppContext webAppContext = new JB6WebAppContext(context);
- //
- if (registration != null)
- {
- registration.registerWebApp(webAppContext);
+ //
+ if (registration != null)
+ {
+ registration.registerWebApp(webAppContext);
+ }
}
}
catch (Exception e)
@@ -364,9 +387,14 @@
{
try
{
- if (registration != null)
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
{
- registration.unregisterWebApp(context.getPath());
+ if (registration != null)
+ {
+ registration.unregisterWebApp(context.getPath());
+ }
}
}
catch (Exception e)
@@ -374,4 +402,41 @@
e.printStackTrace();
}
}
+
+ private boolean isDisabledNativeRegistration(ServletContext servletContext)
+ {
+ if (servletContext != null)
+ {
+ String disableWCINativeRegistration =
servletContext.getInitParameter(GateInServlet.WCIDISABLENATIVEREGISTRATION);
+ if (disableWCINativeRegistration != null &&
disableWCINativeRegistration.equalsIgnoreCase("true"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public void registerWebApp(WebAppContext webappContext, String dispatchPath)
+ {
+ if (isDisabledNativeRegistration(webappContext.getServletContext()))
+ {
+
this.manualMonitoredContexts.put(webappContext.getServletContext().getServletContextName(),
dispatchPath);
+ registration.registerWebApp(webappContext);
+ }
+ }
+
+ @Override
+ public void unregisterWebApp(ServletContext servletContext)
+ {
+ this.manualMonitoredContexts.remove(servletContext.getServletContextName());
+ registration.unregisterWebApp(servletContext.getContextPath());
+ }
}
Modified:
components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java
===================================================================
---
components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/jetty/src/main/java/org/gatein/wci/jetty/Jetty6ServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -1,7 +1,9 @@
package org.gatein.wci.jetty;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
@@ -13,6 +15,8 @@
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
+import org.gatein.wci.api.GateInServlet;
+import org.gatein.wci.api.GateInServletRegistrations;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.command.CommandDispatcher;
import org.gatein.wci.impl.DefaultServletContainerFactory;
@@ -41,6 +45,9 @@
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
+ /** The monitored contexts which were manually added. */
+ private static Map<String, String> manualMonitoredContexts = new
HashMap<String, String>();
+
private final Set<String> monitoredContextHandlerCollection = new
HashSet<String>();
/** Perform cross-context session invalidation on logout, or not */
@@ -58,13 +65,22 @@
HttpServletRequest request, HttpServletResponse response,
RequestDispatchCallback callback, Object handback)
throws ServletException, IOException
- {
- return dispatcher.include(targetServletContext, request, response,
- callback, handback);
- }
+ {
+ if
(manualMonitoredContexts.containsKey(targetServletContext.getServletContextName()))
+ {
+ String dispatherPath =
manualMonitoredContexts.get(targetServletContext.getServletContextName());
+ CommandDispatcher dispatcher = new CommandDispatcher(dispatherPath);
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ else
+ {
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ }
public void setCallback(Registration registration) {
this.registration = registration;
+ GateInServletRegistrations.setServletContainerContext(this);
}
public void unsetCallback(Registration registration) {
@@ -182,36 +198,46 @@
private void startWebAppContext(WebAppContext webappContext)
{
- try
+ try
+ {
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(webappContext.getServletContext()))
{
Jetty6WebAppContext context = new Jetty6WebAppContext(webappContext);
-
+
//
if (registration != null)
{
registration.registerWebApp(context);
}
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
}
private void stopWebAppContext(WebAppContext webappContext)
{
- try
+ try
+ {
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(webappContext.getServletContext()))
{
if (registration != null)
{
registration.unregisterWebApp(webappContext.getContextPath());
}
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
private void registerWebAppContext(WebAppContext wac)
@@ -302,5 +328,41 @@
//Ignore event
}
+ private boolean isDisabledNativeRegistration(ServletContext servletContext)
+ {
+ if (servletContext != null)
+ {
+ String disableWCINativeRegistration =
servletContext.getInitParameter(GateInServlet.WCIDISABLENATIVEREGISTRATION);
+ if (disableWCINativeRegistration != null &&
disableWCINativeRegistration.equalsIgnoreCase("true"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public void registerWebApp(org.gatein.wci.spi.WebAppContext webappContext, String
dispatchPath)
+ {
+ if (isDisabledNativeRegistration(webappContext.getServletContext()))
+ {
+
this.manualMonitoredContexts.put(webappContext.getServletContext().getServletContextName(),
dispatchPath);
+ registration.registerWebApp(webappContext);
+ }
+ }
+
+ @Override
+ public void unregisterWebApp(ServletContext servletContext)
+ {
+ this.manualMonitoredContexts.remove(servletContext.getServletContextName());
+ registration.unregisterWebApp(servletContext.getContextPath());
+ }
}
Modified:
components/wci/trunk/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
---
components/wci/trunk/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -22,6 +22,17 @@
******************************************************************************/
package org.gatein.wci.tomcat;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
@@ -31,28 +42,21 @@
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.core.StandardContext;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
-
+import org.gatein.wci.api.GateInServlet;
+import org.gatein.wci.api.GateInServletRegistrations;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.command.CommandDispatcher;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
-import org.apache.catalina.core.StandardContext;
+import org.gatein.wci.spi.WebAppContext;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-
/**
* An implementation of the <code>ServletContainerContext</code> for Tomcat.
*
@@ -71,6 +75,9 @@
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
+
+ /** The monitored contexts which were manually added. */
+ private static HashMap<String, String> manualMonitoredContexts = new
HashMap<String, String>();
/** . */
private final Engine engine;
@@ -96,12 +103,22 @@
RequestDispatchCallback callback,
Object handback) throws ServletException, IOException
{
- return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ if
(manualMonitoredContexts.containsKey(targetServletContext.getServletContextName()))
+ {
+ String dispatherPath =
manualMonitoredContexts.get(targetServletContext.getServletContextName());
+ CommandDispatcher dispatcher = new CommandDispatcher(dispatherPath);
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ else
+ {
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
}
public void setCallback(Registration registration)
{
this.registration = registration;
+ GateInServletRegistrations.setServletContainerContext(this);
}
public void unsetCallback(Registration registration)
@@ -328,13 +345,19 @@
{
try
{
- log.debug("Context added " + context.getPath());
- TC6WebAppContext webAppContext = new TC6WebAppContext(context);
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
+ {
- //
- if (registration != null)
- {
- registration.registerWebApp(webAppContext);
+ log.debug("Context added " + context.getPath());
+ TC6WebAppContext webAppContext = new TC6WebAppContext(context);
+
+ //
+ if (registration != null)
+ {
+ registration.registerWebApp(webAppContext);
+ }
}
}
catch (Exception e)
@@ -347,9 +370,14 @@
{
try
{
- if (registration != null)
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
{
- registration.unregisterWebApp(context.getPath());
+ if (registration != null)
+ {
+ registration.unregisterWebApp(context.getPath());
+ }
}
}
catch (Exception e)
@@ -357,4 +385,41 @@
e.printStackTrace();
}
}
+
+ private boolean isDisabledNativeRegistration(ServletContext servletContext)
+ {
+ if (servletContext != null)
+ {
+ String disableWCINativeRegistration =
servletContext.getInitParameter(GateInServlet.WCIDISABLENATIVEREGISTRATION);
+ if (disableWCINativeRegistration != null &&
disableWCINativeRegistration.equalsIgnoreCase("true"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public void registerWebApp(WebAppContext webappContext, String dispatchPath)
+ {
+ if (isDisabledNativeRegistration(webappContext.getServletContext()))
+ {
+
this.manualMonitoredContexts.put(webappContext.getServletContext().getServletContextName(),
dispatchPath);
+ registration.registerWebApp(webappContext);
+ }
+ }
+
+ @Override
+ public void unregisterWebApp(ServletContext servletContext)
+ {
+ this.manualMonitoredContexts.remove(servletContext.getServletContextName());
+ registration.unregisterWebApp(servletContext.getContextPath());
+ }
}
Modified:
components/wci/trunk/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
---
components/wci/trunk/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -39,6 +39,8 @@
import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.WebApp;
+import org.gatein.wci.api.GateInServlet;
+import org.gatein.wci.api.GateInServletRegistrations;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.TicketService;
@@ -46,6 +48,7 @@
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
+import org.gatein.wci.spi.WebAppContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -53,7 +56,9 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -74,6 +79,9 @@
/** The monitored contexts. */
private final Set<String> monitoredContexts = new HashSet<String>();
+
+ /** The monitored contexts which were manually added. */
+ private static Map<String, String> manualMonitoredContexts = new
HashMap<String, String>();
/** . */
private final Engine engine;
@@ -96,12 +104,22 @@
RequestDispatchCallback callback,
Object handback) throws ServletException, IOException
{
- return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ if
(manualMonitoredContexts.containsKey(targetServletContext.getServletContextName()))
+ {
+ String dispatherPath =
manualMonitoredContexts.get(targetServletContext.getServletContextName());
+ CommandDispatcher dispatcher = new CommandDispatcher(dispatherPath);
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
+ else
+ {
+ return dispatcher.include(targetServletContext, request, response, callback,
handback);
+ }
}
public void setCallback(Registration registration)
{
this.registration = registration;
+ GateInServletRegistrations.setServletContainerContext(this);
}
public void unsetCallback(Registration registration)
@@ -349,13 +367,18 @@
{
try
{
- log.debug("Context added " + context.getPath());
- TC7WebAppContext webAppContext = new TC7WebAppContext(context);
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
+ {
+ log.debug("Context added " + context.getPath());
+ TC7WebAppContext webAppContext = new TC7WebAppContext(context);
- //
- if (registration != null)
- {
- registration.registerWebApp(webAppContext);
+ //
+ if (registration != null)
+ {
+ registration.registerWebApp(webAppContext);
+ }
}
}
catch (Exception e)
@@ -368,9 +391,14 @@
{
try
{
- if (registration != null)
+ // skip if the webapp has explicitly stated it doesn't want native
registration
+ // usefull when portlets are dependent on servlet ordering
+ if (!isDisabledNativeRegistration(context.getServletContext()))
{
- registration.unregisterWebApp(context.getPath());
+ if (registration != null)
+ {
+ registration.unregisterWebApp(context.getPath());
+ }
}
}
catch (Exception e)
@@ -378,4 +406,41 @@
e.printStackTrace();
}
}
+
+ private boolean isDisabledNativeRegistration(ServletContext servletContext)
+ {
+ if (servletContext != null)
+ {
+ String disableWCINativeRegistration =
servletContext.getInitParameter(GateInServlet.WCIDISABLENATIVEREGISTRATION);
+ if (disableWCINativeRegistration != null &&
disableWCINativeRegistration.equalsIgnoreCase("true"))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public void registerWebApp(WebAppContext webappContext, String dispatchPath)
+ {
+ if (isDisabledNativeRegistration(webappContext.getServletContext()))
+ {
+
this.manualMonitoredContexts.put(webappContext.getServletContext().getServletContextName(),
dispatchPath);
+ registration.registerWebApp(webappContext);
+ }
+ }
+
+ @Override
+ public void unregisterWebApp(ServletContext servletContext)
+ {
+ this.manualMonitoredContexts.remove(servletContext.getServletContextName());
+ registration.unregisterWebApp(servletContext.getContextPath());
+ }
}
Modified: components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServlet.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServlet.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServlet.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -25,6 +25,7 @@
import org.gatein.wci.command.CommandServlet;
import org.gatein.wci.impl.generic.GenericServletContainerContext;
import org.gatein.wci.impl.generic.GenericWebAppContext;
+import org.gatein.wci.spi.WebAppContext;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
@@ -41,6 +42,8 @@
private String contextPath;
private ServletContext servletContext;
+
+ public static final String WCIDISABLENATIVEREGISTRATION =
"gatein.wci.native.DisableRegistration";
public void init() throws ServletException
{
@@ -52,10 +55,11 @@
//
String contextPath = (String)m.invoke(servletContext);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- GenericWebAppContext webAppContext = new GenericWebAppContext(servletContext,
contextPath, classLoader);
+
+ WebAppContext webAppContext = new GenericWebAppContext(servletContext,
contextPath, classLoader);
- //
- GenericServletContainerContext.register(webAppContext,
"/gateinservlet");
+ GateInServletRegistrations.register(webAppContext, "/gateinservlet");
+
this.contextPath = contextPath;
this.servletContext = servletContext;
}
@@ -69,8 +73,7 @@
{
if (contextPath != null)
{
- //GenericServletContainerContext.unregister(contextPath);
- GenericServletContainerContext.unregister(servletContext);
+ GateInServletRegistrations.unregister(servletContext);
}
}
}
\ No newline at end of file
Modified:
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletListener.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletListener.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletListener.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -45,13 +45,13 @@
GenericWebAppContext webAppContext = new GenericWebAppContext(servletContext,
contextPath, classLoader);
- GenericServletContainerContext.register(webAppContext, "/PortletWrapper");
+ GateInServletRegistrations.register(webAppContext, "/PortletWrapper");
}
public void contextDestroyed(ServletContextEvent event)
{
ServletContext servletContext = event.getServletContext();
- GenericServletContainerContext.unregister(servletContext);
+ GateInServletRegistrations.unregister(servletContext);
}
}
Added:
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletRegistrations.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletRegistrations.java
(rev 0)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletRegistrations.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2011, 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. *
+ * *
+ * 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.gatein.wci.api;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+
+import org.gatein.wci.ServletContainer;
+import org.gatein.wci.impl.DefaultServletContainer;
+import org.gatein.wci.impl.DefaultServletContainerFactory;
+import org.gatein.wci.impl.generic.GenericWebAppContext;
+import org.gatein.wci.spi.ServletContainerContext;
+import org.gatein.wci.spi.ServletContainerContext.Registration;
+import org.gatein.wci.spi.WebAppContext;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class GateInServletRegistrations
+{
+ /** . */
+ private static final Map<String, WebAppContext> pendingContexts =
Collections.synchronizedMap(new LinkedHashMap<String, WebAppContext>(16, 0.5f,
false));
+ private static HashMap<ServletContext, String> requestDispatchMap = new
HashMap<ServletContext, String>();
+
+ private static ServletContainerContext servletContainerContext;
+
+ public static void register(WebAppContext webAppContext, String dispatcherPath)
+ {
+ requestDispatchMap.put(webAppContext.getServletContext(), dispatcherPath);
+
+ if (servletContainerContext != null)
+ {
+ servletContainerContext.registerWebApp(webAppContext, dispatcherPath);
+ }
+ else
+ {
+ pendingContexts.put(webAppContext.getContextPath(), webAppContext);
+ }
+ }
+
+ public static void unregister(ServletContext servletContext)
+ {
+ requestDispatchMap.remove(servletContext);
+
+ String contextPath = servletContext.getContextPath();
+
+ if (servletContainerContext != null)
+ {
+ servletContainerContext.unregisterWebApp(servletContext);
+ }
+
+ //
+ if (pendingContexts.containsKey(contextPath))
+ {
+ pendingContexts.remove(contextPath);
+ }
+ }
+
+ public static void setServletContainerContext(ServletContainerContext context)
+ {
+ servletContainerContext = context;
+
+ for (String contextPath : pendingContexts.keySet())
+ {
+ WebAppContext webAppContext = pendingContexts.get(contextPath);
+ String dispatcherPath =
requestDispatchMap.get(webAppContext.getServletContext());
+ servletContainerContext.registerWebApp(webAppContext, dispatcherPath);
+ }
+ }
+}
+
Property changes on:
components/wci/trunk/wci/src/main/java/org/gatein/wci/api/GateInServletRegistrations.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/generic/GenericServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -23,10 +23,13 @@
package org.gatein.wci.impl.generic;
import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.api.GateInServletRegistrations;
import org.gatein.wci.authentication.GenericAuthentication;
+import org.gatein.wci.impl.DefaultServletContainer;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wci.security.Credentials;
import org.gatein.wci.spi.ServletContainerContext;
+import org.gatein.wci.spi.WebAppContext;
import org.gatein.wci.command.CommandDispatcher;
import javax.servlet.ServletContext;
@@ -46,11 +49,7 @@
*/
public class GenericServletContainerContext implements ServletContainerContext,
ServletContextListener
{
-
/** . */
- private static final Map<String, GenericWebAppContext> pendingContexts =
Collections.synchronizedMap(new HashMap<String, GenericWebAppContext>());
-
- /** . */
private static GenericServletContainerContext instance;
private static HashMap<ServletContext, String> requestDispatchMap = new
HashMap<ServletContext, String>();
@@ -70,37 +69,6 @@
{
}
- public static void register(GenericWebAppContext webAppContext, String
dispatcherPath)
- {
- requestDispatchMap.put(webAppContext.getServletContext(), dispatcherPath);
- if (instance != null && instance.registration != null)
- {
- instance.registration.registerWebApp(webAppContext);
- }
- else
- {
- pendingContexts.put(webAppContext.getContextPath(), webAppContext);
- }
- }
-
- public static void unregister(ServletContext servletContext)
- {
- requestDispatchMap.remove(servletContext);
-
- String contextPath = servletContext.getContextPath();
-
- if (instance != null && instance.registration != null)
- {
- instance.registration.unregisterWebApp(contextPath);
- }
-
- //
- if (pendingContexts.containsKey(contextPath))
- {
- pendingContexts.remove(contextPath);
- }
- }
-
/** . */
public Object include(
@@ -119,12 +87,7 @@
public void setCallback(Registration registration)
{
this.registration = registration;
-
- //
- for (GenericWebAppContext pendingContext : pendingContexts.values())
- {
- registration.registerWebApp(pendingContext);
- }
+ GateInServletRegistrations.setServletContainerContext(this);
}
public void unsetCallback(Registration registration)
@@ -172,4 +135,18 @@
{
// Should we really do something ?
}
+
+ @Override
+ public void registerWebApp(WebAppContext webappContext, String dispatcherPath)
+ {
+ requestDispatchMap.put(webappContext.getServletContext(), dispatcherPath);
+ instance.registration.registerWebApp(webappContext);
+ }
+
+ @Override
+ public void unregisterWebApp(ServletContext servletContext)
+ {
+ requestDispatchMap.remove(servletContext);
+ instance.registration.unregisterWebApp(servletContext.getContextPath());
+ }
}
\ No newline at end of file
Modified:
components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2012-01-17
16:32:16 UTC (rev 8300)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/spi/ServletContainerContext.java 2012-01-18
19:19:09 UTC (rev 8301)
@@ -76,6 +76,21 @@
void unsetCallback(Registration registration);
/**
+ * Manually register a webapp with this ServletContainerContext.
+ *
+ * @param webappContext the WebAppContext associated with the application
+ * @param dispathPath the path to be used
+ */
+ void registerWebApp(WebAppContext webappContext, String dispatchPath);
+
+ /**
+ * Manually unregister a webapp associated with this ServletContainerContext.
+ *
+ * @param servletContext the servletContext of the application to be deregistered
+ */
+ void unregisterWebApp(ServletContext servletContext);
+
+ /**
* Authentication support.
*
* @param request the request valid in the current servlet context