org.apache.commons.httpclient
Class HttpMethodBase

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpMethodBase
All Implemented Interfaces:
HttpMethod
Direct Known Subclasses:
ConnectMethod, DeleteMethod, GetMethod, HeadMethod, OptionsMethod, PutMethod, TraceMethod

public abstract class HttpMethodBase
extends java.lang.Object
implements HttpMethod

An abstract base implementation of HttpMethod.

At minimum, subclasses will need to override

getName()
to return the approriate name for this method

When a method's request may contain a body, subclasses will typically want to override:

getRequestContentLength()
to indicate the length (in bytes) of that body
writeRequestBody(HttpState,HttpConnection)
to write the body

When a method requires additional request headers, subclasses will typically want to override:

addRequestHeaders(HttpState,HttpConnection)
to write those headers

When a method expects specific response headers, subclasses may want to override:

processResponseHeaders(HttpState,HttpConnection)
to handle those headers

Version:
$Revision: 1.55 $ $Date: 2002/09/03 11:19:35 $
Author:
Remy Maucherat, Rodney Waldhoff, Sean C. Sullivan, dIon Gillard, Jeff Dever, Davanum Srinivas, Ortwin Glück

Field Summary
protected static Header USER_AGENT
          The User-Agent header sent on every request.
 
Constructor Summary
HttpMethodBase()
          No-arg constructor.
HttpMethodBase(java.lang.String path)
          Path-specifying constructor.
 
Method Summary
protected  void addAuthorizationRequestHeader(HttpState state, HttpConnection conn)
          Adds an Authorization request if needed, as long as no Authorization request header already exists.
protected  void addContentLengthRequestHeader(HttpState state, HttpConnection conn)
          Adds a Content-Length or Transer-Encoding: Chunked request header, as long as no Content-Length request header already exists.
protected  void addCookieRequestHeader(HttpState state, HttpConnection conn)
          Adds a Cookie request containing the matching Cookies.
protected  void addHostRequestHeader(HttpState state, HttpConnection conn)
          Adds a Host request header, as long as no Host request header already exists.
protected  void addProxyAuthorizationRequestHeader(HttpState state, HttpConnection conn)
          Adds a Proxy-Authorization request if needed, as long as no Proxy-Authorization request header already exists.
 void addRequestHeader(Header header)
          Add the specified request header.
 void addRequestHeader(java.lang.String headerName, java.lang.String headerValue)
          Add the specified request header, NOT overwriting any previous value.
protected  void addRequestHeaders(HttpState state, HttpConnection conn)
          Populates the request headers map to with additional headers to be submitted to the given HttpConnection.
 void addResponseFooter(Header footer)
          adds a response footer to the internal list
protected  void addUserAgentRequestHeader(HttpState state, HttpConnection conn)
          Adds a default User-Agent request header, as long as no User-Agent request header already exists.
protected  void checkNotUsed()
          Throws an IllegalStateException if used but not recycled.
protected  void checkUsed()
          Throws an IllegalStateException if not used since last recycle.
 int execute(HttpState state, HttpConnection conn)
          Execute this method.
protected static java.lang.String generateRequestLine(HttpConnection connection, java.lang.String name, java.lang.String reqPath, java.lang.String qString, java.lang.String protocol)
          Generate an HTTP/S request line according to the specified attributes.
 boolean getFollowRedirects()
          Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
abstract  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.
protected  int getRequestContentLength()
          Return the length (in bytes) of my request body, suitable for use in a Content-Length header.
 Header getRequestHeader(java.lang.String headerName)
          Get the request header associated with the given name.
 Header[] getRequestHeaders()
          Provides access to the 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()
          Gets the response body as a string.
 Header getResponseFooter(java.lang.String footerName)
          Get the response footer associated with the given name.
 Header[] getResponseFooters()
          Return an array of response footers.
 Header getResponseHeader(java.lang.String headerName)
          Get the response header associated with the given name.
 Header[] getResponseHeaders()
          Provide access to the response headers
 int getStatusCode()
          Provide access to the status code.
 java.lang.String getStatusText()
          Provide access to the status text
 boolean hasBeenUsed()
          Whether the object has been used and not recycled.
 boolean isHttp11()
          Return true if I should use the HTTP/1.1 protocol.
 boolean isStrictMode()
          Returns the value of strictMode.
protected  void processResponseBody(HttpState state, HttpConnection conn)
          When this method is invoked, readResponseBody(HttpState,HttpConnection) will have been invoked.
protected  void processResponseHeaders(HttpState state, HttpConnection conn)
          When this method is invoked, the response headers map will have been populated with the response headers (in other words, readResponseHeaders(HttpState,HttpConnection) will have been invoked).
