[Httpunit-commit] CVS: httpunit/src/com/meterware/servletunit ServletRunner.java,1.19,1.20 ServletUn
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-01-03 16:12:37
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18497/src/com/meterware/servletunit
Modified Files:
ServletRunner.java ServletUnitHttpRequest.java
WebApplication.java
Log Message:
miscellaneous servletunit enhancments
Index: ServletRunner.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ServletRunner.java 17 Oct 2002 23:50:49 -0000 1.19
+++ ServletRunner.java 3 Jan 2003 16:12:35 -0000 1.20
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -23,14 +23,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.net.URL;
import java.util.Dictionary;
import java.util.Hashtable;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-
import com.meterware.httpunit.HttpUnitUtils;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
@@ -41,6 +36,8 @@
/**
* This class acts as a test environment for servlets.
+ *
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class ServletRunner {
@@ -131,6 +128,15 @@
**/
public WebResponse getResponse( String url ) throws MalformedURLException, IOException, SAXException {
return getClient().getResponse( url );
+ }
+
+
+ /**
+ * Shuts down the servlet container, returning any resources held by it.
+ * Calls the destroy method of each active servlet.
+ */
+ public void shutDown() {
+ _application.destroyServlets();
}
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ServletUnitHttpRequest.java 3 Nov 2002 22:44:13 -0000 1.18
+++ ServletUnitHttpRequest.java 3 Jan 2003 16:12:35 -0000 1.19
@@ -148,7 +148,7 @@
* in which case this method returns null.
**/
public Enumeration getHeaderNames() {
- return null;
+ return _headers.keys();
}
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- WebApplication.java 21 Oct 2002 13:34:19 -0000 1.15
+++ WebApplication.java 3 Jan 2003 16:12:35 -0000 1.16
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001-2002, Russell Gold
+ * Copyright (c) 2001-2003, 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
@@ -50,7 +50,7 @@
* This class represents the information recorded about a single web
* application. It is usually extracted from web.xml.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author <a href="ba...@we...">Donald Ball</a>
**/
class WebApplication {
@@ -126,6 +126,14 @@
}
+ /**
+ * Calls the destroy method for every active servlet.
+ */
+ void destroyServlets() {
+ _servletMapping.destroyServlets();
+ }
+
+
ServletRequest getServletRequest( URL url ) {
return _servletMapping.get( url );
}
@@ -392,6 +400,11 @@
}
+ synchronized void destroyServlet() {
+ if (_servlet != null) _servlet.destroy();
+ }
+
+
String getClassName() {
return _className;
}
@@ -437,7 +450,7 @@
SecurityConstraintImpl( Element root ) throws SAXException {
final NodeList roleNames = root.getElementsByTagName( "role-name" );
- for (int i = 0; i < roleNames.getLength(); i++) _roles.add( getTextValue( (Element) roleNames.item( i ) ) );
+ for (int i = 0; i < roleNames.getLength(); i++) _roles.add( getTextValue( roleNames.item( i ) ) );
final NodeList resources = root.getElementsByTagName( "web-resource-collection" );
for (int i = 0; i < resources.getLength(); i++) _resources.add( new WebResourceCollection( (Element) resources.item( i ) ) );
@@ -471,7 +484,7 @@
WebResourceCollection( Element root ) throws SAXException {
final NodeList urlPatterns = root.getElementsByTagName( "url-pattern" );
- for (int i = 0; i < urlPatterns.getLength(); i++) _urlPatterns.add( getTextValue( (Element) urlPatterns.item( i ) ) );
+ for (int i = 0; i < urlPatterns.getLength(); i++) _urlPatterns.add( getTextValue( urlPatterns.item( i ) ) );
}
@@ -559,6 +572,11 @@
String getPathInfo( String servletName ) {
return null;
}
+
+
+ public void destroyServlet() {
+ getConfiguration().destroyServlet();
+ }
}
@@ -642,6 +660,22 @@
return urlFile;
} else {
return urlFile.substring( 0, urlFile.indexOf( '?' ) );
+ }
+ }
+
+
+ public void destroyServlets() {
+ if (_defaultMapping != null) _defaultMapping.destroyServlet();
+ destroyServlets( _exactMatches );
+ destroyServlets( _extensions );
+ destroyServlets( _urlTree );
+ }
+
+
+ private void destroyServlets( Map exactMatches ) {
+ for (Iterator iterator = exactMatches.values().iterator(); iterator.hasNext();) {
+ ServletMapping servletMapping = (ServletMapping) iterator.next();
+ servletMapping.destroyServlet();
}
}
|