Is there a way to specify a timeout for the whole execution of HttpClient?
I have tried the following:
httpClient.getParams().setParameter("http.socket.timeout", timeout * 1000);
httpClient.getParams().setParameter("http.connection.timeout", timeout * 1000);
httpClient.getParams().setParameter("http.connection-manager.timeout", new Long(timeout * 1000));
httpClient.getParams().setParameter("http.protocol.head-body-timeout", timeout * 1000);
It actually works fine, except if a remote host sends back data – even at one byte/second – it will continue to read forever! But I want to interrupt the connection in 10 seconds max, whether or not the host responds.
There is currently no way to set a maximum request duration of that sort: basically you want to say I don’t care whether or not any specific request stage times out, but the entire request must not last longer than 15 seconds (for example).
Your best bet would be to run a separate timer, and when it expires fetch the connection manager used by the HttpClient instance and shutdown the connection, which should terminate the link. Let me know if that works for you.