Skip to content

Commit

Permalink
Add limitation in the array of events for the publish endpoint genera… (
Browse files Browse the repository at this point in the history
#299)

 Add limitation in the array of events for the publish endpoint generateAndPublish
  • Loading branch information
shudhansu-shekhar authored Oct 8, 2024
1 parent adb1584 commit 5597385
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class ProducerController {
@Value("${activedirectory.publish.enabled}")
private boolean isAuthenticationEnabled;

@Value("${maxSizeOfInputArray:250}")
private int maxSizeOfInputArray;

private RestTemplate restTemplate = new RestTemplate();

private JsonParser parser = new JsonParser();
Expand Down Expand Up @@ -153,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());
Expand Down Expand Up @@ -303,7 +314,14 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String
if (bodyJson.isJsonObject()) {
events.add(getAsJsonObject(bodyJson));
} else if (bodyJson.isJsonArray()) {
for (JsonElement element : bodyJson.getAsJsonArray()) {
JsonArray bodyJsonArray = bodyJson.getAsJsonArray();
//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.");
}
for (JsonElement element : bodyJsonArray) {
if (element.isJsonObject()) {
events.add(getAsJsonObject(element));
} else {
Expand Down
2 changes: 2 additions & 0 deletions publish-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ activedirectory.connectionTimeOut:

spring.mvc.pathmatch.matching-strategy: ANT_PATH_MATCHER

#Maximum number of templates in array passed to generateAndPublish endpoint
maxSizeOfInputArray: 250


0 comments on commit 5597385

Please sign in to comment.