rwaldhoff 01/05/21 13:00:02
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMethodBase.java HttpMethod.java
httpclient/src/java/org/apache/commons/httpclient/methods
HeadMethod.java GetMethod.java
Log:
making followRedirects a mutable property
Revision Changes Path
1.4 +16 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpMethodBase.java 2001/05/11 21:42:46 1.3
+++ HttpMethodBase.java 2001/05/21 19:59:48 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.3 2001/05/11 21:42:46 jericho Exp $
- * $Revision: 1.3 $
- * $Date: 2001/05/11 21:42:46 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.4 2001/05/21 19:59:48 rwaldhoff Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/05/21 19:59:48 $
*
* ====================================================================
*
@@ -154,10 +154,11 @@
*/
protected String queryString = null;
+ protected boolean followRedirects = false;
// ----------------------------------------------------------- Constructors
-
+
/**
* Method constructor.
*/
@@ -312,9 +313,17 @@
* @return boolean True if auto redirect should be used for this method
*/
public boolean followRedirects() {
- return (false);
+ return (this.followRedirects);
}
+ /**
+ * Set whether or not I should automatically follow redirects.
+ *
+ * @param followRedirects <tt>true</tt> if auto redirect should be used for
this method
+ */
+ public void setFollowRedirects(boolean followRedirects) {
+ this.followRedirects = followRedirects;
+ }
/**
* Set the state token.
@@ -383,6 +392,7 @@
used = false;
query = null;
queryString = null;
+ followRedirects = false;
}
@@ -556,7 +566,7 @@
/**
* Return true if the method should ask for an expectation.
- *
+ *
* @return true if an expectation will be sent
*/
public boolean needExpectation() {
1.2 +12 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java
Index: HttpMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpMethod.java 2001/04/25 18:42:51 1.1
+++ HttpMethod.java 2001/05/21 19:59:50 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
1.1 2001/04/25 18:42:51 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/25 18:42:51 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
1.2 2001/05/21 19:59:50 rwaldhoff Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/21 19:59:50 $
*
* ====================================================================
*
@@ -201,6 +201,12 @@
*/
public boolean followRedirects();
+ /**
+ * Set whether or not I should automatically follow redirects.
+ *
+ * @param followRedirects <tt>true</tt> if auto redirect should be used for
this method
+ */
+ public void setFollowRedirects(boolean followRedirects);
/**
* Set the state token.
@@ -210,7 +216,7 @@
/**
* Set URL parameter.
- *
+ *
* @param parameterName Parameter name
* @param parameterValue Parameter value
*/
@@ -219,7 +225,7 @@
/**
* Set query string.
- *
+ *
* @param queryString Query string
*/
public void setQueryString(String queryString);
@@ -323,7 +329,7 @@
/**
* Return true if the method needs a content-length header in the request.
- *
+ *
* @return true if a content-length header will be expected by the server
*/
public boolean needContentLength();
@@ -331,7 +337,7 @@
/**
* Return true if the method should ask for an expectation.
- *
+ *
* @return true if an expectation will be sent
*/
public boolean needExpectation();
1.2 +26 -30
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java
Index: HeadMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HeadMethod.java 2001/04/25 18:42:52 1.1
+++ HeadMethod.java 2001/05/21 19:59:55 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
1.1 2001/04/25 18:42:52 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/25 18:42:52 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
1.2 2001/05/21 19:59:55 rwaldhoff Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/21 19:59:55 $
*
* ====================================================================
*
@@ -60,7 +60,7 @@
* [Additional notices, if required by prior licensing conditions]
*
*/
-
+
package org.apache.commons.httpclient.methods;
import java.io.*;
@@ -77,44 +77,40 @@
*/
public class HeadMethod
extends HttpMethodBase {
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Method constructor.
*/
public HeadMethod() {
name = "HEAD";
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
public HeadMethod(String path) {
super(path);
name = "HEAD";
- }
-
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * True if this methods should automatically follow redirects.
- *
- * @return boolean True if auto redirect should be used for this method
- */
- public boolean followRedirects() {
- return (true);
+ setFollowRedirects(true);
}
-
-
+
+ // ---------------------------------------------------------------- Methods
+
+ // override recycle to reset redirects default
+ public void recycle() {
+ super.recycle();
+ setFollowRedirects(true);
+ }
+
// --------------------------------------------------- WebdavMethod Methods
-
-
+
+
/**
* Generate the query body.
*
@@ -123,8 +119,8 @@
public String generateQuery() {
return null;
}
-
-
+
+
/**
* Parse response.
*
@@ -133,8 +129,8 @@
public void parseResponse(InputStream is)
throws IOException {
}
-
-
+
+
/**
* Return true if the method needs a content-length header in the request.
*
1.2 +93 -92
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java
Index: GetMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GetMethod.java 2001/04/25 18:42:52 1.1
+++ GetMethod.java 2001/05/21 19:59:58 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
1.1 2001/04/25 18:42:52 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/25 18:42:52 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
1.2 2001/05/21 19:59:58 rwaldhoff Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/21 19:59:58 $
*
* ====================================================================
*
@@ -60,7 +60,7 @@
* [Additional notices, if required by prior licensing conditions]
*
*/
-
+
package org.apache.commons.httpclient.methods;
import java.io.*;
@@ -79,8 +79,8 @@
*/
public class GetMethod
extends HttpMethodBase {
-
-
+
+
// -------------------------------------------------------------- Constants
@@ -88,28 +88,29 @@
* Temporary directory.
*/
public static final String TEMP_DIR = "temp/";
-
-
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Method constructor.
*/
public GetMethod() {
name = "GET";
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
public GetMethod(String path) {
super(path);
name = "GET";
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
@@ -117,9 +118,10 @@
this(path);
useDisk = true;
setTempDir(tempDir);
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
@@ -128,9 +130,10 @@
setUseDisk(useDisk);
if (useDisk)
setTempDir(tempDir);
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
@@ -139,6 +142,7 @@
useDisk = true;
setTempDir(tempDir);
setTempFile(tempFile);
+ setFollowRedirects(true);
}
/**
@@ -152,9 +156,10 @@
setTempDir(tempDir);
setTempFile(tempFile);
}
+ setFollowRedirects(true);
}
-
-
+
+
/**
* Method constructor.
*/
@@ -162,45 +167,46 @@
this(path);
useDisk = true;
this.fileData = fileData;
+ setFollowRedirects(true);
}
-
-
+
+
// ----------------------------------------------------- Instance Variables
-
-
+
+
/**
* By default, the get method will buffer read data to the disk.
*/
protected boolean useDisk = true;
-
-
+
+
/**
* If we're not using the HD, we're using a memory byte buffer.
*/
protected byte[] memoryData;
-
-
+
+
/**
* File which contains the buffered data.
*/
protected File fileData;
-
-
+
+
/**
* Temporary directory to use.
*/
protected String tempDir = TEMP_DIR;
-
-
+
+
/**
* Temporary file to use.
*/
protected String tempFile = null;
-
-
+
+
// ------------------------------------------------------------- Properties
-
-
+
+
/**
* Use disk setter.
*
@@ -210,8 +216,8 @@
checkNotUsed();
this.useDisk = useDisk;
}
-
-
+
+
/**
* Use disk getter.
*
@@ -219,19 +225,8 @@
*/
public boolean getUseDisk() {
return useDisk;
- }
-
-
- /**
- * True if this methods should automatically follow redirects.
- *
- * @return boolean True if auto redirect should be used for this method
- */
- public boolean followRedirects() {
- return (true);
}
-
-
+
/**
* Temporary directory setter.
*
@@ -241,16 +236,16 @@
checkNotUsed();
this.tempDir = tempDir;
}
-
-
+
+
/**
* Temporary directory getter.
*/
public String getTempDir() {
return tempDir;
}
-
-
+
+
/**
* Temporary file setter.
*
@@ -260,24 +255,24 @@
checkNotUsed();
this.tempFile = tempFile;
}
-
-
+
+
/**
* Temporary file getter.
*/
public String getTempFile() {
return tempFile;
}
-
-
+
+
/**
* File data getter.
*/
public File getFileData() {
return fileData;
}
-
-
+
+
/**
* File data setter.
*/
@@ -285,19 +280,25 @@
checkNotUsed();
this.fileData = fileData;
}
-
-
+
+
// --------------------------------------------------------- Public Methods
-
-
+
+ // override recycle to reset redirects default
+ public void recycle() {
+ super.recycle();
+ setFollowRedirects(true);
+ }
+
+
/**
* Get read data.
*/
public InputStream getData()
throws IOException {
-
+
checkUsed();
-
+
if (useDisk) {
return new FileInputStream(fileData);
} else {
@@ -305,18 +306,18 @@
throw new IOException("Data not found");
return new ByteArrayInputStream(memoryData);
}
-
+
}
-
-
+
+
/**
* Get read data as a String.
*/
public String getDataAsString()
throws IOException {
-
+
checkUsed();
-
+
if (useDisk) {
InputStream is = new FileInputStream(fileData);
byte[] buffer = new byte[4096];
@@ -336,13 +337,13 @@
else
return "";
}
-
+
}
-
-
+
+
// ----------------------------------------------------- HttpMethod Methods
-
-
+
+
/**
* Generate the query body.
*
@@ -351,8 +352,8 @@
public String generateQuery() {
return null;
}
-
-
+
+
/**
* Parse response.
*
@@ -360,17 +361,17 @@
*/
public void parseResponse(InputStream is)
throws IOException {
-
+
OutputStream out = null;
-
+
if (useDisk) {
-
+
if (fileData == null) {
-
+
// Create a temporary file on the HD
File dir = new File(tempDir);
dir.mkdirs();
-
+
String tempFileName = null;
if (tempFile == null) {
String encodedPath = URLEncoder.encode(getPath());
@@ -384,17 +385,17 @@
} else {
tempFileName = tempFile;
}
-
+
fileData = new File(tempDir, tempFileName);
-
+
}
-
+
out = new FileOutputStream(fileData);
-
+
} else {
out = new ByteArrayOutputStream();
}
-
+
byte[] buffer = new byte[4096];
int nb = 0;
while (true) {
@@ -405,15 +406,15 @@
throw new IOException("Unable to buffer data");
out.write(buffer, 0, nb);
}
-
+
if (!useDisk)
memoryData = ((ByteArrayOutputStream) out).toByteArray();
-
+
out.close();
-
+
}
-
-
+
+
/**
* Return true if the method needs a content-length header in the request.
*