org.apache.commons.httpclient.methods
Class GetMethod

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpMethodBase
        |
        +--org.apache.commons.httpclient.methods.GetMethod
Direct Known Subclasses:
ExpectContinueMethod, UrlGetMethod

public class GetMethod
extends HttpMethodBase

Implements the HTTP GET method.

The HTTP GET method is defined in section 9.3 of RFC2616:

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

GetMethods will follow redirect requests from the http server by default. This behavour can be disabled by calling setFollowRedirects(false).

The useDisk methods have been deprecated. Disk I/O is the responsibility of the client. If you need to write a response body to a file, you can use the following as an example:

     out = new FileOutputStream(myFile);
     InputStream in = getResponseBodyAsStream();
     byte[] buffer = new byte[10000];
     int len ;
     while ((len = in.read(buffer)) > 0) {
        out.write(buffer, 0, len);
     }
     in.close();
     out.close();
 

Since:
1.0
Version:
$Revision: 1.24.2.1 $
Author:
Remy Maucherat, Sung-Gu Park, Sean C. Sullivan, Mike Bowler, Jeff Dever

Fields inherited from class org.apache.commons.httpclient.HttpMethodBase
USER_AGENT
 
Constructor Summary
GetMethod()
          No-arg constructor.
GetMethod(java.lang.String uri)
          Constructor specifying a URI.
GetMethod(java.lang.String path, java.io.File fileData)
          Deprecated. the client is responsible for disk I/O
GetMethod(java.lang.String path, java.lang.String tempDir)
          Deprecated. the client is responsible for disk I/O
GetMethod(java.lang.String path, java.lang.String tempDir, java.lang.String tempFile)
          Deprecated. the client is responsible for disk I/O
 
Method Summary
 java.io.File getFileData()
          Deprecated. the client is responsible for disk I/O
 java.lang.String getName()
          Returns "GET".
 java.lang.String getTempDir()
          Deprecated. the client is responsible for disk I/O
 java.lang.String getTempFile()
          Deprecated. the client is responsible for disk I/O
 boolean getUseDisk()
          Deprecated. the client is responsible for disk I/O
protected  void readResponseBody(HttpState state, HttpConnection conn)
          Overrides method in HttpMethodBase to write data to the appropriate buffer.
 void recycle()
          Recycles the HTTP method so that it can be used again.
 void setFileData(java.io.File fileData)
          Deprecated. the client is responsible for disk I/O
 void setTempDir(java.lang.String tempDir)
          Deprecated. the client is responsible for disk I/O
 void setTempFile(java.lang.String tempFile)
          Deprecated. the client is responsible for disk I/O
 void setUseDisk(boolean useDisk)
          Deprecated. the client is responsible for disk I/O
 
Methods inherited from class org.apache.commons.httpclient.HttpMethodBase
addAuthorizationRequestHeader, addContentLengthRequestHeader, addCookieRequestHeader, addHostRequestHeader, addProxyAuthorizationRequestHeader, addProxyConnectionHeader, addRequestHeader, addRequestHeader, addRequestHeaders, addResponseFooter, addUserAgentRequestHeader, checkNotUsed, checkUsed, execute, fakeResponse, generateRequestLine, getAuthenticationRealm, getContentCharSet, getDoAuthentication, getFollowRedirects, getHostConfiguration, getMethodRetryHandler, getPath, getProxyAuthenticationRealm, getQueryString, getRecoverableExceptionCount, getRequestCharSet, getRequestContentLength, getRequestHeader, getRequestHeaderGroup, getRequestHeaders, getResponseBody, getResponseBodyAsStream, getResponseBodyAsString, getResponseCharSet, getResponseContentLength, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaderGroup, getResponseHeaders, getResponseStream, getResponseTrailerHeaderGroup, getStatusCode, getStatusLine, getStatusText, getURI, hasBeenUsed, isConnectionCloseForced, isHttp11, isStrictMode, processResponseBody, processResponseHeaders, processStatusLine, readResponse, readResponseHeaders, readStatusLine, releaseConnection, removeRequestHeader, responseBodyConsumed, setConnectionCloseForced, setDoAuthentication, setFollowRedirects, setHostConfiguration, setHttp11, setMethodRetryHandler, setPath, setQueryString, setQueryString, setRequestHeader, setRequestHeader, setResponseStream, setStrictMode, shouldCloseConnection, validate, writeRequest, writeRequestBody, writeRequestHeaders, writeRequestLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GetMethod

