craigmcc 01/01/23 12:12:22
Modified: tester build.xml
tester/src/bin tester.xml
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester Resources01.java
Resources01.txt Resources02.java Resources03.java
Resources03.txt Resources04.java
Log:
Add a variety of positive and negative tests for the following APIs:
ServletContext.getResource()
ServletContext.getResourceAsStream()
Class.getResource() - Both WEB-INF/classes and WEB-INF/lib
Class.getResourceAsStream() - Both WEB-INF/classes and WEB-INF/lib
Tomcat 4.0 current code (including the recently merged resources changes)
passes all of these tests.
Revision Changes Path
1.2 +8 -0 jakarta-tomcat-4.0/tester/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/build.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.xml 2000/12/18 05:06:12 1.1
+++ build.xml 2001/01/23 20:11:48 1.2
@@ -41,6 +41,7 @@
<copy todir="${tester.build}/web">
<fileset dir="web"/>
</copy>
+ <mkdir dir="${tester.build}/web/WEB-INF/classes"/>
</target>
@@ -59,7 +60,14 @@
<fileset dir="src/tester">
<include name="**/*.properties"/>
</fileset>
+ <fileset dir="src/tester">
+ <include name="**/*.txt"/>
+ </fileset>
</copy>
+ <copy file="src/tester/org/apache/tester/Resources01.txt"
+
tofile="${tester.build}/web/WEB-INF/classes/org/apache/tester/Unpacked01.txt"/>
+ <copy file="src/tester/org/apache/tester/Resources03.txt"
+
tofile="${tester.build}/web/WEB-INF/classes/org/apache/tester/Unpacked03.txt"/>
<!-- Create and install tester library -->
<mkdir dir="${tester.build}/web/WEB-INF/lib"/>
1.8 +123 -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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- tester.xml 2001/01/06 02:38:12 1.7
+++ tester.xml 2001/01/23 20:12:00 1.8
@@ -2,6 +2,7 @@
<!-- ========== Global Properties ======================================= -->
<property name="catalina.home" value="../../build/tomcat-4.0"/>
+ <property name="debug" value="0"/>
<property name="host" value="localhost"/>
<property name="port" value="8080"/>
<!-- <property name="protocol" value="HTTP/1.0"/> -->
@@ -10,7 +11,7 @@
<taskdef name="tester" classname="org.apache.tester.TestClient"/>
- <target name="all"
depends="ROOT,CaseSensitive,RequestDispatcher,ServletRequest,ServletResponse"/>
+ <target name="all"
depends="ROOT,CaseSensitive,RequestDispatcher,Resources,ServletRequest,ServletResponse"/>
<target name="ROOT">
@@ -112,6 +113,127 @@
<tester host="${host}" port="${port}" protocol="${protocol}"
request="${context.path}/WrappedInclude01"
outContent="Include01 PASSED"/>
+
+ </target>
+
+
+ <target name="Resources">
+
+ <!-- ========== Positive ServletContext.getResource() Tests =========== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources01?mode=context&path=/WEB-INF/web.xml"
+ outContent="Resources01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources01?mode=context&path=/Forward01.txt"
+ outContent="Resources01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources01?mode=context&path=/Include01.txt"
+ outContent="Resources01 PASSED"/>
+
+ <!-- ========== Positive Class.getResource() Tests ==================== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources01?mode=class&path=/org/apache/tester/Resources01.txt"
+ outContent="Resources01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources01?mode=class&path=/org/apache/tester/Unpacked01.txt"
+ outContent="Resources01 PASSED"/>
+
+ <!-- ========== Negative ServletContext.getResource() Tests =========== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources02?mode=context&path=/WEB-INF/web.xml.bad"
+ outContent="Resources02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources02?mode=context&path=/Forward02.txt.bad"
+ outContent="Resources02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources02?mode=context&path=/Include02.txt.bad"
+ outContent="Resources02 PASSED"/>
+
+ <!-- ========== Negative Class.getResource() Tests ==================== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources02?mode=class&path=/org/apache/tester/Resources02.txt.bad"
+ outContent="Resources02 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources02?mode=class&path=/org/apache/tester/Unpacked02.txt.bad"
+ outContent="Resources02 PASSED"/>
+
+ <!-- ========== Positive ServletContext.getResourceAsStream() Tests === -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources03?mode=context&path=/WEB-INF/web.xml"
+ outContent="<?xml version="1.0"
encoding="ISO-8859-1"?>"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources03?mode=context&path=/Forward01.txt"
+ outContent="Forward01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources03?mode=context&path=/Include01.txt"
+ outContent="Include01 PASSED"/>
+
+ <!-- ========== Positive Class.getResourceAsStream() Tests ============ -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources03?mode=class&path=/org/apache/tester/Resources03.txt"
+ outContent="Resources03 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources03?mode=class&path=/org/apache/tester/Unpacked03.txt"
+ outContent="Resources03 PASSED"/>
+
+ <!-- ========== Negative ServletContext.getResourceAsStream() Tests === -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources04?mode=context&path=/WEB-INF/web.xml.bad"
+ outContent="Resources04 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources04?mode=context&path=/Forward04.txt.bad"
+ outContent="Resources04 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources04?mode=context&path=/Include04.txt.bad"
+ outContent="Resources04 PASSED"/>
+
+ <!-- ========== Negative Class.getResourceAsStream() Tests ============ -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources04?mode=class&path=/org/apache/tester/Resources04.txt.bad"
+ outContent="Resources04 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources04?mode=class&path=/org/apache/tester/Unpacked04.txt.bad"
+ outContent="Resources04 PASSED"/>
</target>
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Resources01.java
Index: Resources01.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 <[EMAIL PROTECTED]>. *
* *
* 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 <code>ServletContext.getResource()</code> as well as
* <code>ClassLoader.getResource()</code>. Operation is controlled by query
* parameters:
* <ul>
* <li><strong>mode</strong> - Use <code>context</code> for servlet context
* test, or <code>class</code> for class loader test. [context]</li>
* <li><strong>path</strong> - Resource path to the requested resource,
* starting with a slash. [/WEB-INF/web.xml]</li>
* </ul>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/01/23 20:12:08 $
*/
public class Resources01 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Identify our configuration parameters
String mode = request.getParameter("mode");
if (mode == null)
mode = "context";
String path = request.getParameter("path");
if (path == null)
path = "/WEB-INF/web.xml";
// Execute the desired test
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
URL url = null;
try {
if ("context".equals(mode))
url = getServletContext().getResource(path);
else
url = this.getClass().getResource(path);
if (url == null)
writer.println("Resources01 FAILED - No URL was returned");
else {
writer.println("Resources01 PASSED");
writer.println("url = " + url.toString());
}
} catch (MalformedURLException e) {
writer.println("Resources01 FAILED - MalformedURLException: "
+ e);
}
// Add wrapper messages as required
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/Resources01.txt
Index: Resources01.txt
===================================================================
Resources01 PASSED
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Resources02.java
Index: Resources02.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 <[EMAIL PROTECTED]>. *
* *
* 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.*;
/**
* Negative test for <code>ServletContext.getResource()</code> as well as
* <code>ClassLoader.getResource()</code>. Operation is controlled by query
* parameters:
* <ul>
* <li><strong>mode</strong> - Use <code>context</code> for servlet context
* test, or <code>class</code> for class loader test. [context]</li>
* <li><strong>path</strong> - Resource path to the requested resource,
* starting with a slash. [/WEB-INF/web.xml]</li>
* </ul>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/01/23 20:12:10 $
*/
public class Resources02 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Identify our configuration parameters
String mode = request.getParameter("mode");
if (mode == null)
mode = "context";
String path = request.getParameter("path");
if (path == null)
path = "/WEB-INF/web.xml";
// Execute the desired test
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
URL url = null;
try {
if ("context".equals(mode))
url = getServletContext().getResource(path);
else
url = this.getClass().getResource(path);
if (url == null)
writer.println("Resources02 PASSED");
else
writer.println("Resources02 FAILED - Returned URL " +
url.toString());
} catch (MalformedURLException e) {
writer.println("Resources02 FAILED - MalformedURLException: "
+ e);
}
// Add wrapper messages as required
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/Resources03.java
Index: Resources03.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 <[EMAIL PROTECTED]>. *
* *
* 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 <code>ServletContext.getResourceAsStream()</code> as well
* as <code>ClassLoader.getResourceAsStream()</code>. Operation is controlled
* by query parameters:
* <ul>
* <li><strong>mode</strong> - Use <code>context</code> for servlet context
* test, or <code>class</code> for class loader test. [context]</li>
* <li><strong>path</strong> - Resource path to the requested resource,
* starting with a slash. [/WEB-INF/web.xml]</li>
* </ul>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/01/23 20:12:11 $
*/
public class Resources03 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Identify our configuration parameters
String mode = request.getParameter("mode");
if (mode == null)
mode = "context";
String path = request.getParameter("path");
if (path == null)
path = "/WEB-INF/web.xml";
// Execute the desired test
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
InputStream is = null;
URL url = null;
try {
if ("context".equals(mode)) {
is = getServletContext().getResourceAsStream(path);
url = getServletContext().getResource(path);
} else {
is = this.getClass().getResourceAsStream(path);
url = this.getClass().getResource(path);
}
if (url == null) {
if (is == null)
writer.println("Resources03 FAILED - No IS or URL was returned");
else
writer.println("Resources03 FAILED - Returned IS but no URL");
} else {
if (is == null)
writer.println("Resources03 FAILED - Returned URL but no IS");
else {
InputStreamReader isr = new InputStreamReader(is);
while (true) {
int c = isr.read();
if (c < 0)
break;
char ch = (char) c;
if (ch < ' ')
break;
writer.print(ch);
}
}
writer.println();
writer.println("url = " + url.toString());
}
} catch (MalformedURLException e) {
writer.println("Resources03 FAILED - MalformedURLException: "
+ e);
} catch (IOException e) {
writer.println("Resources03 FAILED - IOException: " + e);
}
// Add wrapper messages as required
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/Resources03.txt
Index: Resources03.txt
===================================================================
Resources03 PASSED
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Resources04.java
Index: Resources04.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 <[EMAIL PROTECTED]>. *
* *
* 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.*;
/**
* Negative test for <code>ServletContext.getResourceAsStream()</code> as well
* as <code>ClassLoader.getResourceAsStream()</code>. Operation is controlled
* by query parameters:
* <ul>
* <li><strong>mode</strong> - Use <code>context</code> for servlet context
* test, or <code>class</code> for class loader test. [context]</li>
* <li><strong>path</strong> - Resource path to the requested resource,
* starting with a slash. [/WEB-INF/web.xml]</li>
* </ul>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/01/23 20:12:12 $
*/
public class Resources04 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Identify our configuration parameters
String mode = request.getParameter("mode");
if (mode == null)
mode = "context";
String path = request.getParameter("path");
if (path == null)
path = "/WEB-INF/web.xml";
// Execute the desired test
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
InputStream is = null;
URL url = null;
try {
if ("context".equals(mode)) {
is = getServletContext().getResourceAsStream(path);
url = getServletContext().getResource(path);
} else {
is = this.getClass().getResourceAsStream(path);
url = this.getClass().getResource(path);
}
if (is == null) {
if (url == null)
writer.println("Resources04 PASSED");
else
writer.println("Resources04 FAILED - Stream is null but URL is "
+ url);
} else {
if (url != null)
writer.println("Resources04 FAILED - Stream is not null and URL
is " + url);
else
writer.println("Resources04 FAILED - Stream is not null and URL
is null");
}
} catch (MalformedURLException e) {
writer.println("Resources04 FAILED - MalformedURLException: "
+ e);
}
// Add wrapper messages as required
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.7 +81 -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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- web.xml 2001/01/06 02:38:13 1.6
+++ web.xml 2001/01/23 20:12:17 1.7
@@ -81,6 +81,26 @@
</filter-mapping>
<filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources02</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources03</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources04</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
<filter-name>GenericFilter</filter-name>
<url-pattern>/WrappedSetBufferSize01</url-pattern>
</filter-mapping>
@@ -144,6 +164,26 @@
</servlet>
<servlet>
+ <servlet-name>Resources01</servlet-name>
+ <servlet-class>org.apache.tester.Resources01</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Resources02</servlet-name>
+ <servlet-class>org.apache.tester.Resources02</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Resources03</servlet-name>
+ <servlet-class>org.apache.tester.Resources03</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Resources04</servlet-name>
+ <servlet-class>org.apache.tester.Resources04</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>SetBufferSize01</servlet-name>
<servlet-class>org.apache.tester.SetBufferSize01</servlet-class>
</servlet>
@@ -153,6 +193,7 @@
<servlet-class>org.apache.tester.SetLocale01</servlet-class>
</servlet>
+
<!-- ========== Servlet Mappings ====================================== -->
<servlet-mapping>
@@ -248,6 +289,46 @@
<servlet-mapping>
<servlet-name>Reset01</servlet-name>
<url-pattern>/WrappedReset01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources01</servlet-name>
+ <url-pattern>/Resources01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources01</servlet-name>
+ <url-pattern>/WrappedResources01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources02</servlet-name>
+ <url-pattern>/Resources02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources02</servlet-name>
+ <url-pattern>/WrappedResources02</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources03</servlet-name>
+ <url-pattern>/Resources03</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources03</servlet-name>
+ <url-pattern>/WrappedResources03</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources04</servlet-name>
+ <url-pattern>/Resources04</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources04</servlet-name>
+ <url-pattern>/WrappedResources04</url-pattern>
</servlet-mapping>
<servlet-mapping>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]