You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@apache.org on 2001/07/11 01:30:16 UTC
cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml
craigmcc 01/07/10 16:30:16
Modified: tester/src/bin tester.xml
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester Lifecycle01.java
Lifecycle02.java
Log:
Add unit tests to prove that servlet lifecycle is handled correctly - i.e.
init() is called exactly once before the service() method is invoked, and
the first call can be either a GET or a POST.
These tests indicate that the error reported by Bugzilla #206 does *not*
occur with current Tomcat 4.0 code.
Revision Changes Path
1.53 +24 -1 jakarta-tomcat-4.0/tester/src/bin/tester.xml
Index: tester.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- tester.xml 2001/06/25 15:40:47 1.52
+++ tester.xml 2001/07/10 23:30:10 1.53
@@ -15,7 +15,7 @@
<taskdef name="tester" classname="org.apache.tester.TestClient"/>
- <target name="all" depends="ROOT,Authentication,CaseSensitive,Decoding,ErrorPage,FilterRequest,FilterResponse,Jndi,RequestDispatcher,Resources,ServletContext,ServletRequest,ServletResponse,HttpSession,XercesTest,SSITest,CGITest"/>
+ <target name="all" depends="ROOT,Authentication,CaseSensitive,Decoding,ErrorPage,FilterRequest,FilterResponse,Jndi,Lifecycle,RequestDispatcher,Resources,ServletContext,ServletRequest,ServletResponse,HttpSession,XercesTest,SSITest,CGITest"/>
<target name="ROOT">
@@ -493,6 +493,29 @@
<tester host="${host}" port="${port}" protocol="${protocol}"
request="${context.path}/WrappedJndi02" debug="${debug}"
outContent="Jndi02 PASSED"/>
+
+ </target>
+
+
+ <target name="Lifecycle">
+
+ <!-- ========== Lifecycle Management ================================== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/Lifecycle01"
+ outContent="Lifecycle01 PASSED" debug="${debug}"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/WrappedLifecycle01"
+ outContent="Lifecycle01 PASSED" debug="${debug}"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/Lifecycle02" method="POST"
+ outContent="Lifecycle02 PASSED" debug="${debug}"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/WrappedLifecycle02" method="POST"
+ outContent="Lifecycle02 PASSED" debug="${debug}"/>
</target>
1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Lifecycle01.java
Index: Lifecycle01.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <ap...@apache.org>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for servlet lifecycle management. This servlet is
* <strong>not</strong> declared to be load-on-startup, and the first request
* made to it should be a "GET".
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/07/10 23:30:12 $
*/
public class Lifecycle01 extends HttpServlet {
private boolean doubled = false;
private boolean initialized = false;
public void init() throws ServletException {
if (initialized)
doubled = true;
else
initialized = true;
}
public void destroy() {
initialized = false;
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
if (doubled) {
writer.println("Lifecycle01 FAILED - Double initialization");
} else if (initialized) {
writer.println("Lifecycle01 PASSED");
} else {
writer.println("Lifecycle01 FAILED - GET but not initialized");
}
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
if (doubled) {
writer.println("Lifecycle01 FAILED - POST and double initialization");
} else if (initialized) {
writer.println("Lifecycle01 FAILED - POST called");
} else {
writer.println("Lifecycle01 FAILED - POST and not initialized");
}
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Lifecycle02.java
Index: Lifecycle02.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <ap...@apache.org>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for servlet lifecycle management. This servlet is
* <strong>not</strong> declared to be load-on-startup, and the first request
* made to it should be a "POST".
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/07/10 23:30:13 $
*/
public class Lifecycle02 extends HttpServlet {
private boolean doubled = false;
private boolean initialized = false;
public void init() throws ServletException {
if (initialized)
doubled = true;
else
initialized = true;
}
public void destroy() {
initialized = false;
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
if (doubled) {
writer.println("Lifecycle02 FAILED - GET and double initialization");
} else if (initialized) {
writer.println("Lifecycle02 FAILED - GET called");
} else {
writer.println("Lifecycle02 FAILED - GET and not initialized");
}
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
if (doubled) {
writer.println("Lifecycle02 FAILED - Double initialization");
} else if (initialized) {
writer.println("Lifecycle02 PASSED");
} else {
writer.println("Lifecycle02 FAILED - POST but not initialized");
}
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.40 +40 -0 jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- web.xml 2001/06/24 00:00:06 1.39
+++ web.xml 2001/07/10 23:30:14 1.40
@@ -280,6 +280,16 @@
<filter-mapping>
<filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedLifecycle01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedLifecycle02</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
<url-pattern>/WrappedReflection01</url-pattern>
</filter-mapping>
@@ -654,6 +664,16 @@
</servlet>
<servlet>
+ <servlet-name>Lifecycle01</servlet-name>
+ <servlet-class>org.apache.tester.Lifecycle01</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Lifecycle02</servlet-name>
+ <servlet-class>org.apache.tester.Lifecycle02</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>Reflection01</servlet-name>
<servlet-class>org.apache.tester.Reflection01</servlet-class>
</servlet>
@@ -1164,6 +1184,26 @@
<servlet-mapping>
<servlet-name>Jndi02</servlet-name>
<url-pattern>/WrappedJndi02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Lifecycle01</servlet-name>
+ <url-pattern>/Lifecycle01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Lifecycle01</servlet-name>
+ <url-pattern>/WrappedLifecycle01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Lifecycle02</servlet-name>
+ <url-pattern>/Lifecycle02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Lifecycle02</servlet-name>
+ <url-pattern>/WrappedLifecycle02</url-pattern>
</servlet-mapping>
<servlet-mapping>