|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.httpclient.HttpMethodBase
org.apache.commons.httpclient.methods.ExpectContinueMethod
org.apache.commons.httpclient.methods.EntityEnclosingMethod
This abstract class serves as a foundation for all HTTP methods that can enclose an entity within requests
Field Summary | |
static long |
CONTENT_LENGTH_AUTO
The content length will be calculated automatically. |
static long |
CONTENT_LENGTH_CHUNKED
The request will use chunked transfer encoding. |
Constructor Summary | |
EntityEnclosingMethod()
No-arg constructor. |
|
EntityEnclosingMethod(java.lang.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. |
boolean |
getFollowRedirects()
Entity enclosing requests cannot be redirected without user intervention according to RFC 2616. |
java.io.InputStream |
getRequestBody()
Returns the request body as a InputStream . |
java.lang.String |
getRequestBodyAsString()
Returns the request body as a String . |
protected long |
getRequestContentLength()
Returns the length of the request body. |
protected boolean |
hasRequestContent()
Returns true if there is a request body to be sent. |
void |
recycle()
Recycles the HTTP method so that it can be used again. |
void |
setFollowRedirects(boolean followRedirects)
Entity enclosing requests cannot be redirected without user intervention according to RFC 2616. |
void |
setRequestBody(java.io.InputStream body)
Sets the request body to be the specified inputstream. |
void |
setRequestBody(java.lang.String body)
Sets the request body to be the specified string. |
void |
setRequestContentLength(int length)
Deprecated. use setRequestContentLength(long) instead
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. |
void |
setRequestContentLength(long length)
Sets length information about the request body. |
protected boolean |
writeRequestBody(HttpState state,
HttpConnection conn)
Writes the request body to the given connection . |
Methods inherited from class org.apache.commons.httpclient.methods.ExpectContinueMethod |
getUseExpectHeader, setUseExpectHeader |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long CONTENT_LENGTH_AUTO
public static final long CONTENT_LENGTH_CHUNKED
Constructor Detail |
public EntityEnclosingMethod()
public EntityEnclosingMethod(java.lang.String uri)
uri
- either an absolute or relative URIMethod Detail |
protected boolean hasRequestContent()
This method must be overridden by sub-classes that implement alternative request content input methods
hasRequestContent
in class ExpectContinueMethod
protected void clearRequestBody()
This method must be overridden by sub-classes that implement alternative request content input methods.
protected byte[] generateRequestBody()
This method must be overridden by sub-classes that implement alternative request content input methods.
public boolean getFollowRedirects()
getFollowRedirects
in interface HttpMethod
getFollowRedirects
in class HttpMethodBase
false
.public void setFollowRedirects(boolean followRedirects)
setFollowRedirects
in interface HttpMethod
setFollowRedirects
in class HttpMethodBase
followRedirects
- must always be false
public void setRequestContentLength(int length)
setRequestContentLength(long)
instead
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.
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.public void setRequestContentLength(long length)
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.
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.protected long getRequestContentLength()
protected void addRequestHeaders(HttpState state, HttpConnection conn) throws java.io.IOException, HttpException
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.
addRequestHeaders
in class ExpectContinueMethod
state
- the state
information associated with this methodconn
- the connection
used to execute
this HTTP method
java.io.IOException
- if an I/O (transport) error occurs. Some transport exceptions
can be recovered from.
HttpException
- if a protocol exception occurs. Usually protocol exceptions
cannot be recovered from.HttpMethodBase.writeRequestHeaders(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)
protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn) throws java.io.IOException, HttpException
state
- current state of http requestsconn
- the connection to use for I/O
java.io.IOException
- when errors occur reading or writing to/from the
connection
HttpException
- when a recoverable error occurspublic void setRequestBody(java.io.InputStream body)
body
- Request body content as InputStream
public java.io.InputStream getRequestBody()
InputStream
.
Calling this method will cause the content to be buffered.
InputStream
if it has been set.public void setRequestBody(java.lang.String body)
setRequestHeader("Content-type", "text/xml; charset=UTF-8");
default
content encoding is used (ISO-8859-1).
body
- Request body content as a stringpublic java.lang.String getRequestBodyAsString() throws java.io.IOException
String
.
Calling this method will cause the content to be buffered.
String
java.io.IOException
- if I/O error occurs while reading the request bodyprotected boolean writeRequestBody(HttpState state, HttpConnection conn) throws java.io.IOException, HttpException
connection
.
writeRequestBody
in class HttpMethodBase
state
- the state
information associated with this methodconn
- the connection
used to execute
this HTTP method
java.io.IOException
- if an I/O (transport) error occurs. Some transport exceptions
can be recovered from.
HttpException
- if a protocol exception occurs. Usually protocol exceptions
cannot be recovered from.public void recycle()
recycle
in interface HttpMethod
recycle
in class HttpMethodBase
HttpMethodBase.releaseConnection()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |