You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2003/02/07 05:50:04 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestMethodsExternalHost.java TestMethodsNoHost.java TestStatusLine.java TestWebappNoncompliant.java
jsdever 2003/02/06 20:50:03
Modified: httpclient/src/test-webapp/conf web.xml
httpclient/src/test/org/apache/commons/httpclient
TestMethodsExternalHost.java TestMethodsNoHost.java
TestStatusLine.java TestWebappNoncompliant.java
Added: httpclient/src/test-webapp/src/org/apache/commons/httpclient
StatusLineServlet.java
Log:
Added some tests to demonstrate the broken status line bug 16864
Revision Changes Path
1.3 +10 -0 jakarta-commons/httpclient/src/test-webapp/conf/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test-webapp/conf/web.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- web.xml 4 Oct 2001 17:49:15 -0000 1.2
+++ web.xml 7 Feb 2003 04:50:03 -0000 1.3
@@ -40,6 +40,11 @@
<servlet-class>org.apache.commons.httpclient.ReadCookieServlet</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>statusline</servlet-name>
+ <servlet-class>org.apache.commons.httpclient.StatusLineServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>params</servlet-name>
<url-pattern>/params</url-pattern>
@@ -73,5 +78,10 @@
<servlet-mapping>
<servlet-name>readcookie</servlet-name>
<url-pattern>/cookie/read</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>statusline</servlet-name>
+ <url-pattern>/statusline</url-pattern>
</servlet-mapping>
</web-app>
1.1 jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/StatusLineServlet.java
Index: StatusLineServlet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/StatusLineServlet.java,v 1.1 2003/02/07 04:50:03 jsdever Exp $
* $Revision: 1.1 $
* $Date: 2003/02/07 04:50:03 $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* 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 apache@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 Group.
*
* 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
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.httpclient;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class StatusLineServlet extends MultiMethodServlet {
protected void genericService(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setHeader("StatusLineSetByServlet","Yes");
int code = 402;
try {
code = Integer.parseInt(request.getHeader("Set-StatusCode"));
} catch (Exception e) {
}
String message = request.getHeader("Set-StatusMessage");
response.sendError(code, message);
}
}
1.9 +61 -85 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java
Index: TestMethodsExternalHost.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TestMethodsExternalHost.java 2 Feb 2003 11:05:19 -0000 1.8
+++ TestMethodsExternalHost.java 7 Feb 2003 04:50:03 -0000 1.9
@@ -76,16 +76,20 @@
* @author Remy Maucherat
* @author Rodney Waldhoff
* @author Ortwin Gl�ck
+ * @author Jeff Dever
* @version $Id$
*/
public class TestMethodsExternalHost extends TestCase {
+ private HttpClient client;
+ private HttpMethod method;
// -------------------------------------------------------------- Constants
private static final String externalHost = "java.sun.com";
private static final int externalPort = 80;
private static final String externalPath = "/index.html";
+ private static final String externalUri = "http://java.sun.com/index.html";
private final String PROXY_HOST = System.getProperty("httpclient.test.proxyHost");
private final String PROXY_PORT = System.getProperty("httpclient.test.proxyPort");
private final String PROXY_USER = System.getProperty("httpclient.test.proxyUser");
@@ -106,66 +110,59 @@
return new TestSuite(TestMethodsExternalHost.class);
}
+ // ------------------------------------------------------- Helper Methods
+
+ public void setUp() {
+ client = new HttpClient();
- // ----------------------------------------------------------- OPTIONS Test
-
+ client.getHostConfiguration().setHost(externalHost, externalPort, "http");
- public void testMethodsOptionsExternal() {
+ if (PROXY_HOST != null) {
+ if (PROXY_USER != null) {
+ HttpState state = client.getState();
+ state.setProxyCredentials(null, new UsernamePasswordCredentials(
+ PROXY_USER, PROXY_PASS));
+ }
+ client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
+ }
+ }
- HttpClient client = new HttpClient();
- client.getHostConfiguration().setHost(externalHost, externalPort, "http");
- OptionsMethod method = new OptionsMethod(externalPath);
+ public void tearDown() {
+ method.releaseConnection();
+ method = null;
+ client = null;
+ }
+ public void executeMethod() {
try {
- if (PROXY_HOST != null) {
- if (PROXY_USER != null) {
- HttpState state = client.getState();
- state.setProxyCredentials(null, new UsernamePasswordCredentials(
- PROXY_USER, PROXY_PASS));
- }
- client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
- }
client.executeMethod(method);
} catch (Throwable t) {
t.printStackTrace();
fail("Unable to execute method : " + t.toString());
}
+ }
+
+ // ----------------------------------------------------------- OPTIONS Test
+
+
+ public void testMethodsOptionsExternal() {
- Enumeration methodsAllowed = method.getAllowedMethods();
+ method = new OptionsMethod(externalPath);
+ executeMethod();
+
+ Enumeration methodsAllowed = ((OptionsMethod)method).getAllowedMethods();
// This enumeration musn't be empty
assertTrue("No HTTP method allowed : result of OPTIONS is incorrect.",
methodsAllowed.hasMoreElements());
}
-
-
// --------------------------------------------------------------- GET Test
public void testMethodsGetExternal() {
- HttpClient client = new HttpClient();
-
- client.getHostConfiguration().setHost(externalHost, externalPort, "http");
-
- if (PROXY_HOST != null) {
- if (PROXY_USER != null) {
- HttpState state = client.getState();
- state.setProxyCredentials(null, new UsernamePasswordCredentials(
- PROXY_USER, PROXY_PASS));
- }
- client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
- }
-
- GetMethod method = new GetMethod("/");
-
-
- try {
- client.executeMethod(method);
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Unable to execute method : " + t.toString());
- }
+ method = new GetMethod(externalUri);
+ executeMethod();
try {
String data = method.getResponseBodyAsString();
@@ -179,13 +176,7 @@
method.recycle();
method.setPath(externalPath);
-
- try {
- client.executeMethod(method);
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Unable to execute method : " + t.toString());
- }
+ executeMethod();
try {
String data = method.getResponseBodyAsString();
@@ -204,25 +195,8 @@
public void testMethodsHeadExternal() {
- HttpClient client = new HttpClient();
- client.getHostConfiguration().setHost(externalHost, externalPort, "http");
-
- if (PROXY_HOST != null) {
- if (PROXY_USER != null) {
- HttpState state = client.getState();
- state.setProxyCredentials(null, new UsernamePasswordCredentials(
- PROXY_USER, PROXY_PASS));
- }
- client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
- }
- HeadMethod method = new HeadMethod(externalPath);
-
- try {
- client.executeMethod(method);
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Unable to execute method : " + t.toString());
- }
+ method = new HeadMethod(externalPath);
+ executeMethod();
assertTrue("Method failed : " + method.getStatusCode(),
(method.getStatusCode() == 200));
@@ -232,25 +206,12 @@
/**
* This test proves that bad urls throw an IOException,
* and not some other throwable like a NullPointerException.
+ *
+ * FIXME: Bad urls don't throw an IOException.
*/
public void testIOException() {
- HttpClient client = new HttpClient();
- String host = "whaturl.com.org";
- int port = 80;
-
- client.getHostConfiguration().setHost(host, port, "http");
-
- if (PROXY_HOST != null) {
- if (PROXY_USER != null) {
- HttpState state = client.getState();
- state.setProxyCredentials(null, new UsernamePasswordCredentials(
- PROXY_USER, PROXY_PASS));
- }
- client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
- }
-
- GetMethod method = new GetMethod("");
+ method = new GetMethod("http://www.bogusurl.xyz");
try {
client.executeMethod(method);
@@ -262,5 +223,20 @@
fail("Should have thrown an exception");
}
+
+
+ /**
+ * http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16864
+ */
+ public void testDomino_Go_Webserver404() throws Exception {
+
+ // this file should not exist
+ method = new GetMethod("http://www.pc.ibm.com/us/accessories/monitors/p_allmodelos.html");
+ int statusCode = client.executeMethod(method);
+
+ assertEquals(404, method.getStatusCode());
+
+ }
+
}
1.16 +13 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
Index: TestMethodsNoHost.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TestMethodsNoHost.java 3 Feb 2003 21:21:19 -0000 1.15
+++ TestMethodsNoHost.java 7 Feb 2003 04:50:03 -0000 1.16
@@ -253,4 +253,13 @@
assertEquals(qs1, method.getQueryString());
}
+ /**
+ * Make sure that its OK to call releaseConnection if the connection has not been.
+ */
+ public void testReleaseConnection() {
+ HttpClient client = new HttpClient();
+ HttpMethod method = new GetMethod("http://bogus.url/path/");
+ method.releaseConnection();
+ }
+
}
1.6 +4 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java
Index: TestStatusLine.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestStatusLine.java 23 Jan 2003 22:48:27 -0000 1.5
+++ TestStatusLine.java 7 Feb 2003 04:50:03 -0000 1.6
@@ -149,7 +149,6 @@
fail();
} catch (HttpException e) { /* expected */ }
-
}
}
1.2 +25 -0 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappNoncompliant.java
Index: TestWebappNoncompliant.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappNoncompliant.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestWebappNoncompliant.java 1 Feb 2003 16:10:48 -0000 1.1
+++ TestWebappNoncompliant.java 7 Feb 2003 04:50:03 -0000 1.2
@@ -59,12 +59,14 @@
package org.apache.commons.httpclient;
import junit.framework.*;
+import org.apache.commons.httpclient.methods.*;
/**
* Tests cases intended to test if entity enclosing methods
* can deal with non-compliant HTTP servers or proxies
*
* @author Oleg Kalnichevski
+ * @author Jeff Dever
*/
public class TestWebappNoncompliant extends TestWebappBase
@@ -105,4 +107,27 @@
}
assertEquals(200,method.getStatusCode());
}
+
+ /**
+ */
+ public void testNoncompliantStatusLine()
+ {
+ HttpClient client = new HttpClient();
+ client.getHostConfiguration().setHost(host, port, "http");
+ GetMethod method = new GetMethod("/" + context + "/statusline");
+ method.setRequestHeader("Set-StatusCode", 444+"");
+ method.setRequestHeader("Set-StatusMessage", "This status message contains\n"
+ + " a newline and a\r"
+ + " carrage return but that should be OK.");
+ try {
+ client.executeMethod(method);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Unexpected exception: " + e.toString());
+ }
+ assertEquals(444, method.getStatusCode());
+ }
+
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org