commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis SELLINGER" <>
Subject (HttpClient) Posting large files using MultipartPostMethod
Date Thu, 14 Aug 2003 08:47:17 GMT

I have been trying to implement a simple client to upload a file to a servlet.  The code I
use is pretty basic (summarized below).  I find that it works for files that are sufficiently
small (<128 K) but gives the following error for larger files:

14 août 2003 10:19:55 com.vigis.designfilereplication.Replicator postReplicationRequest
GRAVE: I/O error while executing replication post request... root cause Software caused connection
abort: socket write error Software caused connection abort: socket write error
	at Method)
	at Source)
	at Source)
	at org.apache.commons.httpclient.HttpConnection$WrappedOutputStream.write(
	at Source)
	at Source)
	at org.apache.commons.httpclient.methods.multipart.FilePart.sendData(
	at org.apache.commons.httpclient.methods.multipart.Part.send(
	at org.apache.commons.httpclient.methods.multipart.Part.sendParts(
	at org.apache.commons.httpclient.methods.MultipartPostMethod.writeRequestBody(
	at org.apache.commons.httpclient.HttpMethodBase.writeRequest(
	at org.apache.commons.httpclient.HttpMethodBase.processRequest(
	at org.apache.commons.httpclient.HttpMethodBase.execute(
	at org.apache.commons.httpclient.HttpClient.executeMethod(
	at org.apache.commons.httpclient.HttpClient.executeMethod(
	at com.vigis.designfilereplication.Replicator.postReplicationRequest(
	at com.vigis.designfilereplication.Replicator.main(

My client is running on Java 1.4.2 under windows xp sp1.  In the case where the post fails,
I don't think that it arrives at my server (i.e. my servlet does not start running the getPost()
method).  My server is a servlet running under tomcat 4.1.x using the com.oreilly.servlet.MultipartRequest
API to handle the upload.  This servlet has be used extensively with multipart posts originalating
from Internet Explorer, so there should be no problems with it.

Here is a cleaned up version of the code I am executing:

		MultipartPostMethod post = new MultipartPostMethod("http://alsace/vwjserv/accept/dea93");
		HttpClient client = new HttpClient();
		UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("-----","-----");
		try {
			File archive1 = new File("c:/test.txt");
		} catch (FileNotFoundException e1) {
		int statusCode = -1;
		int retryCount = 0;
		boolean retry = true;
		while (retry) {
			try {
				statusCode = client.executeMethod(post);
				retry = false;
			} catch (HttpRecoverableException hrx) {
			} catch (HttpException e) {
			} catch (IOException e) {			

I think the code is pretty clean, but I am obviously missing a parmeter or something. Any
help would be appreciated.

Thanks in advance,

Dennis Sellinger

View raw message