try {
httpRequest = requestFactory.buildGetRequest(genericUrl);
} catch (IOException e) {
String errorMessage = String.format("Build GET Request for URL <%s> fails, with following message <%s>", genericUrl.build(), e.getMessage());
logger.error(errorMessage, e);
throw new AsanaException(errorMessage, e);
}
HttpResponse execute = null;
try {
execute = httpRequest.execute();
} catch (UnknownHostException unknownHostException) {
String errorMessage = String.format("Executing GET Request <%s> for unknown host. Possible reasons: 1. Typo in URL, 2. Not working internet connections", genericUrl.build());
logger.error(errorMessage, unknownHostException);
throw new AsanaException(errorMessage, unknownHostException);
} catch (HttpResponseException httpResponseException) {
int statusCode = httpResponseException.getStatusCode();
String errorMessage = String.format("Executing GET Request <%s> fails with response status code <%s> and following message <%s>",
genericUrl.build(), String.valueOf(statusCode), httpResponseException.getMessage());
// not found
if (statusCode == 404) {
return null;
}
logger.error(errorMessage, httpResponseException);
throw new AsanaException(errorMessage, httpResponseException);
} catch (IOException e) {
String errorMessage = String.format("Executing GET Request <%s> fails, with following message <%s>", genericUrl.build(), e.getMessage());
logger.error(errorMessage, e);
throw new AsanaException(errorMessage, e);
}
Object resultObject = null;
try {
resultObject = execute.parseAs(typeOfTeResult);
} catch (IOException e) {
String errorMessage = String.format("Parsing Response from GET Request <%s> fails, with following message <%s>", genericUrl.build(), e.getMessage());
logger.error(errorMessage, e);
throw new AsanaException(errorMessage, e);
}
return prepareResult(resultObject, expectedResult);
}