The Apache HttpClient framework allows you to specify a connection timeout and a socket timeout, like so:
final HttpParams httpParams = new BasicHttpParams();
if (connectionTimeout > 0) {
HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
}
if (socketTimeout > 0) {
HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
}
HttpClient client = new DefaultHttpClient(httpParams);
I would like to fine-tune my connection timeouts. This question explains the difference between the settings nicely, but provides no help for debugging the exceptions that get thrown.
My question is, what exception gets thrown for each type of timeout? I have a java.net.SocketTimeoutException
; is this from a connection timeout or a socket timeout? I suspect it's the latter, especially since the message says "Read timed out". What exception will be thrown for a connection timeout? TimeoutException
? ConnectException
? Why aren't the relationships between timeout settings and exceptions thrown captured in the Apache Http Docs?
The direct parent classes for SocketTimeoutException
are InterruptedIoException
and IOException
; the former has only the SocketTimeoutException
for a subclass, but the IOException
has many subclasses. Is there another reference that covers what all flavors of exceptions one can expect to receive from an HttpClient execute
method? It only declares that it can throw an IOException
, which is really very broad.