org.apache.commons.httpclient.methods
Class EntityEnclosingMethod

java.lang.Object
  |
  +--org.apache.commons.httpclient.HttpMethodBase
        |
        +--org.apache.commons.httpclient.methods.GetMethod
              |
              +--org.apache.commons.httpclient.methods.EntityEnclosingMethod
All Implemented Interfaces:
HttpMethod
Direct Known Subclasses:
PostMethod, PutMethod

public abstract class EntityEnclosingMethod
extends GetMethod

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

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

Field Summary
static int CONTENT_LENGTH_AUTO
          The content length will be calculated automatically.
static int CONTENT_LENGTH_CHUNKED
          The request will use chunked transfer encoding.
 
Fields inherited from class org.apache.commons.httpclient.HttpMethodBase
USER_AGENT
 
Constructor Summary
EntityEnclosingMethod()
          No-arg constructor.
EntityEnclosingMethod(String uri)
          Constructor specifying a URI.
EntityEnclosingMethod(String uri, String tempDir)
          Deprecated. the client is responsible for disk I/O
EntityEnclosingMethod(String uri, String tempDir, String tempFile)
          Deprecated. the client is responsible for disk I/O
 
Method Summary
protected  void addRequestHeaders(HttpState state, HttpConnection conn)
          Set the Expect header if it has not already been set, in addition to the "standard" set of headers.
protected  void bufferContent()
          Buffers the request body and calculates the content length.
 boolean getFollowRedirects()
          Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.
 InputStream getRequestBody()
          Gets the request body as a stream.
 String getRequestBodyAsString()
          Gets the request body as a String.
protected  int getRequestContentLength()
          Override method of HttpMethodBase to return the length of the request body.
 boolean getUseExpectHeader()
          Returns the useExpectHeader.
 void recycle()
          Override method of HttpMethodBase to clear my request body.
 void setFollowRedirects(boolean followRedirects)
          Entity enclosing requests cannot be redirected without user intervention according to RFC 2616.
 void setRequestBody(InputStream body)
          Sets the request body to be the specified inputstream.
 void setRequestBody(String body)
          Sets the request body to be the specified string.
 void setRequestContentLength(int length)
          Sets length information about the request body.
 void setUseExpectHeader(boolean value)
          Sets the useExpectHeader.
protected  boolean writeRequestBody(HttpState state, HttpConnection conn)
          Override method of HttpMethodBase to write request parameters as the request body.
 
Methods inherited from class org.apache.commons.httpclient.methods.GetMethod
getFileData, getName, getResponseBody, getResponseBodyAsStream, getTempDir, getTempFile, getUseDisk, readResponseBody, setFileData, setTempDir, setTempFile, setUseDisk
 
Methods inherited from class org.apache.commons.httpclient.HttpMethodBase
addAuthorizationRequestHeader, addContentLengthRequestHeader, addCookieRequestHeader, addHostRequestHeader, addProxyAuthorizationRequestHeader, addRequestHeader, addRequestHeader, addResponseFooter, addUserAgentRequestHeader, checkNotUsed, checkUsed, execute, generateRequestLine, getContentCharSet, getDoAuthentication, getHostConfiguration, getPath, getQueryString, getRecoverableExceptionCount, getRequestCharSet, getRequestHeader, getRequestHeaderGroup, getRequestHeaders, getResponseBodyAsString, getResponseCharSet, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaderGroup, getResponseHeaders, getResponseTrailerHeaderGroup, getStatusCode, getStatusLine, getStatusText, getURI, hasBeenUsed, isHttp11, isStrictMode, processResponseBody, processResponseHeaders, processStatusLine, readResponse, readResponseHeaders, readStatusLine, releaseConnection, removeRequestHeader, responseBodyConsumed, setDoAuthentication, setHostConfiguration, setHttp11, setPath, setQueryString, setQueryString, setRequestHeader, setRequestHeader, setResponseStream, setStrictMode, shouldCloseConnection, validate, writeRequest, writeRequestHeaders, writeRequestLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_LENGTH_AUTO