protected  void processStatusLine(HttpState state, HttpConnection conn)
          When this method is invoked, the status code and status text values will have been set (in other words, readStatusLine(HttpState,HttpConnection will have been invoked).
protected  void readResponse(HttpState state, HttpConnection conn)
          Reads the response from the given HttpConnection.
protected  void readResponseBody(HttpState state, HttpConnection conn)
          Read the response body from the given HttpConnection.
protected  void readResponseHeaders(HttpState state, HttpConnection conn)
          Read response headers from the given HttpConnection, populating the response headers map.
protected  void readStatusLine(HttpState state, HttpConnection conn)
          Read the status line from the given HttpConnection, setting my status code and status text.
 void recycle()
          Recycle this method so that it can be used again.
 void removeRequestHeader(java.lang.String headerName)
          Remove the request header associated with the given name.
 void setFollowRedirects(boolean followRedirects)
          Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 void setHttp11(boolean http11)
          Set whether or not I should use the HTTP/1.1 protocol.
 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.
protected  void setResponseStream(java.io.InputStream responseStream)
           
 void setStrictMode(boolean strictMode)
          Turns strict mode on or off.
 boolean validate()
          Confirm that I am ready to execute.
protected  void writeRequest(HttpState state, HttpConnection conn)
           Writes my request to the given HttpConnection.
protected  boolean writeRequestBody(HttpState state, HttpConnection conn)
          Write the request body to the given HttpConnection
protected  void writeRequestHeaders(HttpState state, HttpConnection conn)
          Writes the request headers to the given HttpConnection.
protected  void writeRequestLine(HttpState state, HttpConnection conn)
          Writes the "request line" to the given HttpConnection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_AGENT

protected static final Header USER_AGENT
The User-Agent header sent on every request.
Constructor Detail

HttpMethodBase

public HttpMethodBase()
No-arg constructor.

HttpMethodBase

public HttpMethodBase(java.lang.String path)
Path-specifying constructor.
Parameters:
path - my path
Method Detail

getName

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

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)
Specified by:
setFollowRedirects in interface HttpMethod
Parameters:
followRedirects - true to follow redirects, false otherwise

getFollowRedirects

public boolean getFollowRedirects()
Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
Specified by:
getFollowRedirects in interface HttpMethod
Returns:
true if I will automatically follow HTTP redirects

setHttp11

public void setHttp11(boolean http11)
Set whether or not I should use the HTTP/1.1 protocol. internal
Parameters:
http11 - true to use HTTP/1.1, false to use 1.0

isHttp11

public boolean isHttp11()
Return true if I should use the HTTP/1.1 protocol. internal
Returns:
true if I should use the HTTP/1.1 protocol

setPath

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

addRequestHeader

public void addRequestHeader(Header header)
Add the specified request header. If a header of the same name already exists, the new value will be appended onto the the existing value list. A header value of null will be ignored. Note that header-name matching is case insensitive.
Specified by:
addRequestHeader in interface HttpMethod
Parameters:
header - the header to add to the request

addResponseFooter

public void addResponseFooter(Header footer)
adds a response footer to the internal list
Specified by:
addResponseFooter in interface HttpMethod

getPath

public java.lang.String getPath()
Get the path part of my request.
Specified by:
getPath in interface HttpMethod
Returns:
the path to request or "/" if the path is blank.

setQueryString

public void setQueryString(java.lang.String queryString)
Set my query string.
Specified by:
setQueryString in interface HttpMethod
Parameters:
queryString - the query string

setQueryString

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

getQueryString

public java.lang.String getQueryString()
Get my query string.
Specified by:
getQueryString in interface HttpMethod
Returns:
The query string portion of the 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.
Specified by:
setRequestHeader in interface HttpMethod
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.
Specified by:
setRequestHeader in interface HttpMethod
Parameters:
header - the header

getRequestHeader

public Header getRequestHeader(java.lang.String headerName)
Get the request header associated with the given name. Header name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
Specified by:
getRequestHeader in interface HttpMethod
Parameters:
headerName - the header name to match
Returns:
the matching header

getRequestHeaders

public Header[] getRequestHeaders()
Provides access to the request headers.
Specified by:
getRequestHeaders in interface HttpMethod
Returns:
an array of my request headers.

getStatusCode

public int getStatusCode()
Provide access to the status code.
Specified by:
getStatusCode in interface HttpMethod
Returns:
the status code associated with the latest response.

getResponseHeaders

public Header[] getResponseHeaders()
Provide access to the response headers
Specified by:
getResponseHeaders in interface HttpMethod
Returns:
an array of my response headers.

