org.apache.commons.httpclient
Interface HttpMethod

All Known Subinterfaces:
HttpUrlMethod
All Known Implementing Classes:
HttpMethodBase

public interface HttpMethod

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

Since:
1.0
Version:
$Revision: 1.23 $ $Date: 2003/01/28 04:40:20 $
Author:
Remy Maucherat, Rod Waldhoff, Jeff Dever, Mike Bowler

Method Summary
 void addRequestHeader(Header header)
          Adds the specified request header, NOT overwriting any previous value.
 void addRequestHeader(String headerName, 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.
 String getName()
          Obtain the name of this method, suitable for use in the "request line", for example "GET" or "POST".
 String getPath()
          Get the path part of my request.
 String getQueryString()
          Get my query string.
 Header getRequestHeader(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.
 InputStream getResponseBodyAsStream()
          Return my response body, if any, as an InputStream.
 String getResponseBodyAsString()
          Return my response body, if any, as a String.
 Header getResponseFooter(String footerName)
          Return the specified response footer.
 Header[] getResponseFooters()
          Return an array of my response footers
 Header getResponseHeader(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.
 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(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(String path)
          Set the path part of my request.
 void setQueryString(NameValuePair[] params)
          Set my query string.
 void setQueryString(String queryString)
          Set my query string.
 void setRequestHeader(Header header)
          Set the specified request header, overwriting any previous value.
 void setRequestHeader(String headerName, 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 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(String path)
Set the path part of my request.
Parameters:
path - the path to request

getPath

public 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 functionaity may change in the future.

Parameters:
strictMode - True to enable strict mode.

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(String headerName,
                             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(String headerName,
                             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(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(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.)
Parameters:
followRedirects - True if I should automatically follow redirects.

setQueryString

public void setQueryString(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 String getQueryString()
Get my query string.
Returns:
my query string

getRequestHeaders

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

validate

public boolean validate()
Confirm that I am ready to execute.
Returns:
True if I am ready to execute.

getStatusCode

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

getStatusText

public String getStatusText()
Return the status text (or "reason phrase") associated with the latest response.
Returns:
The status text.

getResponseHeaders

public Header[] getResponseHeaders()
Return an array of my response headers.
Returns:
An array of all the response headers.

getResponseHeader

public Header getResponseHeader(String headerName)
Return the specified response header. Note that header-name matching is case insensitive.
Parameters:
headerName - The name of the header to be returned.
Returns:
The specified response header.

getResponseFooters

public Header[] getResponseFooters()
Return an array of my response footers
Returns:
null if no footers are available

getResponseFooter

public Header getResponseFooter(String footerName)
Return the specified response footer. Note that footer-name matching is case insensitive.
Parameters:
footerName - The name of the footer.
Returns:
The response footer.

getResponseBody

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

getResponseBodyAsString

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

getResponseBodyAsStream

public InputStream getResponseBodyAsStream()
                                    throws IOException
Return my response body, if any, as an InputStream. Otherwise return null.
Returns:
As above.
Throws:
IOException - If an IO problem occurs.

hasBeenUsed

public boolean hasBeenUsed()
Return true if I have been executed but not recycled.
Returns:
true if this has been used.

execute

public int execute(HttpState state,
                   HttpConnection connection)
            throws HttpException,
                   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:
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.
Parameters:
footer - The footer to add.
Since:
2.0

getStatusLine

public StatusLine getStatusLine()
Return the Status-Line from the response.
Returns:
The status line
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.