public GetMethod()
No-arg constructor.
Since:
1.0

GetMethod

public GetMethod(java.lang.String uri)
Constructor specifying a URI.
Parameters:
uri - either an absolute or relative URI
Since:
1.0

GetMethod

public GetMethod(java.lang.String path,
                 java.lang.String tempDir)
Deprecated. the client is responsible for disk I/O

Constructor.
Parameters:
path - the path to request
tempDir - the directory in which to store temporary files
Since:
1.0

GetMethod

public GetMethod(java.lang.String path,
                 java.lang.String tempDir,
                 java.lang.String tempFile)
Deprecated. the client is responsible for disk I/O

Constructor.
Parameters:
path - the path to request
tempDir - the directory in which to store temporary files
tempFile - the file (under tempDir) to buffer contents to
Since:
1.0

GetMethod

public GetMethod(java.lang.String path,
                 java.io.File fileData)
Deprecated. the client is responsible for disk I/O

Constructor.
Parameters:
path - the path to request
fileData - the file to buffer contents to
Since:
1.0
Method Detail

setFileData

public void setFileData(java.io.File fileData)
Deprecated. the client is responsible for disk I/O

File data setter.
Parameters:
fileData - the file to buffer data to
Since:
1.0

getFileData

public java.io.File getFileData()
Deprecated. the client is responsible for disk I/O

File data getter.
Returns:
the file being used for buffering data
Since:
1.0

getName

public java.lang.String getName()
Returns "GET".
Overrides:
getName in class HttpMethodBase
Returns:
"GET"
Since:
2.0

setTempDir

public void setTempDir(java.lang.String tempDir)
Deprecated. the client is responsible for disk I/O

Temporary directory setter.
Parameters:
tempDir - New value of tempDir
Since:
1.0

getTempDir

public java.lang.String getTempDir()
Deprecated. the client is responsible for disk I/O

Temporary directory getter.
Returns:
the current temporary directory
Since:
1.0

setTempFile

public void setTempFile(java.lang.String tempFile)
Deprecated. the client is responsible for disk I/O

Temporary file setter.
Parameters:
tempFile - New value of tempFile
Since:
1.0

getTempFile

public java.lang.String getTempFile()
Deprecated. the client is responsible for disk I/O

Temporary file getter.
Returns:
the current temporary file
Since:
1.0

setUseDisk

public void setUseDisk(boolean useDisk)
Deprecated. the client is responsible for disk I/O

Buffer the response in a file or not. The default is false.
Parameters:
useDisk - If true the entire response will be buffered in a temporary file.
Since:
1.0

getUseDisk

public boolean getUseDisk()
Deprecated. the client is responsible for disk I/O

Tells if the response will be buffered in a file.
Returns:
true if the response will be buffered
Since:
1.0

recycle

public void recycle()
Recycles the HTTP method so that it can be used again. Note that all of the instance variables will be reset once this method has been called. This method will also release the connection being used by this HTTP method.
Overrides:
recycle in class HttpMethodBase
Since:
1.0
See Also:
HttpMethodBase.releaseConnection()

readResponseBody

protected void readResponseBody(HttpState state,
                                HttpConnection conn)
                         throws java.io.IOException,
                                HttpException
Overrides method in HttpMethodBase to write data to the appropriate buffer.
Overrides:
readResponseBody in class HttpMethodBase
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
java.io.IOException - if an I/O (transport) error occurs
HttpException - if a protocol exception occurs.
HttpRecoverableException - if a recoverable transport error occurs. Usually this kind of exceptions can be recovered from by retrying the HTTP method
Since:
2.0
See Also:
HttpMethodBase.readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), HttpMethodBase.processResponseBody(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)


Copyright © 2001-2004 Apache Software Foundation. All Rights Reserved.