getResponseHeader

public Header getResponseHeader(java.lang.String headerName)
Get the response header associated with the given name. Header name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
Specified by:
getResponseHeader in interface HttpMethod
Parameters:
headerName - the header name to match
Returns:
the matching header

getResponseBody

public byte[] getResponseBody()
Return my response body, if any, as a byte array. Otherwise return null.
Specified by:
getResponseBody in interface HttpMethod

getResponseBodyAsStream

public java.io.InputStream getResponseBodyAsStream()
                                            throws java.io.IOException
Return my response body, if any, as an InputStream. Otherwise return null.
Specified by:
getResponseBodyAsStream in interface HttpMethod
Returns:
the response body as an InputStream
Throws:
java.io.IOException - when there are errors obtaining the response

getResponseBodyAsString

public java.lang.String getResponseBodyAsString()
Gets the response body as a string. Note: The string conversion done on the data is done with the default character encoding. The use of this method may be non-portable.
Specified by:
getResponseBodyAsString in interface HttpMethod
Returns:
my response body, if any, as a String. Otherwise return null.

getResponseFooters

public Header[] getResponseFooters()
Return an array of response footers.
Specified by:
getResponseFooters in interface HttpMethod
Returns:
null if no footers are available

getResponseFooter

public Header getResponseFooter(java.lang.String footerName)
Get the response footer associated with the given name. Footer name matching is case insensitive. null will be returned if either footerName is null or there is no matching header for footerName or there are no footers available.
Specified by:
getResponseFooter in interface HttpMethod
Parameters:
footerName - the footer name to match
Returns:
the matching footer

setResponseStream

protected void setResponseStream(java.io.InputStream responseStream)

getStatusText

public java.lang.String getStatusText()
Provide access to the status text
Specified by:
getStatusText in interface HttpMethod
Returns:
the status text (or "reason phrase") associated with the latest response.

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.
Specified by:
setStrictMode in interface HttpMethod
Parameters:
strictMode - true for strict mode, false otherwise

isStrictMode

public boolean isStrictMode()
Returns the value of strictMode. NOTE: StrictMode is currently experimental and its functionlaity may change in the future.
Specified by:
isStrictMode in interface HttpMethod
Returns:
true if strict mode is enabled.

addRequestHeader

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

execute

public int execute(HttpState state,
                   HttpConnection conn)
            throws HttpException,
                   java.io.IOException,
                   java.lang.NullPointerException
Execute this method. Note that we cannot currently support redirects that change the connection parameters (host, port, protocol) because we don't yet have a good way to get the new connection. For the time being, we just return the redirect response code, and allow the user agent to resubmit if desired.
Specified by:
execute in interface HttpMethod
Parameters:
state - HttpState information to associate with this request. Must be non-null.
conn - theHttpConnection to write to/read from. Must be non-null. Note that we cannot currently support redirects that change the HttpConnection parameters (host, port, protocol) because we don't yet have a good way to get the new connection. For the time being, we just return the 302 response, and allow the user agent to resubmit if desired.
Returns:
the integer status code if one was obtained, or -1
Throws:
HttpException - if an protocol exception occurs
java.io.IOException - if an I/O error occurs
java.lang.NullPointerException - if the state is null

hasBeenUsed

public boolean hasBeenUsed()
Whether the object has been used and not recycled.
Specified by:
hasBeenUsed in interface HttpMethod
Returns:
true if I have been executed but not recycled.

recycle

public void recycle()
Recycle this method so that it can be used again. All of my instances variables will be reset once this method has been called.
Specified by:
recycle in interface HttpMethod

removeRequestHeader

public void removeRequestHeader(java.lang.String headerName)
Remove the request header associated with the given name. Note that header-name matching is case insensitive.
Specified by:
removeRequestHeader in interface HttpMethod
Parameters:
headerName - the header name

validate

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

This implementation always returns true.

Specified by:
validate in interface HttpMethod
Returns:
true

getRequestContentLength

protected int getRequestContentLength()
Return the length (in bytes) of my request body, suitable for use in a Content-Length header.

Return -1 when the content-length is unknown.

This implementation returns 0, indicating that the request has no body.

Returns:
0, indicating that the request has no body.

addAuthorizationRequestHeader

protected void addAuthorizationRequestHeader(HttpState state,
                                             HttpConnection conn)
                                      throws java.io.IOException,
                                             HttpException
Adds an Authorization request if needed, as long as no Authorization request header already exists.
Parameters:
state - current state of http requests
conn - the connection to use for I/O
Throws:
java.io.IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

addContentLengthRequestHeader