public static final int CONTENT_LENGTH_AUTO
The content length will be calculated automatically. This implies buffering of the content.

See Also:
Constant Field Values

CONTENT_LENGTH_CHUNKED

public static final int CONTENT_LENGTH_CHUNKED
The request will use chunked transfer encoding. Content length is not calculated and the content is not buffered.

See Also:
Constant Field Values
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

EntityEnclosingMethod

public EntityEnclosingMethod(String uri,
                             String tempDir)
Deprecated. the client is responsible for disk I/O

Constructor specifying a URI and a tempDir.

Parameters:
uri - either an absolute or relative URI
tempDir - directory to store temp files in
Since:
2.0

EntityEnclosingMethod

public EntityEnclosingMethod(String uri,
                             String tempDir,
                             String tempFile)
Deprecated. the client is responsible for disk I/O

Constructor specifying a URI, tempDir and tempFile.

Parameters:
uri - either an absolute or relative URI
tempDir - directory to store temp files in
tempFile - file to store temporary data in
Since:
2.0
Method Detail

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

getUseExpectHeader

public boolean getUseExpectHeader()
Returns the useExpectHeader.

Returns:
boolean

setUseExpectHeader

public void setUseExpectHeader(boolean value)
Sets the useExpectHeader.

Parameters:
value - The useExpectHeader to set

setRequestContentLength

public void setRequestContentLength(int length)
Sets length information about the request body.

Note: If you specify a content length the request is unbuffered. This prevents redirection and automatic retry if a request fails the first time. This means that the HttpClient can not perform authorization automatically but will throw an Exception. You will have to set the necessary 'Authorization' or 'Proxy-Authorization' headers manually.

Parameters:
length - size in bytes or any of CONTENT_LENGTH_AUTO, CONTENT_LENGTH_CHUNKED. If number of bytes or CONTENT_LENGTH_CHUNKED is specified the content will not be buffered internally and the Content-Length header of the request will be used. In this case the user is responsible to supply the correct content length. If CONTENT_LENGTH_AUTO is specified the request will be buffered before it is sent over the network.

getRequestContentLength

protected int getRequestContentLength()
Override method of HttpMethodBase to return the length of the request body.

Overrides:
getRequestContentLength in class HttpMethodBase
Returns:
number of bytes in the request body

setRequestBody

public void setRequestBody(InputStream body)
Sets the request body to be the specified inputstream.

Parameters:
body - Request body content as InputStream

getRequestBody

public InputStream getRequestBody()
Gets the request body as a stream.

Returns:
The request body InputStream if it has been set.

setRequestBody

public void setRequestBody(String body)
Sets the request body to be the specified string.

Parameters:
body - Request body content as a string

getRequestBodyAsString

public String getRequestBodyAsString()
                              throws IOException
Gets the request body as a String.

Returns:
the request body as a string
Throws:
IOException - when i/o errors occur reading the request

addRequestHeaders

protected void addRequestHeaders(HttpState state,
                                 HttpConnection conn)
                          throws IOException,
                                 HttpException
Set the Expect header if it has not already been set, in addition to the "standard" set of headers.

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

writeRequestBody

protected boolean writeRequestBody(HttpState state,
                                   HttpConnection conn)
                            throws IOException,
                                   HttpException
Override method of HttpMethodBase to write request parameters as the request body. The input stream will be truncated after the specified content length.

Overrides:
writeRequestBody in class HttpMethodBase
Parameters:
state - the client state
conn - the connection to write to
Returns:
true
Throws:
IOException - when i/o errors occur reading the response
HttpException - when a protocol error occurs or state is invalid

recycle

public void recycle()
Override method of HttpMethodBase to clear my request body.

Specified by:
recycle in interface HttpMethod
Overrides:
recycle in class GetMethod

bufferContent

protected void bufferContent()
Buffers the request body and calculates the content length. If the method was called earlier it returns immediately.



Copyright (c) 1999-2002 - Apache Software Foundation