org.apache.commons.httpclient
Interface HttpMethod

All Known Subinterfaces:
HttpUrlMethod
All Known Implementing Classes:
HttpMethodBase, UrlDeleteMethod, UrlGetMethod, UrlHeadMethod, UrlOptionsMethod, UrlPostMethod, UrlPutMethod

public interface HttpMethod

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

Since:
1.0
Version:
$Revision: 1.22 $ $Date: 2003/01/23 22:47:46 $
Author:
Remy Maucherat, Rod Waldhoff, Jeff Dever

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.
 void addResponseFooter(Header footer)
          Use this method internally to add footers.
 int execute(HttpState state, HttpConnection connection)
          Execute this method.
 boolean getDoAuthentication()
          Whether or not I should automatically process responses where authentication is required (status code 401, etc.)
 boolean getFollowRedirects()
          Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 HostConfiguration getHostConfiguration()
          Gets the host configuration for this method.
 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 getResponseFooter(java.lang.String footerName)
          Return the specified response footer.
 Header[] getResponseFooters()
          Return an array of my response footers
 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.
 StatusLine getStatusLine()
          Return the Status-Line from the response.
 java.lang.String getStatusText()
          Return the status text (or "reason phrase") associated with the latest response.
 URI getURI()
          Gets the URI for this method.
 boolean hasBeenUsed()
          Return true if I have been executed but not recycled.
 boolean isStrictMode()
          Returns the value of strictMode.
 void recycle()
          Recycle this method so that it can be used again.
 void releaseConnection()
          Releases the connection being used by this method.
 void removeRequestHeader(java.lang.String headerName)
          Remove all request headers associated with the given name.
 void setDoAuthentication(boolean doAuthentication)
          Set whether or not I should automatically process responses where authentication is required (status code 401, etc.)
 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.
 void setStrictMode(boolean strictMode)
          Turns strict mode on or off.
 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

getHostConfiguration

public HostConfiguration getHostConfiguration()
Gets the host configuration for this method.

Returns:
the HostConfiguration or null if none is set

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. Calling this method AFTER the request has been executed will return the ACTUAL path, following any 301 or 302 redirects (except for redirects off the initial server, which are not supported, or when HttpClient is set to not follow redirects; in either case, HttpClient returns the 301 or 302 status code).

Returns:
the path to request

getURI

public URI getURI()
           throws URIException
Gets the URI for this method. The URI will be absolute if the host configuration has been set or relative otherwise.

Returns:
URI
Throws:
URIException - if a URI cannot be constructed

setStrictMode

public void setStrictMode(boolean strictMode)
Turns strict mode on or off. In strict mode (the default) we following the letter of RFC 2616, the Http 1.1 specification. If strict mode is turned off we attempt to violate the specification in the same way that most Http user agent's do (and many HTTP servers expect. NOTE: StrictMode is currently experimental and its functionlaity may change in the future.


isStrictMode

public boolean isStrictMode()
Returns the value of strictMode. NOTE: StrictMode is currently experimental and its functionlaity may change in the future.

Returns:
true if strict mode is enabled.

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

getFollowRedirects

public boolean getFollowRedirects()
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.


getResponseFooters

public Header[] getResponseFooters()
Return an array of my response footers

Returns:
null if no footers are available

getResponseFooter

public Header getResponseFooter(java.lang.String footerName)
Return the specified response footer. Note that footer-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.

java.io.IOException

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.


releaseConnection

public void releaseConnection()
Releases the connection being used by this method. In particular the connection is used to read the response(if there is one) and will be held until the response has been read.


addResponseFooter

public void addResponseFooter(Header footer)
Use this method internally to add footers.

Since:
2.0

getStatusLine

public StatusLine getStatusLine()
Return the Status-Line from the response.

Since:
2.0

getDoAuthentication

public boolean getDoAuthentication()
Whether or not I should automatically process responses where authentication is required (status code 401, etc.)

Returns:
true if authentications will be processed automatically
Since:
2.0

setDoAuthentication

public void setDoAuthentication(boolean doAuthentication)
Set whether or not I should automatically process responses where authentication is required (status code 401, etc.)

Parameters:
doAuthentication - true to process authentications
Since:
2.0


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