protected void addContentLengthRequestHeader(HttpState state,
                                             HttpConnection conn)
                                      throws java.io.IOException,
                                             HttpException
Adds a Content-Length or Transer-Encoding: Chunked request header, as long as no Content-Length request header already exists.
Parameters:
state - current state of http requests
conn - the connection to use for I/O
Throws:
java.io.IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

addCookieRequestHeader

protected void addCookieRequestHeader(HttpState state,
                                      HttpConnection conn)
                               throws java.io.IOException,
                                      HttpException
Adds a Cookie request containing the matching Cookies.
Parameters:
state - current state of http requests
conn - the connection to use for I/O
Throws:
java.io.IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

addHostRequestHeader

protected void addHostRequestHeader(HttpState state,
                                    HttpConnection conn)
                             throws java.io.IOException,
                                    HttpException
Adds a Host request header, as long as no Host request header already exists.
Parameters:
state - current state of http requests
conn - the connection to use for I/O
Throws:
java.io.IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

addProxyAuthorizationRequestHeader

protected void addProxyAuthorizationRequestHeader(HttpState state,
                                                  HttpConnection conn)
                                           throws java.io.IOException,
                                                  HttpException
Adds a Proxy-Authorization request if needed, as long as no Proxy-Authorization request header already exists.
Parameters:
state - current state of http requests
conn - the connection to use for I/O
Throws:
java.io.IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

addRequestHeaders

protected void addRequestHeaders(HttpState state,
                                 HttpConnection conn)
                          throws java.io.IOException,
                                 HttpException
Populates the request headers map to with additional headers to be submitted to the given HttpConnection.

This implementation adds User-Agent, Host, Cookie, Content-Length, Transfer-Encoding, and Authorization headers, when appropriate.

Subclasses may want to override this method to to add additional headers, and may choose to invoke this implementation (via super) to add the "standard" headers.

Parameters:
state - the client state
conn - the HttpConnection the headers will eventually be written to
Throws:
java.io.IOException - when an error occurs writing the request
HttpException - when a HTTP protocol error occurs
See Also:
writeRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

addUserAgentRequestHeader

protected void addUserAgentRequestHeader(HttpState state,
                                         HttpConnection conn)
                                  throws java.io.IOException,
                                         HttpException
Adds a default User-Agent request header, as long as no User-Agent request header already exists.
Parameters:
state - the client state
conn - the HttpConnection the headers will eventually be written to
Throws:
java.io.IOException - when an error occurs writing the request
HttpException - when a HTTP protocol error occurs

checkNotUsed

protected void checkNotUsed()
                     throws java.lang.IllegalStateException
Throws an IllegalStateException if used but not recycled.
Throws:
java.lang.IllegalStateException - if the method has been used and not recycled

checkUsed

protected void checkUsed()
                  throws java.lang.IllegalStateException
Throws an IllegalStateException if not used since last recycle.
Throws:
java.lang.IllegalStateException - if not used

generateRequestLine

protected static java.lang.String generateRequestLine(HttpConnection connection,
                                                      java.lang.String name,
                                                      java.lang.String reqPath,
                                                      java.lang.String qString,
                                                      java.lang.String protocol)
Generate an HTTP/S request line according to the specified attributes.
Parameters:
connection - the connection the request will be sent to
name - the method name generate a request for
reqPath - the path for the request
qString - the query string for the request
protocol - the protocol to use (e.g. HTTP/1.0)
Returns:
a line to send to the server that will fulfil the request

processResponseBody

protected void processResponseBody(HttpState state,
                                   HttpConnection conn)
When this method is invoked, readResponseBody(HttpState,HttpConnection) will have been invoked.

This implementation does nothing.

Subclasses may want to override this method.

Parameters:
state - the client state
conn - the HttpConnection to read the response from
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), readResponseBody(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

processResponseHeaders

protected void processResponseHeaders(HttpState state,
                                      HttpConnection conn)
When this method is invoked, the response headers map will have been populated with the response headers (in other words, readResponseHeaders(HttpState,HttpConnection) will have been invoked).

This implementation will handle the Set-Cookie and Set-Cookie2 headers, if any, adding the relevant cookies to the given HttpState.

Subclasses may want to override this method to specially process additional headers, and/or invoke this method (via super) to process the Set-Cookie and Set-Cookie2 headers.

Parameters:
state - the client state
conn - the HttpConnection to read the response from
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), readResponseHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

processStatusLine

protected void processStatusLine(HttpState state,
                                 HttpConnection conn)
