// parse and return response.
return (T)((parser != null) && (inputStream != null) ? parser.parse(inputStream) : null);
} catch (ClientProtocolException e) {
Throwable cause = e.getCause();
if ((cause != null) && (cause instanceof CircularRedirectException)) {
throw new ConnectionException(e, false);
} else {
throw new UnexpectedException(e);
}
} catch (ConnectTimeoutException e) {
throw new ConnectionException(e, true);
} catch (IOException e) {
throw new ConnectionException(e, false);
} finally {
FileUtils.safeClose(inputStream);
if (client != null) {
client.getConnectionManager().shutdown();
}