Hi,

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
java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(Unknown Source)
        at java.net.SocketOutputStream.write(Unknown Source)
        at 
org.apache.commons.httpclient.HttpConnection$WrappedOutputStream.write(HttpConnection.java:1344)
        at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
        at java.io.BufferedOutputStream.write(Unknown Source)
        at 
org.apache.commons.httpclient.methods.multipart.FilePart.sendData(FilePart.java:300)
        at org.apache.commons.httpclient.methods.multipart.Part.send(Part.java:294)
        at 
org.apache.commons.httpclient.methods.multipart.Part.sendParts(Part.java:344)
        at 
org.apache.commons.httpclient.methods.MultipartPostMethod.writeRequestBody(MultipartPostMethod.java:262)
        at 
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2224)
        at 
org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMethodBase.java:2534)
        at 
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1047)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:638)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:500)
        at 
com.vigis.designfilereplication.Replicator.postReplicationRequest(Replicator.java:424)
        at com.vigis.designfilereplication.Replicator.main(Replicator.java:170)

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();
                client.setConnectionTimeout(5000);
                UsernamePasswordCredentials credentials = new 
UsernamePasswordCredentials("-----","-----");
                client.getState().setCredentials("realm","host",credentials);
                post.setDoAuthentication(true);
                try {
                        File archive1 = new File("c:/test.txt");
                        post.addParameter("VIGIS_ULD00",archive1);
                } catch (FileNotFoundException e1) {
                        ...
                }
                post.addParameter("instant",Long.toHexString(this.instant.getTime()));
                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.

Dennis Sellinger
Geotech
France.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to