When this method is invoked, the status code and status text values will have been set (in other words, readStatusLine(HttpState,HttpConnection will have been invoked).

Subclasses may want to override this method to respond to these value. This implementation does nothing.

Parameters:
state - the client state
conn - the HttpConnection to read the response from
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), readStatusLine(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

readResponse

protected void readResponse(HttpState state,
                            HttpConnection conn)
                     throws java.io.IOException,
                            HttpException
Reads the response from the given HttpConnection.

The response is written according to the following logic:

  1. readStatusLine(HttpState,HttpConnection) is invoked to read the request line.
  2. processStatusLine(HttpState,HttpConnection) is invoked, allowing the method to respond to the status line if desired.
  3. readResponseHeaders(HttpState,HttpConnection is invoked to read the associated headers.
  4. processResponseHeaders(HttpState,HttpConnection is invoked, allowing the method to respond to the headers if desired.
  5. readResponseBody(HttpState,HttpConnection) is invoked to read the associated body (if any).
  6. processResponseBody(HttpState,HttpConnection is invoked, allowing the method to respond to the body if desired.
Subclasses may want to override one or more of the above methods to to customize the processing. (Or they may choose to override this method if dramatically different processing is required.)

Parameters:
state - the client state
conn - the HttpConnection to read the response from
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid

readResponseBody

protected void readResponseBody(HttpState state,
                                HttpConnection conn)
                         throws java.io.IOException,
                                HttpException
Read the response body from the given HttpConnection.

The current implementation simply consumes the expected response body (according to the values of the Content-Length and Transfer-Encoding headers, if any).

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the client state
conn - the HttpConnection to read the response from
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), processResponseBody(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

readResponseHeaders

protected void readResponseHeaders(HttpState state,
                                   HttpConnection conn)
                            throws java.io.IOException,
                                   HttpException
Read response headers from the given HttpConnection, populating the response headers map.

Subclasses may want to override this method to to customize the processing.

"It must be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma." - HTTP/1.0 (4.3)

Parameters:
state - the client state
conn - the HttpConnection to read the response from
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), processResponseHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

readStatusLine

protected void readStatusLine(HttpState state,
                              HttpConnection conn)
                       throws java.io.IOException,
                              HttpRecoverableException,
                              HttpException
Read the status line from the given HttpConnection, setting my status code and status text.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the client state
conn - the HttpConnection to read the response from
Throws:
java.io.IOException - when errors occur reading the status line
HttpException - If there is no status line, the protocol is not recognised, if we are unable to parse the status code from the line, or there was no status text
HttpRecoverableException - when the status line is null and the request should be retried
See Also:
readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), processStatusLine(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

writeRequest

protected void writeRequest(HttpState state,
                            HttpConnection conn)
                     throws java.io.IOException,
                            HttpException

Writes my request to the given HttpConnection.

The request is written according to the following logic:

  1. writeRequestLine(HttpState, HttpConnection) is invoked to write the request line.
  2. writeRequestHeaders(HttpState, HttpConnection) is invoked to write the associated headers.
  3. \r\n is sent to close the head part of the request.
  4. writeRequestBody(HttpState, HttpConnection) is invoked to write the body part of the request.

Subclasses may want to override one or more of the above methods to to customize the processing. (Or they may choose to override this method if dramatically different processing is required.)

Parameters:
state - the client state
conn - the HttpConnection to write the request to
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
                            throws java.io.IOException,
                                   HttpException
Write the request body to the given HttpConnection

If an expectation is required, this method should ensure that it has been sent by checking the status code.

This method should return true if the request body was actually sent (or is empty), or false if it could not be sent for some reason (for example, expectation required but not present).

This implementation writes nothing and returns true.

Parameters:
state - the client state
conn - the connection to write to
Returns:
true
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid

writeRequestHeaders

protected void writeRequestHeaders(HttpState state,
                                   HttpConnection conn)
                            throws java.io.IOException,
                                   HttpException
Writes the request headers to the given HttpConnection.

This implementation invokes addRequestHeaders(HttpState,HttpConnection), and then writes each header to the request stream.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the client state
conn - the HttpConnection to write to
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid
See Also:
addRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), getRequestHeaders()

writeRequestLine

protected void writeRequestLine(HttpState state,
                                HttpConnection conn)
                         throws java.io.IOException,
                                HttpException
Writes the "request line" to the given HttpConnection.

Subclasses may want to override this method to to customize the processing.

Parameters:
state - the client state
conn - the HttpConnection to write to
Throws:
java.io.IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid
See Also:
generateRequestLine(org.apache.commons.httpclient.HttpConnection, java.lang.String, java.lang.String, java.lang.String, java.lang.String)


Copyright (c) 2001 - Apache Software Foundation