From b39e1ac201357b78bf579fff050b74a7dcd47c4d Mon Sep 17 00:00:00 2001 From: Xin Zheng Date: Wed, 5 Jun 2024 10:54:56 +0700 Subject: [PATCH] RedisStorage.cleanup() NumberFormatException if caller didn't assign one --- .../swisspush/reststorage/RestStorageHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swisspush/reststorage/RestStorageHandler.java b/src/main/java/org/swisspush/reststorage/RestStorageHandler.java index e217494..5180a5c 100644 --- a/src/main/java/org/swisspush/reststorage/RestStorageHandler.java +++ b/src/main/java/org/swisspush/reststorage/RestStorageHandler.java @@ -14,6 +14,7 @@ import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.BasicAuthHandler; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.swisspush.reststorage.exception.RestStorageExceptionFactory; import org.swisspush.reststorage.util.*; @@ -45,6 +46,7 @@ public class RestStorageHandler implements Handler { private final boolean return200onDeleteNonExisting; private final DecimalFormat decimalFormat; private final Integer maxStorageExpandSubresources; + private final long resourceCleanupAmount; public RestStorageHandler( Vertx vertx, @@ -62,6 +64,7 @@ public RestStorageHandler( this.rejectStorageWriteOnLowMemory = config.isRejectStorageWriteOnLowMemory(); this.return200onDeleteNonExisting = config.isReturn200onDeleteNonExisting(); this.maxStorageExpandSubresources = config.getMaxStorageExpandSubresources(); + this.resourceCleanupAmount = config.getResourceCleanupAmount(); this.decimalFormat = new DecimalFormat(); this.decimalFormat.setMaximumFractionDigits(1); @@ -127,7 +130,15 @@ private void cleanup(RoutingContext ctx) { ctx.response().end(); }); pump.start(); - }, ctx.request().params().get("cleanupResourcesAmount")); + }, getCleanupResourcesAmountContextOrConfig(ctx)); + } + + private String getCleanupResourcesAmountContextOrConfig(RoutingContext ctx) { + String cleanupResourcesAmount = ctx.request().getParam("cleanupResourcesAmount"); + if (StringUtils.isEmpty(cleanupResourcesAmount)) { + cleanupResourcesAmount = String.valueOf(this.resourceCleanupAmount); + } + return cleanupResourcesAmount; } private void getResourceNotFound(RoutingContext ctx) {