You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by og...@apache.org on 2005/09/12 17:03:07 UTC
svn commit: r280350 -
/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java
Author: oglueck
Date: Mon Sep 12 08:03:03 2005
New Revision: 280350
URL: http://svn.apache.org/viewcvs?rev=280350&view=rev
Log:
fix spacing
prepare for adding another case
Modified:
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java?rev=280350&r1=280349&r2=280350&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestRedirects.java Mon Sep 12 08:03:03 2005
@@ -45,7 +45,7 @@
import org.apache.commons.httpclient.server.SimpleResponse;
/**
- * Basic authentication test cases.
+ * Redirection test cases.
*
* @author Oleg Kalnichevski
*
@@ -73,43 +73,41 @@
}
private class BasicRedirectService implements HttpService {
-
- private int statuscode = HttpStatus.SC_MOVED_TEMPORARILY;
- private String host = null;
- private int port;
+ private int statuscode = HttpStatus.SC_MOVED_TEMPORARILY;
+ private String host = null;
+ private int port;
- public BasicRedirectService(final String host, int port, int statuscode) {
- super();
- this.host = host;
- this.port = port;
- if (statuscode > 0) {
- this.statuscode = statuscode;
- }
+ public BasicRedirectService(final String host, int port, int statuscode) {
+ super();
+ this.host = host;
+ this.port = port;
+ if (statuscode > 0) {
+ this.statuscode = statuscode;
}
+ }
- public BasicRedirectService(final String host, int port) {
- this(host, port, -1);
- }
+ public BasicRedirectService(final String host, int port) {
+ this(host, port, -1);
+ }
- public boolean process(final SimpleRequest request, final SimpleResponse response)
- throws IOException
- {
- RequestLine reqline = request.getRequestLine();
- HttpVersion ver = reqline.getHttpVersion();
- if (reqline.getUri().equals("/oldlocation/")) {
- response.setStatusLine(ver, this.statuscode);
- response.addHeader(new Header("Location",
- "http://" + this.host + ":" + this.port + "/newlocation/"));
- response.addHeader(new Header("Connection", "close"));
- } else if (reqline.getUri().equals("/newlocation/")) {
- response.setStatusLine(ver, HttpStatus.SC_OK);
- response.setBodyString("Successful redirect");
- } else {
- response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
- }
- return true;
+ public boolean process(final SimpleRequest request, final SimpleResponse response)
+ throws IOException {
+ RequestLine reqline = request.getRequestLine();
+ HttpVersion ver = reqline.getHttpVersion();
+ if (reqline.getUri().equals("/oldlocation/")) {
+ response.setStatusLine(ver, this.statuscode);
+ response.addHeader(new Header("Location",
+ "http://" + this.host + ":" + this.port + "/newlocation/"));
+ response.addHeader(new Header("Connection", "close"));
+ } else if (reqline.getUri().equals("/newlocation/")) {
+ response.setStatusLine(ver, HttpStatus.SC_OK);
+ response.setBodyString("Successful redirect");
+ } else {
+ response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
}
+ return true;
}
+ }
private class CircularRedirectService implements HttpService {
@@ -162,29 +160,30 @@
}
private class BogusRedirectService implements HttpService {
+ private String url;
- public BogusRedirectService() {
- super();
- }
+ public BogusRedirectService(String redirectUrl) {
+ super();
+ this.url = redirectUrl;
+ }
- public boolean process(final SimpleRequest request, final SimpleResponse response)
- throws IOException
- {
- RequestLine reqline = request.getRequestLine();
- HttpVersion ver = reqline.getHttpVersion();
- if (reqline.getUri().equals("/oldlocation/")) {
- response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
- response.addHeader(new Header("Location", "xxx://bogus"));
- } else if (reqline.getUri().equals("/relativelocation/")) {
- response.setStatusLine(ver, HttpStatus.SC_OK);
- response.setBodyString("Successful redirect");
- } else {
- response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
- }
- return true;
+ public boolean process(final SimpleRequest request, final SimpleResponse response)
+ throws IOException {
+ RequestLine reqline = request.getRequestLine();
+ HttpVersion ver = reqline.getHttpVersion();
+ if (reqline.getUri().equals("/oldlocation/")) {
+ response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
+ response.addHeader(new Header("Location", url));
+ } else if (reqline.getUri().equals("/relativelocation/")) {
+ response.setStatusLine(ver, HttpStatus.SC_OK);
+ response.setBodyString("Successful redirect");
+ } else {
+ response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
}
+ return true;
}
-
+ }
+
public void testBasicRedirect300() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
@@ -414,7 +413,7 @@
public void testRejectBogusRedirectLocation() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
- this.server.setHttpService(new BogusRedirectService());
+ this.server.setHttpService(new BogusRedirectService("xxx://bogus"));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org