rwaldhoff 01/08/13 16:35:30
Modified: httpclient/src/java/org/apache/commons/httpclient/methods
Tag: rlwrefactoring DeleteMethod.java
GetMethod.java HeadMethod.java PostMethod.java
PutMethod.java
httpclient/src/java/org/apache/commons/httpclient Tag:
rlwrefactoring HttpMethodBase.java
Log:
More JavaDoc.
Removing some unused (legacy) methods.
Revision Changes Path
No revision
No revision
1.1.1.1.2.2 +11 -5
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java
Index: DeleteMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.1.1.1.2.2
diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
--- DeleteMethod.java 2001/08/10 22:27:12 1.1.1.1.2.1
+++ DeleteMethod.java 2001/08/13 23:35:29 1.1.1.1.2.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v
1.1.1.1.2.1 2001/08/10 22:27:12 rwaldhoff Exp $
- * $Revision: 1.1.1.1.2.1 $
- * $Date: 2001/08/10 22:27:12 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v
1.1.1.1.2.2 2001/08/13 23:35:29 rwaldhoff Exp $
+ * $Revision: 1.1.1.1.2.2 $
+ * $Date: 2001/08/13 23:35:29 $
*
* ====================================================================
*
@@ -74,6 +74,7 @@
/**
* DELETE Method.
+ * Implements an HTTP DELETE request.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @author <a href="mailto:[EMAIL PROTECTED]">B.C. Holmes</a>
@@ -86,14 +87,15 @@
/**
- * Method constructor.
+ * No-arg constructor.
*/
public DeleteMethod() {
}
/**
- * Method constructor.
+ * Path-setting constructor.
+ * @param path the path to request
*/
public DeleteMethod(String path) {
super(path);
@@ -102,6 +104,10 @@
// ----------------------------------------------------- HttpMethod Methods
+ /**
+ * Returns <tt>"DELETE"</tt>.
+ * @return <tt>"DELETE"</tt>
+ */
public String getName() {
return "DELETE";
}
1.2.2.5 +35 -21
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.2.2.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- GetMethod.java 2001/08/13 17:38:56 1.2.2.4
+++ GetMethod.java 2001/08/13 23:35:29 1.2.2.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
1.2.2.4 2001/08/13 17:38:56 rwaldhoff Exp $
- * $Revision: 1.2.2.4 $
- * $Date: 2001/08/13 17:38:56 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v
1.2.2.5 2001/08/13 23:35:29 rwaldhoff Exp $
+ * $Revision: 1.2.2.5 $
+ * $Date: 2001/08/13 23:35:29 $
*
* ====================================================================
*
@@ -75,6 +75,7 @@
/**
* GET Method.
+ * Implements an HTTP GET request.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @author Sung-Gu Park
@@ -94,7 +95,7 @@
/**
- * Method constructor.
+ * No-arg constructor.
*/
public GetMethod() {
setFollowRedirects(true);
@@ -102,7 +103,8 @@
/**
- * Method constructor.
+ * Path-setting constructor.
+ * @param path the path to request
*/
public GetMethod(String path) {
super(path);
@@ -111,7 +113,9 @@
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param tempDir the directory in which to store temporary files
*/
public GetMethod(String path, String tempDir) {
this(path);
@@ -122,7 +126,10 @@
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param useDisk whether or not to buffer contents to disk
+ * @param tempDir the directory in which to store temporary files
*/
public GetMethod(String path, boolean useDisk, String tempDir) {
this(path);
@@ -134,7 +141,10 @@
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param tempDir the directory in which to store temporary files
+ * @param tempFile the file (under tempDir) to buffer contents to
*/
public GetMethod(String path, String tempDir, String tempFile) {
this(path);
@@ -145,7 +155,11 @@
}
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param useDisk whether or not to buffer contents to disk
+ * @param tempDir the directory in which to store temporary files
+ * @param tempFile the file to buffer contents to
*/
public GetMethod(String path, boolean useDisk, String tempDir,
String tempFile) {
@@ -160,7 +174,9 @@
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param tempFile the file to buffer contents to
*/
public GetMethod(String path, File fileData) {
this(path);
@@ -283,6 +299,10 @@
// --------------------------------------------------------- Public Methods
+ /**
+ * Returns <tt>"GET"</tt>.
+ * @return <tt>"GET"</tt>
+ */
public String getName() {
return "GET";
}
@@ -347,7 +367,11 @@
// ----------------------------------------------------- HttpMethod Methods
- public void readResponseBody(State state, HttpConnection conn) throws
IOException {
+ /**
+ * Overrides method in {@link HttpMethodBase} to
+ * write data to the appropriate buffer.
+ */
+ protected void readResponseBody(State state, HttpConnection conn) throws
IOException {
log.debug("GetMethod.readResponseBody(State,HttpConnection)");
OutputStream out = null;
if (useDisk) {
@@ -418,15 +442,5 @@
out.close();
}
-
- /**
- * 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() {
- return false;
- }
-
}
1.3.2.3 +14 -22
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.3.2.2
retrieving revision 1.3.2.3
diff -u -r1.3.2.2 -r1.3.2.3
--- HeadMethod.java 2001/08/13 17:38:56 1.3.2.2
+++ HeadMethod.java 2001/08/13 23:35:29 1.3.2.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
1.3.2.2 2001/08/13 17:38:56 rwaldhoff Exp $
- * $Revision: 1.3.2.2 $
- * $Date: 2001/08/13 17:38:56 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v
1.3.2.3 2001/08/13 23:35:29 rwaldhoff Exp $
+ * $Revision: 1.3.2.3 $
+ * $Date: 2001/08/13 23:35:29 $
*
* ====================================================================
*
@@ -85,7 +85,7 @@
/**
- * Method constructor.
+ * No-arg constructor.
*/
public HeadMethod() {
setFollowRedirects(true);
@@ -93,7 +93,8 @@
/**
- * Method constructor.
+ * Path-setting constructor.
+ * @param path the path to request
*/
public HeadMethod(String path) {
super(path);
@@ -113,32 +114,23 @@
// --------------------------------------------------- WebdavMethod Methods
+ /**
+ * Returns <tt>"HEAD"</tt>.
+ * @return <tt>"HEAD"</tt>
+ */
public String getName() {
return "HEAD";
}
/**
- * 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
+ * Overrides {@link HttpMethodBase} method to
+ * <i>not</i> read a response body, despite the
+ * presence of a <tt>Content-Length</tt> or
+ * <tt>Transfer-Encoding</tt> header.
*/
- public boolean needContentLength() {
- return false;
- }
-
protected void readResponseBody(State state, HttpConnection conn) throws
IOException, HttpException {
log.debug("HeadMethod.readResponseBody(State,HttpConnection)");
return; // despite the possible presence of a content-length header, HEAD
returns no response body
}
-
- /**
- * Return true if the method's response is expected to have a body.
- *
- * @return true if a response body should be expected by the client
- */
- public boolean hasResponseBody() {
- return false;
- }
-
}
1.3.2.5 +77 -27
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
Index: PostMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -u -r1.3.2.4 -r1.3.2.5
--- PostMethod.java 2001/08/13 22:37:12 1.3.2.4
+++ PostMethod.java 2001/08/13 23:35:29 1.3.2.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
1.3.2.4 2001/08/13 22:37:12 rwaldhoff Exp $
- * $Revision: 1.3.2.4 $
- * $Date: 2001/08/13 22:37:12 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
1.3.2.5 2001/08/13 23:35:29 rwaldhoff Exp $
+ * $Revision: 1.3.2.5 $
+ * $Date: 2001/08/13 23:35:29 $
* ====================================================================
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -34,35 +34,35 @@
// ----------------------------------------------------------- Constructors
-
/**
- * Method constructor.
+ * No-arg constructor.
*/
public PostMethod() {
super();
}
-
/**
- * Method constructor.
+ * Path-setting constructor.
+ * @param path the path to request
*/
public PostMethod(String path) {
super(path);
}
-
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param tempDir directory to store temp files in
*/
public PostMethod(String path, String tempDir) {
super(path, tempDir);
}
-
-
-
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param useDisk whether or not to buffer temporary data to disk
+ * @param tempDir directory to store temp files in
*/
public PostMethod(String path, boolean useDisk, String tempDir) {
super(path, useDisk, tempDir);
@@ -70,7 +70,11 @@
/**
- * Method constructor.
+ * Constructor.
+ * @param path the path to request
+ * @param useDisk whether or not to buffer temporary data to disk
+ * @param tempDir directory to store temp files in
+ * @param tempFile file to store temporary data in
*/
public PostMethod(String path, boolean useDisk, String tempDir,
String tempFile) {
@@ -79,16 +83,30 @@
// ----------------------------------------------------- HttpMethod Methods
+ /**
+ * Returns <tt>"POST"</tt>.
+ * @return <tt>"POST"</tt>
+ */
public String getName() {
return "POST";
}
-
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to clear my request body.
+ */
public void recycle() {
super.recycle();
requestBody = null;
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to throw {@link IllegalStateException} if
+ * my request body has already been generated.
+ *
+ * @throws IllegalStateException if my request body has already been generated.
+ */
public void setParameter(String parameterName, String parameterValue) {
if(null != requestBody) {
throw new IllegalStateException("Request body already generated.");
@@ -96,6 +114,13 @@
super.setParameter(parameterName,parameterValue);
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to throw {@link IllegalStateException} if
+ * my request body has already been generated.
+ *
+ * @throws IllegalStateException if my request body has already been generated.
+ */
public void addParameter(String parameterName, String parameterValue) {
if(null != requestBody) {
throw new IllegalStateException("Request body already generated.");
@@ -103,6 +128,13 @@
super.addParameter(parameterName,parameterValue);
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to throw {@link IllegalStateException} if
+ * my request body has already been generated.
+ *
+ * @throws IllegalStateException if my request body has already been generated.
+ */
public void removeParameter(String paramName) {
if(null != requestBody) {
throw new IllegalStateException("Request body already generated.");
@@ -110,6 +142,13 @@
super.removeParameter(paramName);
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to throw {@link IllegalStateException} if
+ * my request body has already been generated.
+ *
+ * @throws IllegalStateException if my request body has already been generated.
+ */
public void removeParameter(String paramName, String paramValue) {
if(null != requestBody) {
throw new IllegalStateException("Request body already generated.");
@@ -117,6 +156,11 @@
super.removeParameter(paramName,paramValue);
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to not send request parameters
+ * as part of the query string.
+ */
protected void writeRequestLine(State state, HttpConnection conn) throws
IOException, HttpException {
// don't send parameters on query string
log.debug("PostMethod.writeRequestLine(State,HttpConnection)");
@@ -124,6 +168,11 @@
conn.print(requestLine);
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to also add <tt>Content-Type</tt> header
+ * when appropriate.
+ */
protected void generateRequestHeaders(State state, HttpConnection conn) throws
IOException, HttpException {
super.generateRequestHeaders(state,conn);
if(!parameters.isEmpty()) {
@@ -131,6 +180,11 @@
}
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to write request parameters as the
+ * request body.
+ */
protected boolean writeRequestBody(State state, HttpConnection conn) throws
IOException, HttpException {
log.debug("PostMethod.writeRequestBody(State,HttpConnection)");
if(null == requestBody) {
@@ -140,6 +194,14 @@
return true;
}
+ /**
+ * Override method of {@link HttpMethodBase}
+ * to return the length of the request body.
+ *
+ * Once this method has been invoked,
+ * the request parameters cannot be altered
+ * until I am {@link #recycle recycled}.
+ */
protected int getRequestContentLength() {
if(null == requestBody) {
requestBody = generateRequestBody(parameters);
@@ -179,18 +241,6 @@
} else {
return "";
}
- }
-
- /**
- * from RFC1945:<BR>
- * A valid Content-Length is required on all HTTP/1.0 POST requests. An
- * HTTP/1.0 server should respond with a 400 (bad request) message if it
- * cannot determine the length of the request message's content.
- *
- * @return true
- */
- public boolean needContentLength() {
- return true;
}
protected String requestBody = null;
1.3.2.5 +32 -13
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -u -r1.3.2.4 -r1.3.2.5
--- PutMethod.java 2001/08/13 22:37:12 1.3.2.4
+++ PutMethod.java 2001/08/13 23:35:29 1.3.2.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.3.2.4 2001/08/13 22:37:12 rwaldhoff Exp $
- * $Revision: 1.3.2.4 $
- * $Date: 2001/08/13 22:37:12 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.3.2.5 2001/08/13 23:35:29 rwaldhoff Exp $
+ * $Revision: 1.3.2.5 $
+ * $Date: 2001/08/13 23:35:29 $
*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -44,14 +44,15 @@
/**
- * Method constructor.
+ * No-arg constructor.
*/
public PutMethod() {
}
/**
- * Method constructor.
+ * Path-setting constructor.
+ * @param path the path to request
*/
public PutMethod(String path) {
super(path);
@@ -81,13 +82,17 @@
// --------------------------------------------------------- Public Methods
+ /**
+ * Return <tt>"PUT"</tt>.
+ * @return <tt>"PUT"</tt>
+ */
public String getName() {
return "PUT";
}
/**
* Send the contents of a file.
- * @deprecated
+ * @deprecated use {@link #setData} instead
*/
public void sendData(File file) throws IOException {
setData(file);
@@ -95,7 +100,6 @@
/**
* Send the contents of a file.
- * @deprecated
*/
public void setData(File file) throws IOException {
checkNotUsed();
@@ -104,7 +108,7 @@
/**
* Send the contents of the resource at the specified URL.
- * @deprecated
+ * @deprecated use {@link #setData} instead
*/
public void sendData(URL url) throws IOException {
sendData(url);
@@ -112,7 +116,6 @@
/**
* Send the contents of the resource at the specified URL.
- * @deprecated
*/
public void setData(URL url) throws IOException {
checkNotUsed();
@@ -122,7 +125,7 @@
/**
* Send the contents of a byte array.
- * @deprecated
+ * @deprecated use {@link #setData} instead
*/
public void sendData(byte[] data) {
setData(data);
@@ -138,7 +141,7 @@
/**
* Send the contents of a string.
- * @deprecated
+ * @deprecated use {@link #setData} instead
*/
public void sendData(String data) {
setData(data);
@@ -156,7 +159,7 @@
* Send the contents of an input stream. The contents will be buffered into
* memory. To upload large entities, it is recommended to first buffer the
* data into a temporary file, and then send that file.
- * @deprecated
+ * @deprecated use {@link #setData} instead
*/
public void sendData(InputStream is) throws IOException {
setData(is);
@@ -183,8 +186,14 @@
}
- // ----------------------------------------------------- HttpMethod Methods
+ // ------------------------------------------------- HttpMethodBase Methods
+ /**
+ * Override the method of {@link HttpMethodBase}
+ * to set the <tt>Expect</tt> header if it has
+ * not already been set, in addition to the "standard"
+ * set of headers.
+ */
protected void generateRequestHeaders(State state, HttpConnection conn) throws
IOException, HttpException {
super.generateRequestHeaders(state,conn);
// Send expectation header
@@ -193,6 +202,12 @@
}
}
+ /**
+ * Override the method of {@link HttpMethodBase}
+ * to not send any data until
+ * the <tt>100 Continue</tt> status has not be
+ * read.
+ */
protected boolean writeRequestBody(State state, HttpConnection conn) throws
IOException, HttpException {
if(requestHeaders.containsKey("expect") && statusCode !=
HttpStatus.SC_CONTINUE) {
return false;
@@ -227,6 +242,10 @@
return true;
}
+ /**
+ * Override the method of {@link HttpMethodBase}
+ * to return the appropriate content length.
+ */
protected int getRequestContentLength() {
if(null != data) {
return data.length;
No revision
No revision
1.10.2.9 +31 -10
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.10.2.8
retrieving revision 1.10.2.9
diff -u -r1.10.2.8 -r1.10.2.9
--- HttpMethodBase.java 2001/08/13 23:04:21 1.10.2.8
+++ HttpMethodBase.java 2001/08/13 23:35:30 1.10.2.9
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.10.2.8 2001/08/13 23:04:21 rwaldhoff Exp $
- * $Revision: 1.10.2.8 $
- * $Date: 2001/08/13 23:04:21 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.10.2.9 2001/08/13 23:35:30 rwaldhoff Exp $
+ * $Revision: 1.10.2.9 $
+ * $Date: 2001/08/13 23:35:30 $
* ====================================================================
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -31,20 +31,41 @@
/**
* An abstract base implementation of {@link HttpMethod}.
* <p>
- * Subclasses will typcially want to override:
- * <dl>
+ * At minimum, subclasses will need to override
+ * <ul><dl>
* <dt>{@link #getName}</dt>
* <dd>to return the approriate name for this method</dd>
+ * </dl></ul>
+ * When a method's request may contain a body,
+ * subclasses will typically want to override:
+ * <ul><dl>
* <dt>{@link #getRequestContentLength}</dt>
- * <dd>when the request may have a body</dd>
+ * <dd>to indicate the length (in bytes) of that body</dd>
* <dt>{@link #writeRequestBody}</dt>
- * <dd>when the request may have a body</dd>
- * <dt>...</dt>
- * </dl>
+ * <dd>to write the body</dd>
+ * </dl></ul>
+ * When a method's response may contain a body,
+ * subclasses may want to override:
+ * <ul><dl>
+ * <dt>{@link #readResponseBody}</dt>
+ * <dd>to do something useful with the returned data</dd>
+ * </dl></ul>
+ * When a method requires additional request headers,
+ * subclasses will typically want to override:
+ * <ul><dl>
+ * <dt>{@link #generateRequestHeaders}</dt>
+ * <dd>to write those headers</dd>
+ * </dl></ul>
+ * When a method expects specific response headers,
+ * subclasses may want to override:
+ * <ul><dl>
+ * <dt>{@link #processResponseHeaders}</dt>
+ * <dd>to handle those headers</dd>
+ * </dl></ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @author Rodney Waldhoff
- * @version $Id: HttpMethodBase.java,v 1.10.2.8 2001/08/13 23:04:21 rwaldhoff Exp $
+ * @version $Id: HttpMethodBase.java,v 1.10.2.9 2001/08/13 23:35:30 rwaldhoff Exp $
*/
public abstract class HttpMethodBase implements HttpMethod {