Skip to content

Add limitation in the array of events for the publish endpoint genera… #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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