Skip to content

Commit e38806b

Browse files
Add limitation in the array of events for the endpoint of generate (#227)
* Add limitation in the array of events for the endpoint of generate * Add limitation in the array of events for the endpoint of generate * Add limitation in the array of events for the endpoint of generate
1 parent a870ce4 commit e38806b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.slf4j.LoggerFactory;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.beans.factory.annotation.Value;
35+
import org.springframework.context.annotation.PropertySource;
3536
import org.springframework.http.HttpStatus;
3637
import org.springframework.http.MediaType;
3738
import org.springframework.http.RequestEntity;
@@ -52,7 +53,6 @@
5253
import java.util.Map.Entry;
5354

5455
import static com.ericsson.eiffel.remrem.generate.constants.RemremGenerateServiceConstants.*;
55-
5656
@RestController
5757
@RequestMapping("/*")
5858
@Api(value = "REMReM Generate Service", description = "REST API for generating Eiffel messages")
@@ -76,6 +76,9 @@ public class RemremGenerateController {
7676
@Value("${lenientValidationEnabledToUsers:false}")
7777
private boolean lenientValidationEnabledToUsers;
7878

79+
@Value("${maxSizeOfInputArray:250}")
80+
private int maxSizeOfInputArray = 250;
81+
7982
public void setLenientValidationEnabledToUsers(boolean lenientValidationEnabledToUsers) {
8083
this.lenientValidationEnabledToUsers = lenientValidationEnabledToUsers;
8184
}
@@ -159,6 +162,12 @@ public ResponseEntity<?> generate(final String msgProtocol, final String msgType
159162

160163
if (inputData.isJsonArray()) {
161164
JsonArray inputEventJsonArray = inputData.getAsJsonArray();
165+
166+
if (inputEventJsonArray.size() > maxSizeOfInputArray) {
167+
return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS,
168+
"The number of events in the input array is too high: " + inputEventJsonArray.size() + " > "
169+
+ maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it.");
170+
}
162171
for (JsonElement element : inputEventJsonArray) {
163172
JsonObject generatedEvent = (processEvent(msgProtocol, msgType,
164173
failIfMultipleFound, failIfNoneFound, lookupInExternalERs, lookupLimit,

service/src/main/resources/application.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ event-repository.enabled: false
2828
event-repository.url: http://<host>:<port>/<context-path-if-available>
2929

3030
# lenientValidationEnabledToUsers true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures
31-
lenientValidationEnabledToUsers: false
31+
lenientValidationEnabledToUsers: false
32+
33+
#Maximum number of templates in array passed to generate endpoint
34+
maxSizeOfInputArray: 250

0 commit comments

Comments
 (0)