Skip to content

Commit 2d5141b

Browse files
Add limitation in the array of events for the publish endpoint generateAndPublish
1 parent adb1584 commit 2d5141b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public class ProducerController {
7878
@Value("${activedirectory.publish.enabled}")
7979
private boolean isAuthenticationEnabled;
8080

81+
@Value("${maxSizeOfInputArray:250}")
82+
private int maxSizeOfInputArray;
83+
84+
public void setMaxSizeOfInputArray(int maxSizeOfInputArray) {
85+
this.maxSizeOfInputArray = maxSizeOfInputArray;
86+
}
87+
8188
private RestTemplate restTemplate = new RestTemplate();
8289

8390
private JsonParser parser = new JsonParser();
@@ -303,6 +310,14 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String
303310
if (bodyJson.isJsonObject()) {
304311
events.add(getAsJsonObject(bodyJson));
305312
} else if (bodyJson.isJsonArray()) {
313+
//here add check for limitation for events in array is fetched from REMReM property and checked during publishing.
314+
if (bodyJson.getAsJsonArray().size() > maxSizeOfInputArray) {
315+
return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS,
316+
"The number of events in the input array is exceeded the allowed limit of 250 events. " +
317+
"This issue occurred because the input array contains more than 250 events, which is not supported by the system. "
318+
+ "To resolve this, please divide the events in to smaller arrays, ensuring each array contains no more than 250 events,"
319+
+ "and try to publish them again. This limitation helps to maintain system performance and stability.");
320+
}
306321
for (JsonElement element : bodyJson.getAsJsonArray()) {
307322
if (element.isJsonObject()) {
308323
events.add(getAsJsonObject(element));

publish-service/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ activedirectory.connectionTimeOut:
4444

4545
spring.mvc.pathmatch.matching-strategy: ANT_PATH_MATCHER
4646

47+
#Maximum size of events in array is fetched from REMReM property and checked during publishing.
48+
maxSizeOfInputArray: 250
4749

4850

0 commit comments

Comments
 (0)