// of the caller to release this connection by calling
// HttpMethod#releaseConnection.
HttpConnection connection = manager.getConnection(configuration);
prepareConnection(connection);
TimingOutTask task = null;
int statusCode;
URI uri = null;
try {
// Get the URI now so that it can be used to report errors if
// necessary.
uri = new URI(connection.getProtocol().getScheme(), null,
configuration.getHost(), connection.getPort(),
method.getPath(), method.getQueryString(), null);
if (roundTripTimeout != Period.INDEFINITELY) {
task = createTimingOutTask(connection);
TIMER.schedule(new RunnableTimerTask(task),
roundTripTimeout.inMillis());
}
// Normally HttpClient takes care or opening collection
// but since we use our own HttpClient we need to do
// it manually
if (!connection.isOpen()) {
connection.open();
}
statusCode = method.execute(httpState, connection);
} catch (Exception e) {
if (task != null && task.timedOut()) {
// Assume that the exception occurred because of the
// timeout.
// todo create a more specific exception that encapsulates the
// todo URL, the timeout and the actual elapsed time.
InterruptedIOException exception =
wrapException("Request to '" + uri +
"' timed out after " + roundTripTimeout, e);
throw exception;
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else if (e instanceof IOException) {
throw (IOException) e;
} else {
throw new UndeclaredThrowableException(e);
}
} finally {
if (task != null) {
// Make sure that any existing timeouts are ignored.
task.deactivate();
}
}
return HttpStatusCode.getStatusCode(statusCode);
}