hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frazer Irving <frazer.irvi...@bbc.co.uk>
Subject Non-blocking file upload
Date Wed, 16 Feb 2011 11:05:30 GMT

I have a requirement to upload a file, and to have the transfer of data 
be interrupted in the event of the server responding with an error. My 
code looks like:

             MimetypesFileTypeMap mime = new MimetypesFileTypeMap();
             request = new PostMethod(url);

             MonitoredRequestEntity ent = new MonitoredRequestEntity(
                     stream, file.length(), mime.getContentType(file), 
             int status = 0;
             try {
                 status = httpClient.executeMethod(request);
             } catch (Exception e) {
                 if (!request.isAborted()) {
                     logger.error("http post failed for job {}", jobId, e);
                     listener.setStatus(new UploadStatus().setFailed());
             if (status != HttpStatus.SC_ACCEPTED && status != 
HttpStatus.SC_OK) {
                 throw new 

It seems that the call to executeMethod is blocking until the entire 
body of the RequestEntity has been written to the server before 
processing the response. Is there a way to have the response processed 
earlier? The files in question are very large and I would like to avoid 
the transfer if possible.

I am using MultiThreadedHttpConnectionManager to manage connections if 
that affects things.


This e-mail (and any attachments) is confidential and may contain personal views which are
not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify
the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.

To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org

View raw message