hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rezvani, Matt" <MRezv...@orionsci.com>
Subject A Retry on a PutMethod
Date Tue, 23 Sep 2003 17:15:37 GMT
When setting the request content length of an enclosed entity to be stored
on the WebDAV server using the PutMethod, the HttpClient returns an
"Unbuffered entity enclosing request can not be repeated" HttpException. I
am aware that if the request is not buffered, then the PutMethod (or
PostMethod) cannot retry the request in case of an authentication challenge
or an I/O error. An alternate solution would be to let the PutMethod buffer
the entire file by setting the request content length to
EntityEnclosingMethod.CONTENT_LENGTH_AUTO. This is OK for small files;
however for enormous size files it causes an out-of-memory error. My
question is how do I send a retry request after an authentication challenge
has been sent back by the server, and why can't the
EntityEnclosingMethod.writeRequestBody() send the request again from it's

Here is a sample code.

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.PutMethod;
import java.io.*;

public class PutMethodExample
		public static void main(String args[]) throws Exception
		HttpClient client = new HttpClient();
		// Assuming that the credentials are passed to the
HttpClient using
		// the HttpState.setCredentials

		PutMethod put = new
		File bigFile = new File("c:\\j2sdk-1_4_2-windows-i586.exe");
		long fileLength = bigFile.length();
		put.setRequestBody(new FileInputStream(bigFile));

		int status = client.executeMethod(put);


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message