public class RepeatableInputStreamRequestEntity
extends org.apache.http.entity.BasicHttpEntity
RequestEntity
that delegates to an
RepeatableInputStreamRequestEntity
, with the one notable difference, that if
the underlying InputStream supports being reset, this RequestEntity will
report that it is repeatable and will reset the stream on all subsequent
attempts to write out the request.
TODO : Move this to apache specific package.Modifier and Type | Field and Description |
---|---|
private java.io.InputStream |
content
The InputStream containing the content to write out
|
private boolean |
firstAttempt
True if the request entity hasn't been written out yet
|
private org.apache.http.entity.InputStreamEntity |
inputStreamRequestEntity
The underlying InputStreamEntity being delegated to
|
private static org.apache.commons.logging.Log |
log |
private java.io.IOException |
originalException
Record the original exception if we do attempt a retry, so that if the
retry fails, we can report the original exception.
|
Constructor and Description |
---|
RepeatableInputStreamRequestEntity(Request<?> request)
Creates a new RepeatableInputStreamRequestEntity using the information
from the specified request.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isChunked() |
boolean |
isRepeatable()
Returns true if the underlying InputStream supports marking/reseting or
if the underlying InputStreamRequestEntity is repeatable (i.e.
|
void |
writeTo(java.io.OutputStream output)
Resets the underlying InputStream if this isn't the first attempt to
write out the request, otherwise simply delegates to
InputStreamRequestEntity to write out the data.
|
getContent, getContentLength, isStreaming, setContent, setContentLength
private boolean firstAttempt
private org.apache.http.entity.InputStreamEntity inputStreamRequestEntity
private java.io.InputStream content
private static final org.apache.commons.logging.Log log
private java.io.IOException originalException
public RepeatableInputStreamRequestEntity(Request<?> request)
request
- The details of the request being written out (content type,
content length, and content).public boolean isChunked()
isChunked
in interface org.apache.http.HttpEntity
isChunked
in class org.apache.http.entity.AbstractHttpEntity
public boolean isRepeatable()
InputStreamRequestEntity#CONTENT_LENGTH_AUTO
and therefore its
entire contents will be buffered in memory and can be repeated).isRepeatable
in interface org.apache.http.HttpEntity
isRepeatable
in class org.apache.http.entity.BasicHttpEntity
org.apache.commons.httpclient.methods.RequestEntity#isRepeatable()
public void writeTo(java.io.OutputStream output) throws java.io.IOException
If an error is encountered the first time we try to write the request entity, we remember the original exception, and report that as the root cause if we continue to encounter errors, rather than masking the original error.
writeTo
in interface org.apache.http.HttpEntity
writeTo
in class org.apache.http.entity.BasicHttpEntity
java.io.IOException
org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream)