hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Mencarelli <david.mencare...@ezcgroup.net>
Subject Abort a PUT request when server sends an error
Date Fri, 24 Aug 2012 14:02:20 GMT
Hello,

I'm using httpclient-4 (more precisely 4.1.2) to send the content of a stream (a huge file
in this case) to my Tomcat's upload servlet using the following code:

HttpRequest httpRequest = new HttpPut(destination);
InputStreamEntity entity = new InputStreamEntity(inputStream, contentLength);
((HttpPut)httpRequest).setEntity(entity);
httpClient.execute(httpRequest,handler);

It worked fine. 

I later added an authentication mechanism to prevent unauthorized user to upload files. If
someone tries to upload without being authenticated the servlet directly responds with an
HttpServletResponse.SC_FORBIDDEN without even processing the request's InputStream.

The problem I am facing is that despite the fact that the request is rejected on the server
side, my client keeps sending the whole content of the InputStream resulting in a waste of
network resources.

Here is a sample trace of execution:
12:00:32,813 -> call to execute
12:00:32:936 -> server sends an SC_FORBIDDEN error
12:00:44:883 -> response handler execute (and I detect the SC_FORBIDDEN status)
Network activity shows that the whole content of the file has been sent on the line. 

I have tried several server sides trick like reading one byte of the input stream then closing
it but nothing worked.

Is there a way to tell the httpclient to stop streaming the content of the file when the response
is forbidden (or any other status different of 200) ?

Any insights will be appreciated.

Thanks!

Regards,
David


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


Mime
View raw message