Skip to content

Commit 428e8db

Browse files
martingrswltr
authored andcommitted
Make the maximum request body size configurable
With Javalin, the maximum request body size is 1 MB by default. This is quite limiting and would prevent even moderately sized plant models from being loaded into the kernel via the web API. Therefore, set the maximum request body size to a more reasonable 200 MB by default, which should be more than sufficient for most use cases. Merged-by: Stefan Walter <stefan.walter@iml.fraunhofer.de>
1 parent 6b295e1 commit 428e8db

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

opentcs-documentation/src/docs/release-notes/changelog.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This change log lists the most relevant changes for past releases in reverse chr
3030
*** Add support for Server-Sent Events (SSE) to the web API.
3131
As an alternative to the `GET /events` endpoint, clients can use the `GET /sse` endpoint to subscribe to events that are sent by the kernel.
3232
*** Use Javalin instead of Spark as the framework for the web API implementation.
33+
The maximum size of request bodies can now be configured via the `servicewebapi.maxRequestBodySize` configuration entry.
3334
* Bugs fixed:
3435
** Properly allow updates of a vehicle's acceptable order types via the `PUT /vehicles/{NAME}/acceptableOrderTypes` web API endpoint.
3536
** Avoid `NullPointerException` when trying to save transport order definitions in the continuous load panel.

opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/ServiceWebApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ public void initialize() {
105105
Consumer<JavalinConfig> config = cfg -> {
106106
cfg.showJavalinBanner = false;
107107
cfg.router.apiBuilder(v1RequestHandler.createRoutes());
108+
if (configuration.maxRequestBodySize() <= 0) {
109+
LOG.warn(
110+
"Maximum request body size must be at least 1 MB. Using default size of {} bytes.",
111+
cfg.http.maxRequestSize
112+
);
113+
}
114+
else {
115+
cfg.http.maxRequestSize = configuration.maxRequestBodySize() * 1024L * 1024L;
116+
}
108117

109118
if (configuration.useSsl()) {
110119
cfg.registerPlugin(

opentcs-kernel-extension-http-services/src/main/java/org/opentcs/kernel/extensions/servicewebapi/ServiceWebApiConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ public interface ServiceWebApiConfiguration {
6363
orderKey = "5"
6464
)
6565
boolean useSsl();
66+
67+
@ConfigurationEntry(
68+
type = "Integer",
69+
description = "The maximum size (in MB) that a request body may have for it to be processed.",
70+
changesApplied = ConfigurationEntry.ChangesApplied.ON_APPLICATION_START,
71+
orderKey = "6"
72+
)
73+
int maxRequestBodySize();
6674
}

opentcs-kernel/src/main/resources/org/opentcs/kernel/distribution/config/opentcs-kernel-defaults-baseline.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ servicewebapi.bindAddress = 0.0.0.0
4747
servicewebapi.bindPort = 55200
4848
servicewebapi.accessKey =
4949
servicewebapi.statusEventsCapacity = 1000
50+
servicewebapi.maxRequestBodySize = 200
5051

5152
defaultdispatcher.dismissUnroutableTransportOrders = true
5253
defaultdispatcher.assignRedundantOrders = false

0 commit comments

Comments
 (0)