}
@Override
public void invoke(final HttpRequest request, final HttpResponse response) {
HAccount authenticatedUser = getAuthenticatedUser();
String apiKey = HeaderHelper.getApiKey(request);
try {
// we are not validating api key but will rate limit any api key
if (authenticatedUser == null && Strings.isNullOrEmpty(apiKey)) {
response.sendError(
Response.Status.UNAUTHORIZED.getStatusCode(),
API_KEY_ABSENCE_WARNING);
return;
}
Runnable taskToRun = new Runnable() {
@Override
public void run() {
RestLimitingSynchronousDispatcher.super.invoke(request,
response);
}
};
if (authenticatedUser == null) {
processor.processApiKey(apiKey, response, taskToRun);
} else if (!Strings.isNullOrEmpty(authenticatedUser.getApiKey())) {
processor.processApiKey(authenticatedUser.getApiKey(),
response, taskToRun);
} else {
processor.processUsername(authenticatedUser.getUsername(),
response, taskToRun);
}
} catch (UnhandledException e) {
Throwable cause = e.getCause();