From 2d5141b644cd9f3c62cea5b3c84d0c1e904290ab Mon Sep 17 00:00:00 2001 From: Shudhansu Shekhar Date: Tue, 17 Sep 2024 15:17:20 +0530 Subject: [PATCH 1/3] Add limitation in the array of events for the publish endpoint generateAndPublish --- .../publish/controller/ProducerController.java | 15 +++++++++++++++ .../src/main/resources/application.properties | 2 ++ 2 files changed, 17 insertions(+) diff --git a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java index d61289e2..215b4eaf 100644 --- a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java +++ b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java @@ -78,6 +78,13 @@ public class ProducerController { @Value("${activedirectory.publish.enabled}") private boolean isAuthenticationEnabled; + @Value("${maxSizeOfInputArray:250}") + private int maxSizeOfInputArray; + + public void setMaxSizeOfInputArray(int maxSizeOfInputArray) { + this.maxSizeOfInputArray = maxSizeOfInputArray; + } + private RestTemplate restTemplate = new RestTemplate(); private JsonParser parser = new JsonParser(); @@ -303,6 +310,14 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String if (bodyJson.isJsonObject()) { events.add(getAsJsonObject(bodyJson)); } else if (bodyJson.isJsonArray()) { + //here add check for limitation for events in array is fetched from REMReM property and checked during publishing. + if (bodyJson.getAsJsonArray().size() > maxSizeOfInputArray) { + return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS, + "The number of events in the input array is exceeded the allowed limit of 250 events. " + + "This issue occurred because the input array contains more than 250 events, which is not supported by the system. " + + "To resolve this, please divide the events in to smaller arrays, ensuring each array contains no more than 250 events," + + "and try to publish them again. This limitation helps to maintain system performance and stability."); + } for (JsonElement element : bodyJson.getAsJsonArray()) { if (element.isJsonObject()) { events.add(getAsJsonObject(element)); diff --git a/publish-service/src/main/resources/application.properties b/publish-service/src/main/resources/application.properties index e23c39f0..568dc5c7 100644 --- a/publish-service/src/main/resources/application.properties +++ b/publish-service/src/main/resources/application.properties @@ -44,5 +44,7 @@ activedirectory.connectionTimeOut: spring.mvc.pathmatch.matching-strategy: ANT_PATH_MATCHER +#Maximum size of events in array is fetched from REMReM property and checked during publishing. +maxSizeOfInputArray: 250 From bcabf457670c7d2c0d137d7b1cc6904b492ebe9e Mon Sep 17 00:00:00 2001 From: Shudhansu Shekhar Date: Wed, 18 Sep 2024 19:55:17 +0530 Subject: [PATCH 2/3] Add limitation in the array of events for the publish endpoint generateAndPublish --- .../publish/controller/ProducerController.java | 15 +++++---------- .../src/main/resources/application.properties | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java index 215b4eaf..546fe6bb 100644 --- a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java +++ b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java @@ -81,10 +81,6 @@ public class ProducerController { @Value("${maxSizeOfInputArray:250}") private int maxSizeOfInputArray; - public void setMaxSizeOfInputArray(int maxSizeOfInputArray) { - this.maxSizeOfInputArray = maxSizeOfInputArray; - } - private RestTemplate restTemplate = new RestTemplate(); private JsonParser parser = new JsonParser(); @@ -310,15 +306,14 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String if (bodyJson.isJsonObject()) { events.add(getAsJsonObject(bodyJson)); } else if (bodyJson.isJsonArray()) { + JsonArray bodyJsonArray = bodyJson.getAsJsonArray(); //here add check for limitation for events in array is fetched from REMReM property and checked during publishing. - if (bodyJson.getAsJsonArray().size() > maxSizeOfInputArray) { + if (bodyJsonArray.size() > maxSizeOfInputArray) { return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS, - "The number of events in the input array is exceeded the allowed limit of 250 events. " + - "This issue occurred because the input array contains more than 250 events, which is not supported by the system. " - + "To resolve this, please divide the events in to smaller arrays, ensuring each array contains no more than 250 events," - + "and try to publish them again. This limitation helps to maintain system performance and stability."); + "The number of events in the input array is too high: " + bodyJsonArray.size() + " > " + maxSizeOfInputArray + ", " + + "You can modify the property 'maxSizeOfInputArray' to increase it"); } - for (JsonElement element : bodyJson.getAsJsonArray()) { + for (JsonElement element : bodyJsonArray) { if (element.isJsonObject()) { events.add(getAsJsonObject(element)); } else { diff --git a/publish-service/src/main/resources/application.properties b/publish-service/src/main/resources/application.properties index 568dc5c7..5d8a790b 100644 --- a/publish-service/src/main/resources/application.properties +++ b/publish-service/src/main/resources/application.properties @@ -44,7 +44,7 @@ activedirectory.connectionTimeOut: spring.mvc.pathmatch.matching-strategy: ANT_PATH_MATCHER -#Maximum size of events in array is fetched from REMReM property and checked during publishing. +#Maximum number of templates in array passed to generateAndPublish endpoint maxSizeOfInputArray: 250 From 18c64c67d2566d296fdf5dd79823851561cdda83 Mon Sep 17 00:00:00 2001 From: Shudhansu Shekhar Date: Thu, 26 Sep 2024 20:00:09 +0530 Subject: [PATCH 3/3] Add limitation in the array of events for the publish endpoint generateAndPublish --- .../publish/controller/ProducerController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java index 546fe6bb..7c70e70e 100644 --- a/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java +++ b/publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java @@ -156,6 +156,14 @@ public ResponseEntity send(final String msgProtocol, final String userDomain, fi return new ResponseEntity(e.getMessage(), HttpStatus.NOT_FOUND); } } + + //here add check for limitation for events in array is fetched from REMReM property and checked during publishing. + if (body.isJsonArray() && (body.getAsJsonArray().size() > maxSizeOfInputArray)) { + return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS, + "The number of events in the input array is too high: " + body.getAsJsonArray().size() + " > " + + maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it."); + + } synchronized (this) { SendResult result = messageService.send(body, msgService, userDomain, tag, routingKey); log.info("HTTP Status: {}", messageService.getHttpStatus().value()); @@ -310,8 +318,8 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String //here add check for limitation for events in array is fetched from REMReM property and checked during publishing. if (bodyJsonArray.size() > maxSizeOfInputArray) { return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS, - "The number of events in the input array is too high: " + bodyJsonArray.size() + " > " + maxSizeOfInputArray + ", " + - "You can modify the property 'maxSizeOfInputArray' to increase it"); + "The number of events in the input array is too high: " + bodyJsonArray.size() + " > " + + maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it."); } for (JsonElement element : bodyJsonArray) { if (element.isJsonObject()) {