org.apache.commons.httpclient
Interface HttpMethod

All Known Implementing Classes:
HttpMethodBase

public interface HttpMethod

A request to be applied to an HttpConnection, and a container for the associated response.

Version:
$Revision: 1.8 $ $Date: 2001/10/04 17:49:12 $
Author:
Remy Maucherat, Rod Waldhoff

Method Summary
 void addRequestHeader(Header header)
          Adds the specified request header, NOT overwriting any previous value.
 void addRequestHeader(java.lang.String headerName, java.lang.String headerValue)
          Adds the specified request header, NOT overwriting any previous value.
 int execute(HttpState state, HttpConnection connection)
          Execute this method.
 boolean followRedirects()
          Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 java.lang.String getName()
          Obtain the name of this method, suitable for use in the "request line", for example "GET" or "POST".
 java.lang.String getPath()
          Get the path part of my request.
 java.lang.String getQueryString()
          Get my query string.
 Header getRequestHeader(java.lang.String headerName)
          Get the request header associated with the given name.
 Header[] getRequestHeaders()
          Return an array of my request headers.
 byte[] getResponseBody()
          Return my response body, if any, as a byte array.
 java.io.InputStream getResponseBodyAsStream()
          Return my response body, if any, as an InputStream.
 java.lang.String getResponseBodyAsString()
          Return my response body, if any, as a String.
 Header getResponseHeader(java.lang.String headerName)
          Return the specified response header.
 Header[] getResponseHeaders()
          Return an array of my response headers.
 int getStatusCode()
          Return the status code associated with the latest response.
 java.lang.String getStatusText()
          Return the status text (or "reason phrase") associated with the latest response.
 boolean hasBeenUsed()
          Return true if I have been executed but not recycled.
 void recycle()
          Recycle this method so that it can be used again.
 void removeRequestHeader(java.lang.String headerName)
          Remove all request headers associated with the given name.
 void setFollowRedirects(boolean followRedirects)
          Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 void setPath(java.lang.String path)
          Set the path part of my request.
 void setQueryString(NameValuePair[] params)
          Set my query string.
 void setQueryString(java.lang.String queryString)
          Set my query string.
 void setRequestHeader(Header header)
          Set the specified request header, overwriting any previous value.
 void setRequestHeader(java.lang.String headerName, java.lang.String headerValue)
          Set the specified request header, overwriting any previous value.
 boolean validate()
          Confirm that I am ready to execute.
 

Method Detail

getName

public java.lang.String getName()
Obtain the name of this method, suitable for use in the "request line", for example "GET" or "POST".
Returns:
the name of this method

setPath

public void setPath(java.lang.String path)
Set the path part of my request.
Parameters:
path - the path to request

getPath

public java.lang.String getPath()
Get the path part of my request.
Returns:
the path to request

setRequestHeader

public void setRequestHeader(java.lang.String headerName,
                             java.lang.String headerValue)
Set the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
headerName - the header's name
headerValue - the header's value

setRequestHeader

public void setRequestHeader(Header header)
Set the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
header - the header

addRequestHeader

public void addRequestHeader(java.lang.String headerName,
                             java.lang.String headerValue)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
headerName - the header's name
headerValue - the header's value

addRequestHeader

public void addRequestHeader(Header header)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
header - the header

getRequestHeader

public Header getRequestHeader(java.lang.String headerName)
Get the request header associated with the given name. Note that header-name matching is case insensitive.
Parameters:
headerName - the header name
Returns:
the header

removeRequestHeader

public void removeRequestHeader(java.lang.String headerName)
Remove all request headers associated with the given name. Note that header-name matching is case insensitive.
Parameters:
headerName - the header name
Returns:
the header

followRedirects

public boolean followRedirects()
Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
Returns:
true if I will automatically follow HTTP redirects

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)

setQueryString

public void setQueryString(java.lang.String queryString)
Set my query string.
Parameters:
queryString - the query string

setQueryString

public void setQueryString(NameValuePair[] params)
Set my query string.
Parameters:
params - an array of NameValuePairs to add as query string parameterss

getQueryString

public java.lang.String getQueryString()
Get my query string.
Returns:
my query string

getRequestHeaders

public Header[] getRequestHeaders()
Return an array of my request headers.

validate

public boolean validate()
Confirm that I am ready to execute.

getStatusCode

public int getStatusCode()
Return the status code associated with the latest response.

getStatusText

public java.lang.String getStatusText()
Return the status text (or "reason phrase") associated with the latest response.

getResponseHeaders

public Header[] getResponseHeaders()
Return an array of my response headers.

getResponseHeader

public Header getResponseHeader(java.lang.String headerName)
Return the specified response header. Note that header-name matching is case insensitive.

getResponseBody

public byte[] getResponseBody()
Return my response body, if any, as a byte array. Otherwise return null.

getResponseBodyAsString

public java.lang.String getResponseBodyAsString()
Return my response body, if any, as a String. Otherwise return null.

getResponseBodyAsStream

public java.io.InputStream getResponseBodyAsStream()
                                            throws java.io.IOException
Return my response body, if any, as an InputStream. Otherwise return null.

hasBeenUsed

public boolean hasBeenUsed()
Return true if I have been executed but not recycled.

execute

public int execute(HttpState state,
                   HttpConnection connection)
            throws HttpException,
                   java.io.IOException
Execute this method.
Parameters:
state - state information to associate with this request
connection - the HttpConnection to write to/read from
Returns:
the integer status code if one was obtained, or -1
Throws:
java.io.IOException - if an I/O error occurs
HttpException - if an protocol exception occurs

recycle

public void recycle()
Recycle this method so that it can be used again. Note that all of my instance variables will be reset once this method has been called.


Copyright (c) 2001 - Apache Software Foundation