protected abstract T parseResponse(String httpResponse) throws JSONException;
public T executeRequest(String accessToken) {
try {
URL url = createURL(accessToken);
HttpResponseContext httpResponse = OAuthUtils.readUrlContent(url.openConnection());
if (httpResponse.getResponseCode() == 200) {
return parseResponse(httpResponse.getResponse());
} else if (httpResponse.getResponseCode() == 400) {
String errorMessage = "Error when obtaining content from Facebook. Error details: " + httpResponse.getResponse();
log.warn(errorMessage);
throw new OAuthException(OAuthExceptionCode.ACCESS_TOKEN_ERROR, errorMessage);
} else {
String errorMessage = "Unspecified IO error. Http response code: " + httpResponse.getResponseCode() + ", details: " + httpResponse.getResponse();
log.warn(errorMessage);
throw new OAuthException(OAuthExceptionCode.IO_ERROR, errorMessage);
}
} catch (JSONException e) {
throw new OAuthException(OAuthExceptionCode.IO_ERROR, e);