From 92e36507fe6e4d458a36341739e1df15ccd8dbd5 Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Wed, 20 Mar 2024 14:53:57 -0400 Subject: [PATCH] ok, this returns an actual HTTP 429 / TOO_MANY_REQUESTS. #9356 --- src/main/java/edu/harvard/iq/dataverse/DatasetPage.java | 4 +++- src/main/java/edu/harvard/iq/dataverse/DataversePage.java | 4 +++- .../java/edu/harvard/iq/dataverse/NavigationWrapper.java | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index b2daa56684f..b3bcffb4faf 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -252,6 +252,8 @@ public enum DisplayMode { DatasetVersionUI datasetVersionUI; @Inject PermissionsWrapper permissionsWrapper; + @Inject + NavigationWrapper navigationWrapper; @Inject FileDownloadHelper fileDownloadHelper; @Inject @@ -1936,7 +1938,7 @@ private void setIdByPersistentId() { private String init(boolean initFull) { // Check for rate limit exceeded. Must be done before anything else to prevent unnecessary processing. if (!cacheFactory.checkRate(session.getUser(), new CheckRateLimitForDatasetPage(null,null))) { - return permissionsWrapper.notFound(); + return navigationWrapper.tooManyRequests(); } //System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes setDataverseSiteUrl(systemConfig.getDataverseSiteUrl()); diff --git a/src/main/java/edu/harvard/iq/dataverse/DataversePage.java b/src/main/java/edu/harvard/iq/dataverse/DataversePage.java index c7d02618f65..cbfe8207be8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataversePage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataversePage.java @@ -118,6 +118,8 @@ public enum LinkMode { @EJB DataverseLinkingServiceBean linkingService; @Inject PermissionsWrapper permissionsWrapper; + @Inject + NavigationWrapper navigationWrapper; @Inject DataverseHeaderFragment dataverseHeaderFragment; @EJB PidProviderFactoryBean pidProviderFactoryBean; @@ -325,7 +327,7 @@ public String init() { //System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes // Check for rate limit exceeded. Must be done before anything else to prevent unnecessary processing. if (!cacheFactory.checkRate(session.getUser(), new CheckRateLimitForCollectionPage(null,null))) { - return permissionsWrapper.notFound(); + return navigationWrapper.tooManyRequests(); } if (this.getAlias() != null || this.getId() != null || this.getOwnerId() == null) {// view mode for a dataverse if (this.getAlias() != null) { diff --git a/src/main/java/edu/harvard/iq/dataverse/NavigationWrapper.java b/src/main/java/edu/harvard/iq/dataverse/NavigationWrapper.java index 832d7ec19ef..54fb8f211a6 100644 --- a/src/main/java/edu/harvard/iq/dataverse/NavigationWrapper.java +++ b/src/main/java/edu/harvard/iq/dataverse/NavigationWrapper.java @@ -16,6 +16,7 @@ import java.util.logging.Logger; import jakarta.faces.context.FacesContext; import jakarta.faces.view.ViewScoped; +import jakarta.ws.rs.core.Response.Status; import jakarta.inject.Inject; import jakarta.inject.Named; import jakarta.servlet.http.HttpServletRequest; @@ -87,6 +88,10 @@ public String notAuthorized(){ } } + public String tooManyRequests() { + return sendError(Status.TOO_MANY_REQUESTS.getStatusCode()); + } + public String notFound() { return sendError(HttpServletResponse.SC_NOT_FOUND); }