I'm getting an intermittent exception org.apache.commons.httpclient.ProtocolException: Unbuffered entity enclosing request can not be repeated.
when using Apache HTTP client library 4.x with Restlet 1.1. The request entity is of type InputRepresentation
, which is associated with ByteArrayInputStream
of known size, with size specified at the time of instantiation.
The exception is thrown in method writeRequestBody
in class org.apache.commons.httpclient.methods.EntityEnclosingMethod
if ((this.repeatCount > 0) && !requestEntity.isRepeatable()) {
throw new ProtocolException(
"Unbuffered entity enclosing request can not be repeated.");
}
To be honest, the cause of this exception is not clear (especially due to its intermittent nature). However, some research suggests that using Apache BufferedHttpEntity to wrap the request entity should help.
Is there a way to inform Restlet to use BufferedHttpEntity when passing its request to the Apache library for handling? What could be the cause of the problem?
If the entity content stream can be reproduced (repeated), which is certainly the case with ByteArrayInputStream, there is no need for BufferedHttpEntity. One just needs to make sure that the original request entity returns a new instance of InputStream from HttpEntity#getContent() method and HttpEntity#isRepeatable() returns true.
Please note though that org.apache.commons.httpclient.ProtocolException
is from an older (EOL-ed) version 3.x. Please make sure you do not have some kind of version mix-up in your application