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 15:26:09 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?

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
	
PutMethod("http://myServer:/webdav/example.txt");
		File bigFile = new File("c:\\j2sdk-1_4_2-windows-i586.exe");
		long fileLength = bigFile.length();
		put.setRequestContentLength((int)fileLength);
		put.setRequestBody(new FileInputStream(bigFile));

		int status = client.executeMethod(put);
		put.releaseConnection();
	}
}

Thanks,
Matt


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