Author: julien(a)jboss.com
Date: 2008-03-08 14:18:46 -0500 (Sat, 08 Mar 2008)
New Revision: 10240
Added:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainer.java
Modified:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContainer.java
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContextDispatcher.java
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainerFactory.java
modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletContainerContext.java
modules/web/trunk/web/src/test/java/org/jboss/portal/test/web/container/ServletContainerTestCase.java
Log:
make ServletContainer an interface
Modified: modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContainer.java
===================================================================
---
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContainer.java 2008-03-07
18:11:53 UTC (rev 10239)
+++
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContainer.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -22,20 +22,11 @@
******************************************************************************/
package org.jboss.portal.web;
-import org.jboss.logging.Logger;
-import org.jboss.portal.web.spi.ServletContainerContext;
-import org.jboss.portal.web.spi.WebAppContext;
-
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
/**
* A static registry for the servlet container context.
@@ -43,306 +34,29 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class ServletContainer
+public interface ServletContainer
{
- private final static Logger log = Logger.getLogger(ServletContainer.class);
- /** . */
- private final Object lock = new Object();
+ boolean addWebAppListener(WebAppListener listener);
- /** The event listeners. */
- private final ArrayList listeners = new ArrayList();
+ boolean removeWebAppListener(WebAppListener listener);
- /** The web applications. */
- private final Map webAppMap = new HashMap();
-
- /** The callback. */
- private RegistrationImpl registration;
-
/**
- * Register a servlet container context. The registration is considered as successful
if no existing context is
- * already registered.
- *
- * @param context the servlet container context to register
- * @throws IllegalArgumentException if the context is null
- */
- public void register(ServletContainerContext context)
- {
- synchronized (lock)
- {
- if (context == null)
- {
- throw new IllegalArgumentException("No null context accepted");
- }
-
- //
- if (registration == null)
- {
-
- registration = new RegistrationImpl(this, context);
-
- // Installs the call back
- context.setCallback(registration);
- }
- }
- }
-
- public boolean addWebAppListener(WebAppListener listener)
- {
- synchronized (lock)
- {
- if (listener == null)
- {
- throw new IllegalArgumentException();
- }
- if (listeners.contains(listener))
- {
- return false;
- }
- listeners.add(listener);
- for (Iterator i = webAppMap.values().iterator(); i.hasNext();)
- {
- WebApp webApp = (WebApp)i.next();
- WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.ADDED);
- safeFireEvent(listener, event);
- }
- return true;
- }
- }
-
- public boolean removeWebAppListener(WebAppListener listener)
- {
- synchronized (lock)
- {
- if (listener == null)
- {
- throw new IllegalArgumentException();
- }
- if (listeners.remove(listener))
- {
- for (Iterator i = webAppMap.values().iterator(); i.hasNext();)
- {
- WebApp webApp = (WebApp)i.next();
- WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED);
- safeFireEvent(listener, event);
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
- private void safeFireEvent(WebAppListener listener, WebAppEvent event)
- {
- try
- {
- listener.onEvent(event);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- private void fireEvent(WebAppEvent event)
- {
- for (Iterator i = listeners.iterator(); i.hasNext();)
- {
- safeFireEvent((WebAppListener)i.next(), event);
- }
- }
-
- /**
* Generic detyped request dispatch to a servlet context using the include mechanism.
*
* @param targetServletContext the target servlet context to dispatch to
* @param request the request valid in the current servlet context
* @param response the response valid in the current servlet context
* @param callback the callback to perform after the dispatch operation
- * @param handback the handback object to provide
- * @return any object
- * @throws Exception any exception
+ * @param handback the handback object that will be provided to the
callback
+ * @return the object returned by the callback
+ * @throws ServletException any servlet exception
+ * @throws IOException any io exception
*/
public Object include(
- ServletContext targetServletContext, HttpServletRequest request,
+ ServletContext targetServletContext,
+ HttpServletRequest request,
HttpServletResponse response,
RequestDispatchCallback callback,
- Object handback) throws ServletException, IOException
- {
- RegistrationImpl registration = this.registration;
-
- //
- if (registration == null)
- {
- throw new IllegalStateException("No SPI installed");
- }
-
- //
- return registration.context.include(targetServletContext, request, response,
callback, handback);
- }
-
- private static class RegistrationImpl implements ServletContainerContext.Registration
- {
-
- /** . */
- private boolean disposed;
-
- /** . */
- private ServletContainer container;
-
- /** . */
- private ServletContainerContext context;
-
- public RegistrationImpl(ServletContainer container, ServletContainerContext
context)
- {
- this.disposed = false;
- this.container = container;
- this.context = context;
- }
-
- public boolean registerWebApp(WebAppContext webAppContext)
- {
- if (disposed)
- {
- throw new IllegalStateException("Disposed registration");
- }
- synchronized (container.lock)
- {
- if (webAppContext == null)
- {
- throw new IllegalArgumentException("No null web app context
accepted");
- }
-
- //
- String key = webAppContext.getContextPath();
-
- //
- if (container.webAppMap.containsKey(key))
- {
- log.debug("Web application " + key + " is already
registered");
- return false;
- }
- else
- {
- try
- {
- log.debug("Web application " + key + "
registration");
- webAppContext.start();
- WebAppImpl webApp = new WebAppImpl(webAppContext);
- container.webAppMap.put(key, webApp);
- container.fireEvent(new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.ADDED));
- return true;
- }
- catch (Exception e)
- {
- log.debug("Was not able to start web app context " + key);
- e.printStackTrace();
- return false;
- }
- }
- }
- }
-
- public boolean unregisterWebApp(String webAppId)
- {
- if (disposed)
- {
- throw new IllegalStateException("Disposed registration");
- }
- synchronized (container.lock)
- {
- if (webAppId == null)
- {
- throw new IllegalArgumentException("No null web app id
accepted");
- }
-
- //
- WebAppImpl webApp = (WebAppImpl)container.webAppMap.remove(webAppId);
- if (webApp != null)
- {
- log.debug("Web application " + webAppId + "
cleanup");
- container.fireEvent(new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED));
- webApp.context.stop();
- return true;
- }
- else
- {
- log.debug("Web application " + webAppId + " was not
registered");
- return false;
- }
- }
- }
-
- public void cancel()
- {
- if (disposed)
- {
- throw new IllegalStateException("Disposed registration");
- }
- synchronized (container.lock)
- {
- // Unregister all web apps
- for (Iterator i = container.webAppMap.values().iterator(); i.hasNext();)
- {
- WebApp webApp = (WebApp)i.next();
- WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED);
- container.fireEvent(event);
- }
-
- //
- container.webAppMap.clear();
-
- // Uninstall the call back
- try
- {
- context.unsetCallback(this);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- // Update state
- context = null;
- disposed = true;
- container.registration = null;
- }
- }
- }
-
- /** Implementation of the <code>WebApp</code> interface. */
- private static class WebAppImpl implements WebApp
- {
-
- /** . */
- final WebAppContext context;
-
- public WebAppImpl(WebAppContext context)
- {
- this.context = context;
- }
-
- public ServletContext getServletContext()
- {
- return context.getServletContext();
- }
-
- public ClassLoader getClassLoader()
- {
- return context.getClassLoader();
- }
-
- public String getContextPath()
- {
- return context.getContextPath();
- }
-
- public boolean importFile(String parentDirRelativePath, String name, InputStream
source, boolean overwrite) throws IOException
- {
- return context.importFile(parentDirRelativePath, name, source, overwrite);
- }
- }
+ Object handback) throws ServletException, IOException;
}
Modified:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContextDispatcher.java
===================================================================
---
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContextDispatcher.java 2008-03-07
18:11:53 UTC (rev 10239)
+++
modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContextDispatcher.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -30,7 +30,7 @@
/**
* Encapsulate dispatch functionnality into a single class so it is easy to
- * pass it as an argment to a framework that neeeds a dispatcher to just a
+ * pass it as an argment to a framework that needs a dispatcher to just a
* servlet context and does not care about the underlying spi or request/response.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -50,6 +50,20 @@
public ServletContextDispatcher(HttpServletRequest request, HttpServletResponse
response, ServletContainer servletContainer)
{
+ if (request == null)
+ {
+ throw new IllegalArgumentException("No null request allowed");
+ }
+ if (response == null)
+ {
+ throw new IllegalArgumentException("No null response allowed");
+ }
+ if (servletContainer == null)
+ {
+ throw new IllegalArgumentException("No null servlet container
allowed");
+ }
+
+ //
this.request = request;
this.response = response;
this.servletContainer = servletContainer;
@@ -72,5 +86,4 @@
{
return servletContainer.include(targetServletContext, request, response, callback,
handback);
}
-
}
Added:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainer.java
===================================================================
---
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainer.java
(rev 0)
+++
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainer.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -0,0 +1,353 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.jboss.portal.web.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.web.spi.ServletContainerContext;
+import org.jboss.portal.web.spi.WebAppContext;
+import org.jboss.portal.web.WebAppListener;
+import org.jboss.portal.web.WebApp;
+import org.jboss.portal.web.WebAppLifeCycleEvent;
+import org.jboss.portal.web.WebAppEvent;
+import org.jboss.portal.web.RequestDispatchCallback;
+import org.jboss.portal.web.ServletContainer;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A static registry for the servlet container context.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultServletContainer implements ServletContainer
+{
+ private final static Logger log = Logger.getLogger(ServletContainer.class);
+
+ /** . */
+ private final Object lock = new Object();
+
+ /** The event listeners. */
+ private final ArrayList<WebAppListener> listeners = new
ArrayList<WebAppListener>();
+
+ /** The web applications. */
+ private final Map<String, WebAppImpl> webAppMap = new HashMap<String,
WebAppImpl>();
+
+ /** The callback. */
+ private RegistrationImpl registration;
+
+ /**
+ * Register a servlet container context. The registration is considered as successful
if no existing context is
+ * already registered.
+ *
+ * @param context the servlet container context to register
+ * @throws IllegalArgumentException if the context is null
+ */
+ public void register(ServletContainerContext context)
+ {
+ synchronized (lock)
+ {
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ if (registration == null)
+ {
+
+ registration = new RegistrationImpl(this, context);
+
+ // Installs the call back
+ context.setCallback(registration);
+ }
+ }
+ }
+
+ public boolean addWebAppListener(WebAppListener listener)
+ {
+ synchronized (lock)
+ {
+ if (listener == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (listeners.contains(listener))
+ {
+ return false;
+ }
+ listeners.add(listener);
+ for (Object response : webAppMap.values())
+ {
+ WebApp webApp = (WebApp)response;
+ WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.ADDED);
+ safeFireEvent(listener, event);
+ }
+ return true;
+ }
+ }
+
+ public boolean removeWebAppListener(WebAppListener listener)
+ {
+ synchronized (lock)
+ {
+ if (listener == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (listeners.remove(listener))
+ {
+ for (WebApp webApp : webAppMap.values())
+ {
+ WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED);
+ safeFireEvent(listener, event);
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ private void safeFireEvent(WebAppListener listener, WebAppEvent event)
+ {
+ try
+ {
+ listener.onEvent(event);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void fireEvent(WebAppEvent event)
+ {
+ for (WebAppListener listener : listeners)
+ {
+ safeFireEvent(listener, event);
+ }
+ }
+
+ /**
+ * Generic detyped request dispatch to a servlet context using the include mechanism.
+ *
+ * @param targetServletContext the target servlet context to dispatch to
+ * @param request the request valid in the current servlet context
+ * @param response the response valid in the current servlet context
+ * @param callback the callback to perform after the dispatch operation
+ * @param handback the handback object that will be provided to the
callback
+ * @return the object returned by the callback
+ * @throws javax.servlet.ServletException any servlet exception
+ * @throws java.io.IOException any io exception
+ */
+ public Object include(
+ ServletContext targetServletContext,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ RequestDispatchCallback callback,
+ Object handback) throws ServletException, IOException
+ {
+ RegistrationImpl registration = this.registration;
+
+ //
+ if (registration == null)
+ {
+ throw new IllegalStateException("No SPI installed");
+ }
+
+ //
+ return registration.context.include(targetServletContext, request, response,
callback, handback);
+ }
+
+ private static class RegistrationImpl implements ServletContainerContext.Registration
+ {
+
+ /** . */
+ private boolean disposed;
+
+ /** . */
+ private DefaultServletContainer container;
+
+ /** . */
+ private ServletContainerContext context;
+
+ public RegistrationImpl(DefaultServletContainer container, ServletContainerContext
context)
+ {
+ this.disposed = false;
+ this.container = container;
+ this.context = context;
+ }
+
+ public boolean registerWebApp(WebAppContext webAppContext)
+ {
+ if (disposed)
+ {
+ throw new IllegalStateException("Disposed registration");
+ }
+ synchronized (container.lock)
+ {
+ if (webAppContext == null)
+ {
+ throw new IllegalArgumentException("No null web app context
accepted");
+ }
+
+ //
+ String key = webAppContext.getContextPath();
+
+ //
+ if (container.webAppMap.containsKey(key))
+ {
+ log.debug("Web application " + key + " is already
registered");
+ return false;
+ }
+ else
+ {
+ try
+ {
+ log.debug("Web application " + key + "
registration");
+ webAppContext.start();
+ WebAppImpl webApp = new WebAppImpl(webAppContext);
+ container.webAppMap.put(key, webApp);
+ container.fireEvent(new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.ADDED));
+ return true;
+ }
+ catch (Exception e)
+ {
+ log.debug("Was not able to start web app context " + key);
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ }
+
+ public boolean unregisterWebApp(String webAppId)
+ {
+ if (disposed)
+ {
+ throw new IllegalStateException("Disposed registration");
+ }
+ synchronized (container.lock)
+ {
+ if (webAppId == null)
+ {
+ throw new IllegalArgumentException("No null web app id
accepted");
+ }
+
+ //
+ WebAppImpl webApp = container.webAppMap.remove(webAppId);
+ if (webApp != null)
+ {
+ log.debug("Web application " + webAppId + "
cleanup");
+ container.fireEvent(new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED));
+ webApp.context.stop();
+ return true;
+ }
+ else
+ {
+ log.debug("Web application " + webAppId + " was not
registered");
+ return false;
+ }
+ }
+ }
+
+ public void cancel()
+ {
+ if (disposed)
+ {
+ throw new IllegalStateException("Disposed registration");
+ }
+ synchronized (container.lock)
+ {
+ // Unregister all web apps
+ for (WebApp webApp : container.webAppMap.values())
+ {
+ WebAppLifeCycleEvent event = new WebAppLifeCycleEvent(webApp,
WebAppLifeCycleEvent.REMOVED);
+ container.fireEvent(event);
+ }
+
+ //
+ container.webAppMap.clear();
+
+ // Uninstall the call back
+ try
+ {
+ context.unsetCallback(this);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ // Update state
+ context = null;
+ disposed = true;
+ container.registration = null;
+ }
+ }
+ }
+
+ /** Implementation of the <code>WebApp</code> interface. */
+ private static class WebAppImpl implements WebApp
+ {
+
+ /** . */
+ final WebAppContext context;
+
+ public WebAppImpl(WebAppContext context)
+ {
+ this.context = context;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return context.getServletContext();
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return context.getClassLoader();
+ }
+
+ public String getContextPath()
+ {
+ return context.getContextPath();
+ }
+
+ public boolean importFile(String parentDirRelativePath, String name, InputStream
source, boolean overwrite) throws IOException
+ {
+ return context.importFile(parentDirRelativePath, name, source, overwrite);
+ }
+ }
+}
\ No newline at end of file
Modified:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainerFactory.java
===================================================================
---
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainerFactory.java 2008-03-07
18:11:53 UTC (rev 10239)
+++
modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultServletContainerFactory.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -42,7 +42,7 @@
}
/** . */
- private final ServletContainer container = new ServletContainer();
+ private final DefaultServletContainer container = new DefaultServletContainer();
/**
* Returns the singleton instance.
@@ -55,7 +55,11 @@
}
/**
- * Register the context argument on the singleton instance.
+ * Registers a servlet container context. The registration is considered as successful
if no existing context is
+ * already registered.
+ *
+ * @param context the servlet container context to register
+ * @throws IllegalArgumentException if the context is null
*/
public static void registerContext(ServletContainerContext context) throws
IllegalArgumentException
{
Modified:
modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletContainerContext.java
===================================================================
---
modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletContainerContext.java 2008-03-07
18:11:53 UTC (rev 10239)
+++
modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletContainerContext.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -48,9 +48,10 @@
* @param request the request valid in the current servlet context
* @param response the response valid in the current servlet context
* @param callback the callback to perform after the dispatch operation
- * @param handback the handback object to provide
- * @return any object
- * @throws Exception any exception
+ * @param handback the handback object that will be provided to the callback
+ * @return the object returned by the callback
+ * @throws ServletException any servlet exception
+ * @throws IOException any io exception
*/
Object include(
ServletContext targetServletContext, HttpServletRequest request,
Modified:
modules/web/trunk/web/src/test/java/org/jboss/portal/test/web/container/ServletContainerTestCase.java
===================================================================
---
modules/web/trunk/web/src/test/java/org/jboss/portal/test/web/container/ServletContainerTestCase.java 2008-03-07
18:11:53 UTC (rev 10239)
+++
modules/web/trunk/web/src/test/java/org/jboss/portal/test/web/container/ServletContainerTestCase.java 2008-03-08
19:18:46 UTC (rev 10240)
@@ -22,11 +22,10 @@
******************************************************************************/
package org.jboss.portal.test.web.container;
-import org.jboss.portal.web.ServletContainer;
import org.jboss.portal.web.WebAppListener;
import org.jboss.portal.web.WebAppEvent;
+import org.jboss.portal.web.impl.DefaultServletContainer;
import org.jboss.portal.web.spi.ServletContainerContext;
-import org.jboss.portal.common.util.CollectionBuilder;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.test.web.WebAppRegistry;
import org.jboss.unit.api.pojo.annotations.Test;
@@ -45,7 +44,7 @@
@Test
public void testContextRegistrationLifeCycle()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc = new ServletContainerContextImpl();
//
@@ -69,7 +68,7 @@
registration.registerWebApp(new WebAppContextImpl("/foo"));
fail("Was expecting an ISE");
}
- catch (IllegalStateException e)
+ catch (IllegalStateException ignore)
{
}
try
@@ -77,7 +76,7 @@
registration.unregisterWebApp("/blah");
fail("Was expecting an ISE");
}
- catch (IllegalStateException e)
+ catch (IllegalStateException ignore)
{
}
try
@@ -85,7 +84,7 @@
registration.cancel();
fail("Was expecting an ISE");
}
- catch (IllegalStateException e)
+ catch (IllegalStateException ignore)
{
}
}
@@ -93,7 +92,7 @@
@Test
public void testConcurrentContextRegistrations()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc1 = new ServletContainerContextImpl();
ServletContainerContextImpl scc2 = new ServletContainerContextImpl();
@@ -122,7 +121,7 @@
@Test
public void testContextRegistrationCancellationUnregistersWebApps()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc = new ServletContainerContextImpl();
WebAppRegistry registry = new WebAppRegistry();
@@ -135,17 +134,17 @@
//
scc.registration.registerWebApp(new WebAppContextImpl("/foo"));
scc.registration.registerWebApp(new WebAppContextImpl("/bar"));
- assertEquals(Tools.toSet(new String[]{"/foo", "/bar"}),
registry.getKeys());
+ assertEquals(Tools.toSet("/foo", "/bar"), registry.getKeys());
//
scc.registration.cancel();
- assertEquals(Tools.toSet(new String[]{}), registry.getKeys());
+ assertEquals(Tools.toSet(), registry.getKeys());
}
@Test
public void testListenerDoubleRegistration()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc = new ServletContainerContextImpl();
WebAppRegistry registry = new WebAppRegistry();
@@ -156,25 +155,25 @@
//
container.register(scc);
scc.registration.registerWebApp(new WebAppContextImpl("/foo"));
- assertEquals(Tools.toSet(new String[]{"/foo"}), registry.getKeys());
+ assertEquals(Tools.toSet("/foo"), registry.getKeys());
//
container.addWebAppListener(registry);
- assertEquals(Tools.toSet(new String[]{"/foo"}), registry.getKeys());
+ assertEquals(Tools.toSet("/foo"), registry.getKeys());
//
container.removeWebAppListener(registry);
- assertEquals(Tools.toSet(new String[]{}), registry.getKeys());
+ assertEquals(Tools.toSet(), registry.getKeys());
//
container.removeWebAppListener(registry);
- assertEquals(Tools.toSet(new String[]{}), registry.getKeys());
+ assertEquals(Tools.toSet(), registry.getKeys());
}
@Test
public void testListenerIsNotified()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc = new ServletContainerContextImpl();
WebAppRegistry registry = new WebAppRegistry();
@@ -189,43 +188,43 @@
container.addWebAppListener(registry);
// Assert we received events during the registration
- assertEquals(Tools.toSet(new String[]{"/foo", "/bar"}),
registry.getKeys());
+ assertEquals(Tools.toSet("/foo", "/bar"), registry.getKeys());
// Add a new web app
scc.registration.registerWebApp(new WebAppContextImpl("/juu"));
// Assert we now have 3 web apps
- assertEquals(Tools.toSet(new String[]{"/foo", "/bar",
"/juu"}), registry.getKeys());
+ assertEquals(Tools.toSet("/foo", "/bar", "/juu"),
registry.getKeys());
// Remove one web app
scc.registration.unregisterWebApp("/foo");
// Assert we have 2 web apps
- assertEquals(Tools.toSet(new String[]{"/bar", "/juu"}),
registry.getKeys());
+ assertEquals(Tools.toSet("/bar", "/juu"), registry.getKeys());
// Remove registration
container.removeWebAppListener(registry);
// Assert we receveived events during removal
- assertEquals(Tools.toSet(new String[]{}), registry.getKeys());
+ assertEquals(Tools.toSet(), registry.getKeys());
// W Add a new web app
scc.registration.registerWebApp(new WebAppContextImpl("/foo"));
// hen unregistered, a new web app registration does not send event
- assertEquals(Tools.toSet(new String[]{}), registry.getKeys());
+ assertEquals(Tools.toSet(), registry.getKeys());
}
@Test
public void testServletContainerThrowsIAE()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
try
{
container.register(null);
fail("Was expecting an IAE");
}
- catch (IllegalArgumentException expected)
+ catch (IllegalArgumentException ignore)
{
}
try
@@ -233,7 +232,7 @@
container.addWebAppListener(null);
fail("Was expecting an IAE");
}
- catch (IllegalArgumentException expected)
+ catch (IllegalArgumentException ignore)
{
}
try
@@ -241,7 +240,7 @@
container.removeWebAppListener(null);
fail("Was expecting an IAE");
}
- catch (IllegalArgumentException expected)
+ catch (IllegalArgumentException ignore)
{
}
}
@@ -249,13 +248,13 @@
@Test
public void testServletContainerThrowsISE() throws Exception
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
try
{
container.include(null, null, null, null, null);
fail("Was expecting an ISE");
}
- catch (IllegalStateException expected)
+ catch (IllegalStateException ignore)
{
}
}
@@ -263,7 +262,7 @@
@Test
public void testListenerFailure()
{
- ServletContainer container = new ServletContainer();
+ DefaultServletContainer container = new DefaultServletContainer();
ServletContainerContextImpl scc = new ServletContainerContextImpl();
WebAppRegistry registry = new WebAppRegistry();
@@ -283,6 +282,6 @@
//
scc.registration.registerWebApp(new WebAppContextImpl("/foo"));
assertTrue(called.get());
- assertEquals(Tools.toSet(new String[]{"/foo"}), registry.getKeys());
+ assertEquals(Tools.toSet("/foo"), registry.getKeys());
}
}