craigmcc 01/03/21 11:38:54
Modified: tester build.xml
tester/src/bin tester.xml
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester Resources05.java
Resources05.txt
Log:
Add test cases where the URL returned by getResource() is actually opened
and read, to ensure that the appropriate stream handler is provided.
Revision Changes Path
1.7 +2 -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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- build.xml 2001/03/13 19:06:09 1.6
+++ build.xml 2001/03/21 19:38:28 1.7
@@ -70,6 +70,8 @@
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"/>
+ <copy file="src/tester/org/apache/tester/Resources05.txt"
+
tofile="${tester.build}/web/WEB-INF/classes/org/apache/tester/Unpacked05.txt"/>
<!-- Install Xerces -->
<copy todir="${tester.build}/web/WEB-INF/lib">
1.22 +27 -0 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- tester.xml 2001/03/17 19:48:20 1.21
+++ tester.xml 2001/03/21 19:38:40 1.22
@@ -350,6 +350,33 @@
request="${context.path}/Resources04?mode=class&path=/org/apache/tester/Unpacked04.txt.bad"
outContent="Resources04 PASSED"/>
+ <!-- ========== Positive Combined getResource/Open Tests ============== -->
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources05?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}/Resources05?mode=context&path=/Forward01.txt"
+ outContent="Forward01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+ request="${context.path}/Resources05?mode=context&path=/Include01.txt"
+ outContent="Include01 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources05?mode=class&path=/org/apache/tester/Resources05.txt"
+ outContent="Resources05 PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ debug="${debug}"
+
request="${context.path}/Resources05?mode=class&path=/org/apache/tester/Unpacked05.txt"
+ outContent="Resources05 PASSED"/>
+
</target>
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Resources05.java
Index: Resources05.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>. The URL returned by
* these calls is then opened with <code>url.openStream()</code>
* in order to ensure that the correct data is actually read.
* 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/03/21 19:38:46 $
*/
public class Resources05 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";
// Prepare for the desired test
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
InputStream is = null;
InputStreamReader isr = null;
URL url = null;
StringBuffer results = new StringBuffer();
boolean ok = true;
// Acquire the appropriate URL
try {
if ("context".equals(mode))
url = getServletContext().getResource(path);
else
url = this.getClass().getResource(path);
if (url == null) {
results.append(" No URL returned");
ok = false;
}
} catch (MalformedURLException e) {
results.append(" MalformedURLException");
ok = false;
}
// Open an input stream and input stream reader on this URL
try {
if (ok) {
is = url.openStream();
isr = new InputStreamReader(is);
}
} catch (IOException e) {
results.append(" Open IOException: " + e);
ok = false;
}
// Copy the contents of this stream to our output
try {
if (ok) {
while (true) {
int ch = isr.read();
if (ch < 0)
break;
writer.print((char) ch);
}
}
} catch (IOException e) {
results.append(" Copy IOException: " + e);
ok = false;
}
// Close the input stream
try {
if (ok) {
isr.close();
}
} catch (IOException e) {
results.append(" Close IOException: " + e);
}
// Report any failures we have encountered
if (!ok) {
writer.print("Resources05 FAILED -");
writer.println(results.toString());
}
// 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/Resources05.txt
Index: Resources05.txt
===================================================================
Resources05 PASSED
1.15 +20 -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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- web.xml 2001/03/17 19:48:21 1.14
+++ web.xml 2001/03/21 19:38:50 1.15
@@ -147,6 +147,11 @@
<filter-mapping>
<filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedResources05</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
<url-pattern>/WrappedSession01</url-pattern>
</filter-mapping>
@@ -309,6 +314,11 @@
</servlet>
<servlet>
+ <servlet-name>Resources05</servlet-name>
+ <servlet-class>org.apache.tester.Resources05</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>Session01</servlet-name>
<servlet-class>org.apache.tester.Session01</servlet-class>
</servlet>
@@ -584,6 +594,16 @@
<servlet-mapping>
<servlet-name>Resources04</servlet-name>
<url-pattern>/WrappedResources04</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources05</servlet-name>
+ <url-pattern>/Resources05</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Resources05</servlet-name>
+ <url-pattern>/WrappedResources05</url-pattern>
</servlet-mapping>
<servlet-mapping>