From portal-commits at lists.jboss.org Sat Mar 8 14:18:47 2008 Content-Type: multipart/mixed; boundary="===============5756772933291564123==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r10240 - in modules/web/trunk/web/src: main/java/org/jboss/portal/web/impl and 2 other directories. Date: Sat, 08 Mar 2008 14:18:47 -0500 Message-ID: --===============5756772933291564123== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/DefaultSer= vletContainer.java Modified: modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContaine= r.java modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContextD= ispatcher.java modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultSer= vletContainerFactory.java modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletCont= ainerContext.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/ServletC= ontainer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContain= er.java 2008-03-07 18:11:53 UTC (rev 10239) +++ modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContain= er.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 Julien Viet * @version $Revision: 1.1 $ */ -public class ServletContainer +public interface ServletContainer { - private final static Logger log =3D Logger.getLogger(ServletContainer.c= lass); = - /** . */ - private final Object lock =3D new Object(); + boolean addWebAppListener(WebAppListener listener); = - /** The event listeners. */ - private final ArrayList listeners =3D new ArrayList(); + boolean removeWebAppListener(WebAppListener listener); = - /** The web applications. */ - private final Map webAppMap =3D 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 =3D=3D null) - { - throw new IllegalArgumentException("No null context accepted"); - } - - // - if (registration =3D=3D null) - { - - registration =3D new RegistrationImpl(this, context); - - // Installs the call back - context.setCallback(registration); - } - } - } - - public boolean addWebAppListener(WebAppListener listener) - { - synchronized (lock) - { - if (listener =3D=3D null) - { - throw new IllegalArgumentException(); - } - if (listeners.contains(listener)) - { - return false; - } - listeners.add(listener); - for (Iterator i =3D webAppMap.values().iterator(); i.hasNext();) - { - WebApp webApp =3D (WebApp)i.next(); - WebAppLifeCycleEvent event =3D new WebAppLifeCycleEvent(webApp= , WebAppLifeCycleEvent.ADDED); - safeFireEvent(listener, event); - } - return true; - } - } - - public boolean removeWebAppListener(WebAppListener listener) - { - synchronized (lock) - { - if (listener =3D=3D null) - { - throw new IllegalArgumentException(); - } - if (listeners.remove(listener)) - { - for (Iterator i =3D webAppMap.values().iterator(); i.hasNext()= ;) - { - WebApp webApp =3D (WebApp)i.next(); - WebAppLifeCycleEvent event =3D new WebAppLifeCycleEvent(web= App, 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 =3D listeners.iterator(); i.hasNext();) - { - safeFireEvent((WebAppListener)i.next(), event); - } - } - - /** * Generic detyped request dispatch to a servlet context using the incl= ude 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 servle= t context * @param callback the callback to perform after the dispat= ch operation - * @param handback the handback object to provide - * @return any object - * @throws Exception any exception + * @param handback the handback object that will be provide= d 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 =3D this.registration; - - // - if (registration =3D=3D null) - { - throw new IllegalStateException("No SPI installed"); - } - - // - return registration.context.include(targetServletContext, request, r= esponse, callback, handback); - } - - private static class RegistrationImpl implements ServletContainerContex= t.Registration - { - - /** . */ - private boolean disposed; - - /** . */ - private ServletContainer container; - - /** . */ - private ServletContainerContext context; - - public RegistrationImpl(ServletContainer container, ServletContainer= Context context) - { - this.disposed =3D false; - this.container =3D container; - this.context =3D context; - } - - public boolean registerWebApp(WebAppContext webAppContext) - { - if (disposed) - { - throw new IllegalStateException("Disposed registration"); - } - synchronized (container.lock) - { - if (webAppContext =3D=3D null) - { - throw new IllegalArgumentException("No null web app context= accepted"); - } - - // - String key =3D webAppContext.getContextPath(); - - // - if (container.webAppMap.containsKey(key)) - { - log.debug("Web application " + key + " is already registere= d"); - return false; - } - else - { - try - { - log.debug("Web application " + key + " registration"); - webAppContext.start(); - WebAppImpl webApp =3D new WebAppImpl(webAppContext); - container.webAppMap.put(key, webApp); - container.fireEvent(new WebAppLifeCycleEvent(webApp, Web= AppLifeCycleEvent.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 =3D=3D null) - { - throw new IllegalArgumentException("No null web app id acce= pted"); - } - - // - WebAppImpl webApp =3D (WebAppImpl)container.webAppMap.remove(w= ebAppId); - if (webApp !=3D null) - { - log.debug("Web application " + webAppId + " cleanup"); - container.fireEvent(new WebAppLifeCycleEvent(webApp, WebApp= LifeCycleEvent.REMOVED)); - webApp.context.stop(); - return true; - } - else - { - log.debug("Web application " + webAppId + " was not registe= red"); - return false; - } - } - } - - public void cancel() - { - if (disposed) - { - throw new IllegalStateException("Disposed registration"); - } - synchronized (container.lock) - { - // Unregister all web apps - for (Iterator i =3D container.webAppMap.values().iterator(); i= .hasNext();) - { - WebApp webApp =3D (WebApp)i.next(); - WebAppLifeCycleEvent event =3D new WebAppLifeCycleEvent(web= App, WebAppLifeCycleEvent.REMOVED); - container.fireEvent(event); - } - - // - container.webAppMap.clear(); - - // Uninstall the call back - try - { - context.unsetCallback(this); - } - catch (Exception e) - { - e.printStackTrace(); - } - - // Update state - context =3D null; - disposed =3D true; - container.registration =3D null; - } - } - } - - /** Implementation of the WebApp interface. */ - private static class WebAppImpl implements WebApp - { - - /** . */ - final WebAppContext context; - - public WebAppImpl(WebAppContext context) - { - this.context =3D 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, ov= erwrite); - } - } + Object handback) throws ServletException, IOException; } Modified: modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletC= ontextDispatcher.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContext= Dispatcher.java 2008-03-07 18:11:53 UTC (rev 10239) +++ modules/web/trunk/web/src/main/java/org/jboss/portal/web/ServletContext= Dispatcher.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/r= esponse. * * @author Julien Viet @@ -50,6 +50,20 @@ = public ServletContextDispatcher(HttpServletRequest request, HttpServlet= Response response, ServletContainer servletContainer) { + if (request =3D=3D null) + { + throw new IllegalArgumentException("No null request allowed"); + } + if (response =3D=3D null) + { + throw new IllegalArgumentException("No null response allowed"); + } + if (servletContainer =3D=3D null) + { + throw new IllegalArgumentException("No null servlet container all= owed"); + } + + // this.request =3D request; this.response =3D response; this.servletContainer =3D servletContainer; @@ -72,5 +86,4 @@ { return servletContainer.include(targetServletContext, request, respo= nse, callback, handback); } - = } Added: modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/Defaul= tServletContainer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultSe= rvletContainer.java (rev 0) +++ modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultSe= rvletContainer.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 Julien Viet + * @version $Revision: 1.1 $ + */ +public class DefaultServletContainer implements ServletContainer +{ + private final static Logger log =3D Logger.getLogger(ServletContainer.c= lass); + + /** . */ + private final Object lock =3D new Object(); + + /** The event listeners. */ + private final ArrayList listeners =3D new ArrayList(); + + /** The web applications. */ + private final Map webAppMap =3D 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 =3D=3D null) + { + throw new IllegalArgumentException("No null context accepted"); + } + + // + if (registration =3D=3D null) + { + + registration =3D new RegistrationImpl(this, context); + + // Installs the call back + context.setCallback(registration); + } + } + } + + public boolean addWebAppListener(WebAppListener listener) + { + synchronized (lock) + { + if (listener =3D=3D null) + { + throw new IllegalArgumentException(); + } + if (listeners.contains(listener)) + { + return false; + } + listeners.add(listener); + for (Object response : webAppMap.values()) + { + WebApp webApp =3D (WebApp)response; + WebAppLifeCycleEvent event =3D new WebAppLifeCycleEvent(webApp= , WebAppLifeCycleEvent.ADDED); + safeFireEvent(listener, event); + } + return true; + } + } + + public boolean removeWebAppListener(WebAppListener listener) + { + synchronized (lock) + { + if (listener =3D=3D null) + { + throw new IllegalArgumentException(); + } + if (listeners.remove(listener)) + { + for (WebApp webApp : webAppMap.values()) + { + WebAppLifeCycleEvent event =3D new WebAppLifeCycleEvent(web= App, 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 incl= ude 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 servle= t context + * @param callback the callback to perform after the dispat= ch operation + * @param handback the handback object that will be provide= d 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 =3D this.registration; + + // + if (registration =3D=3D null) + { + throw new IllegalStateException("No SPI installed"); + } + + // + return registration.context.include(targetServletContext, request, r= esponse, callback, handback); + } + + private static class RegistrationImpl implements ServletContainerContex= t.Registration + { + + /** . */ + private boolean disposed; + + /** . */ + private DefaultServletContainer container; + + /** . */ + private ServletContainerContext context; + + public RegistrationImpl(DefaultServletContainer container, ServletCo= ntainerContext context) + { + this.disposed =3D false; + this.container =3D container; + this.context =3D context; + } + + public boolean registerWebApp(WebAppContext webAppContext) + { + if (disposed) + { + throw new IllegalStateException("Disposed registration"); + } + synchronized (container.lock) + { + if (webAppContext =3D=3D null) + { + throw new IllegalArgumentException("No null web app context= accepted"); + } + + // + String key =3D webAppContext.getContextPath(); + + // + if (container.webAppMap.containsKey(key)) + { + log.debug("Web application " + key + " is already registere= d"); + return false; + } + else + { + try + { + log.debug("Web application " + key + " registration"); + webAppContext.start(); + WebAppImpl webApp =3D new WebAppImpl(webAppContext); + container.webAppMap.put(key, webApp); + container.fireEvent(new WebAppLifeCycleEvent(webApp, Web= AppLifeCycleEvent.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 =3D=3D null) + { + throw new IllegalArgumentException("No null web app id acce= pted"); + } + + // + WebAppImpl webApp =3D container.webAppMap.remove(webAppId); + if (webApp !=3D null) + { + log.debug("Web application " + webAppId + " cleanup"); + container.fireEvent(new WebAppLifeCycleEvent(webApp, WebApp= LifeCycleEvent.REMOVED)); + webApp.context.stop(); + return true; + } + else + { + log.debug("Web application " + webAppId + " was not registe= red"); + 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 =3D new WebAppLifeCycleEvent(web= App, WebAppLifeCycleEvent.REMOVED); + container.fireEvent(event); + } + + // + container.webAppMap.clear(); + + // Uninstall the call back + try + { + context.unsetCallback(this); + } + catch (Exception e) + { + e.printStackTrace(); + } + + // Update state + context =3D null; + disposed =3D true; + container.registration =3D null; + } + } + } + + /** Implementation of the WebApp interface. */ + private static class WebAppImpl implements WebApp + { + + /** . */ + final WebAppContext context; + + public WebAppImpl(WebAppContext context) + { + this.context =3D 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, ov= erwrite); + } + } +} \ No newline at end of file Modified: modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/Def= aultServletContainerFactory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultSe= rvletContainerFactory.java 2008-03-07 18:11:53 UTC (rev 10239) +++ modules/web/trunk/web/src/main/java/org/jboss/portal/web/impl/DefaultSe= rvletContainerFactory.java 2008-03-08 19:18:46 UTC (rev 10240) @@ -42,7 +42,7 @@ } = /** . */ - private final ServletContainer container =3D new ServletContainer(); + private final DefaultServletContainer container =3D new DefaultServletC= ontainer(); = /** * Returns the singleton instance. @@ -55,7 +55,11 @@ } = /** - * Register the context argument on the singleton instance. + * Registers a servlet container context. The registration is considere= d 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) thr= ows IllegalArgumentException { Modified: modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/Serv= letContainerContext.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletCon= tainerContext.java 2008-03-07 18:11:53 UTC (rev 10239) +++ modules/web/trunk/web/src/main/java/org/jboss/portal/web/spi/ServletCon= tainerContext.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 cal= lback + * @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/con= tainer/ServletContainerTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc =3D 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 =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc1 =3D new ServletContainerContextImpl= (); ServletContainerContextImpl scc2 =3D new ServletContainerContextImpl= (); = @@ -122,7 +121,7 @@ @Test public void testContextRegistrationCancellationUnregistersWebApps() { - ServletContainer container =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc =3D new ServletContainerContextImpl(= ); WebAppRegistry registry =3D 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.get= Keys()); + 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 =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc =3D new ServletContainerContextImpl(= ); WebAppRegistry registry =3D 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 =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc =3D new ServletContainerContextImpl(= ); WebAppRegistry registry =3D new WebAppRegistry(); = @@ -189,43 +188,43 @@ container.addWebAppListener(registry); = // Assert we received events during the registration - assertEquals(Tools.toSet(new String[]{"/foo", "/bar"}), registry.get= Keys()); + 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"}), regi= stry.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.get= Keys()); + 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 =3D new ServletContainer(); + DefaultServletContainer container =3D 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 =3D new ServletContainer(); + DefaultServletContainer container =3D 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 =3D new ServletContainer(); + DefaultServletContainer container =3D new DefaultServletContainer(); ServletContainerContextImpl scc =3D new ServletContainerContextImpl(= ); WebAppRegistry registry =3D 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()); } } --===============5756772933291564123==--