int statusCode = httpResponse.getStatusLine().getStatusCode();
// 5xx server error.
// 4xx client error.
// 3xx redriections.
if (statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
ServiceException se = exceptionHandler.handle(httpResponse);
if (se != null) {
throw se;
}
} else if (statusCode >= HttpStatus.SC_OK) {
return responseHandler.handle(httpResponse);
}
// 1xx. HTTP/1.1 extensions
else if (statusCode >= HttpStatus.SC_CONTINUE) {
throw new IllegalStateException(String.format("Unexpected status code: %d received.", statusCode));
}
} catch (IOException io) {
httpRequest.abort();
throw new ServiceException("client side error", io);
} finally {
if (httpResponse != null) {
// consume all entity part so that the connection will be close.
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {