[Httpunit-commit] CVS: httpunit/src/com/meterware/servletunit ServletRunner.java,1.22,1.23 WebApplic
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-02-13 03:23:07
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20086/src/com/meterware/servletunit Modified Files: ServletRunner.java WebApplication.java Log Message: Patch #890936 - Jay Dunning added ServletContextListener support Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ServletRunner.java 17 Jun 2003 11:17:45 -0000 1.22 +++ ServletRunner.java 13 Feb 2004 03:17:46 -0000 1.23 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2003, Russell Gold +* Copyright (c) 2000-2004, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -142,10 +142,11 @@ /** * Shuts down the servlet container, returning any resources held by it. - * Calls the destroy method of each active servlet. + * Calls the destroy method of each active servlet, then notifies + * ContextListeners of server shutdown. */ public void shutDown() { - _application.destroyServlets(); + _application.shutDown(); } Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebApplication.java 27 Feb 2003 13:33:45 -0000 1.19 +++ WebApplication.java 13 Feb 2004 03:17:46 -0000 1.20 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * - * Copyright (c) 2001-2003, Russell Gold + * Copyright (c) 2001-2004, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -28,9 +28,7 @@ import java.net.URL; import java.util.*; -import javax.servlet.Servlet; -import javax.servlet.ServletException; -import javax.servlet.ServletContext; +import javax.servlet.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -48,6 +46,7 @@ * * @author <a href="mailto:rus...@ht...">Russell Gold</a> * @author <a href="ba...@we...">Donald Ball</a> + * @author <a href="jay...@us...">Jay Dunning</a> **/ class WebApplication { @@ -62,6 +61,8 @@ private ArrayList _securityConstraints = new ArrayList(); + private ArrayList _contextListeners = new ArrayList(); + private boolean _useBasicAuthentication; private boolean _useFormAuthentication; @@ -116,10 +117,54 @@ extractSecurityConstraints( document ); extractContextParameters( document ); extractLoginConfiguration( document ); + extractContextListeners( document ); + notifyContextInitialized(); _servletMapping.autoLoadServlets(); } + private void extractContextListeners( Document document ) throws SAXException { + ServletContextListener listener; + NodeList nl = document.getElementsByTagName( "listener" ); + for (int i = 0; i < nl.getLength(); i++) { + String listenerName = getChildNodeValue((Element) nl.item(i), "listener-class").trim(); + try { + listener = (ServletContextListener) Class.forName(listenerName).newInstance(); + } catch (Exception x) { + throw new RuntimeException("Unable to load context listener " + listenerName, x); + } catch (Error x) { + throw new RuntimeException("Unable to load context listener " + listenerName, x); + } + _contextListeners.add(listener); + } + } + + private void notifyContextInitialized() { + ServletContextEvent event = new ServletContextEvent( getServletContext() ); + + for (Iterator i = _contextListeners.iterator(); i.hasNext();) { + ServletContextListener listener = (ServletContextListener) i.next(); + listener.contextInitialized( event ); + } + } + + + void shutDown() { + destroyServlets(); + notifyContextDestroyed(); + } + + + private void notifyContextDestroyed() { + ServletContextEvent event = new ServletContextEvent( getServletContext() ); + + for (ListIterator i = _contextListeners.listIterator( _contextListeners.size() ); i.hasPrevious();) { + ServletContextListener listener = (ServletContextListener) i.previous(); + listener.contextDestroyed( event ); + } + } + + private void extractSecurityConstraints( Document document ) throws SAXException { NodeList nl = document.getElementsByTagName( "security-constraint" ); for (int i = 0; i < nl.getLength(); i++) { |