org.apache.commons.httpclient.methods
Class EntityEnclosingMethod

java.lang.Object
  extended by org.apache.commons.httpclient.HttpMethodBase
      extended by org.apache.commons.httpclient.methods.ExpectContinueMethod
          extended by org.apache.commons.httpclient.methods.EntityEnclosingMethod
All Implemented Interfaces:
HttpMethod
Direct Known Subclasses:
PostMethod, PutMethod

public abstract class EntityEnclosingMethod
extends ExpectContinueMethod

This abstract class serves as a foundation for all HTTP methods that can enclose an entity within requests

Since:
2.0beta1
Version:
$Revision: 161963 $
Author:
Oleg Kalnichevski, Jeff Dever

Constructor Summary
EntityEnclosingMethod()
          No-arg constructor.
EntityEnclosingMethod(String uri)
          Constructor specifying a URI.
 
Method Summary
protected  void addContentLengthRequestHeader(HttpState state, HttpConnection conn)
          Generates Content-Length or Transfer-Encoding: Chunked request header, as long as no Content-Length request header already exists.
protected  void addRequestHeaders(HttpState state, HttpConnection conn)
          Populates the request headers map to with additional headers to be submitted to the given HttpConnection.
protected  void clearRequestBody()
          Clears the request body.
protected  byte[] generateRequestBody()
          Generates the request body.
protected  RequestEntity generateRequestEntity()
           
 boolean getFollowRedirects()
          Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.
 String getRequestCharSet()
          Returns the request's charset.
protected  long getRequestContentLength()
          Returns the length of the request body.
 RequestEntity getRequestEntity()
           
protected  boolean hasRequestContent()
          Returns true if there is a request body to be sent.
 void setContentChunked(boolean chunked)
          Sets whether or not the content should be chunked.
 void setFollowRedirects(boolean followRedirects)
          Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.
 void setRequestEntity(RequestEntity requestEntity)
           
protected  boolean writeRequestBody(HttpState state, HttpConnection conn)
          Writes the request body to the given connection.
 
Methods inherited from class org.apache.commons.httpclient.HttpMethodBase
abort, addCookieRequestHeader, addHostRequestHeader, addProxyConnectionHeader, addRequestHeader, addRequestHeader, addRequestHeader, addResponseFooter, addUserAgentRequestHeader, checkNotUsed, checkUsed, execute, generateRequestLine, getContentCharSet, getDoAuthentication, getEffectiveVersion, getHostAuthState, getName, getParams, getPath, getProxyAuthState, getQueryString, getRequestHeader, getRequestHeaderGroup, getRequestHeaders, getRequestHeaders, getResponseBody, getResponseBodyAsStream, getResponseBodyAsString, getResponseCharSet, getResponseContentLength, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaderGroup, getResponseHeaders, getResponseHeaders, getResponseStream, getResponseTrailerHeaderGroup, getStatusCode, getStatusLine, getStatusText, getURI, hasBeenUsed, isAborted, isConnectionCloseForced, isRequestSent, processResponseBody, processResponseHeaders, processStatusLine, readResponse, readResponseBody, readResponseHeaders, readStatusLine, releaseConnection, removeRequestHeader, removeRequestHeader, responseBodyConsumed, setConnectionCloseForced, setDoAuthentication, setFilters, setLogWire, setParams, setPath, setQueryString, setQueryString, setRequestHeader, setRequestHeader, setResponseStream, setURI, shouldCloseConnection, validate, writeRequest, writeRequestHeaders, writeRequestLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityEnclosingMethod

public EntityEnclosingMethod()
No-arg constructor.

Since:
2.0

EntityEnclosingMethod

public EntityEnclosingMethod(String uri)
Constructor specifying a URI.

Parameters:
uri - either an absolute or relative URI
Since:
2.0
Method Detail

hasRequestContent

protected boolean hasRequestContent()
Returns true if there is a request body to be sent.

This method must be overridden by sub-classes that implement alternative request content input methods

Specified by:
hasRequestContent in class ExpectContinueMethod
Returns:
boolean
Since:
2.0beta1

clearRequestBody

protected void clearRequestBody()
Clears the request body.

This method must be overridden by sub-classes that implement alternative request content input methods.

Since:
2.0beta1

generateRequestBody

protected byte[] generateRequestBody()
Generates the request body.

This method must be overridden by sub-classes that implement alternative request content input methods.

Returns:
request body as an array of bytes. If the request content has not been set, returns null.
Since:
2.0beta1

generateRequestEntity

protected RequestEntity generateRequestEntity()
Returns:
a new request entity

getFollowRedirects

public boolean getFollowRedirects()
Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.

Specified by:
getFollowRedirects in interface HttpMethod
Overrides:
getFollowRedirects in class HttpMethodBase
Returns:
false.
Since:
2.0

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.

Specified by:
setFollowRedirects in interface HttpMethod
Overrides:
setFollowRedirects in class HttpMethodBase
Parameters:
followRedirects - must always be false

getRequestCharSet

public String getRequestCharSet()
Returns the request's charset. The charset is parsed from the request entity's content type, unless the content type header has been set manually.

Overrides:
getRequestCharSet in class HttpMethodBase
Returns:
the request's charset
Since:
3.0
See Also:
RequestEntity.getContentType()

setContentChunked

public void setContentChunked(boolean chunked)
Sets whether or not the content should be chunked.

Parameters:
chunked - true if the content should be chunked
Since:
3.0

getRequestContentLength

protected long getRequestContentLength()
Returns the length of the request body.

Returns:
number of bytes in the request body

addRequestHeaders

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

This implementation adds tt>Content-Length or Transfer-Encoding headers.

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.

Overrides:
addRequestHeaders in class ExpectContinueMethod
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
IOException
HttpException
Since:
3.0
See Also:
HttpMethodBase.writeRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

addContentLengthRequestHeader

protected void addContentLengthRequestHeader(HttpState state,
                                             HttpConnection conn)
                                      throws IOException,
                                             HttpException
Generates Content-Length or Transfer-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:
IOException - when errors occur reading or writing to/from the connection
HttpException - when a recoverable error occurs

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
                            throws IOException
Writes the request body to the given connection.

Overrides:
writeRequestBody in class HttpMethodBase
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Returns:
true
Throws:
IOException

getRequestEntity

public RequestEntity getRequestEntity()
Returns:
Returns the requestEntity.
Since:
3.0

setRequestEntity

public void setRequestEntity(RequestEntity requestEntity)
Parameters:
requestEntity - The requestEntity to set.
Since:
3.0


Copyright (c) 1999-2005 - Apache Software Foundation