Skip to content

Commit ea091e0

Browse files
committed
Increase WebFlux Buffer Size
1 parent 1cc4b5f commit ea091e0

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.medizininformatikinitiative.torch.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.http.codec.ServerCodecConfigurer;
5+
import org.springframework.web.reactive.config.WebFluxConfigurer;
6+
7+
@Configuration
8+
public class WebFluxServerConfig implements WebFluxConfigurer {
9+
10+
@Override
11+
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
12+
// Increase the max buffer size for incoming requests to 2 MB
13+
configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024);
14+
}
15+
}
16+

src/test/java/de/medizininformatikinitiative/torch/FhirControllerIT.java

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
import de.numcodex.sq2cql.Translator;
1818
import de.numcodex.sq2cql.model.structured_query.StructuredQuery;
1919
import org.hl7.fhir.r4.model.OperationOutcome;
20-
import org.junit.jupiter.api.Assertions;
21-
import org.junit.jupiter.api.BeforeAll;
22-
import org.junit.jupiter.api.Nested;
23-
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.TestInstance;
20+
import org.junit.jupiter.api.*;
2521
import org.junit.jupiter.params.ParameterizedTest;
2622
import org.junit.jupiter.params.provider.ValueSource;
2723
import org.slf4j.Logger;
@@ -31,11 +27,7 @@
3127
import org.springframework.beans.factory.annotation.Value;
3228
import org.springframework.boot.test.context.SpringBootTest;
3329
import org.springframework.boot.test.web.client.TestRestTemplate;
34-
import org.springframework.http.HttpEntity;
35-
import org.springframework.http.HttpHeaders;
36-
import org.springframework.http.HttpMethod;
37-
import org.springframework.http.MediaType;
38-
import org.springframework.http.ResponseEntity;
30+
import org.springframework.http.*;
3931
import org.springframework.test.annotation.DirtiesContext;
4032
import org.springframework.test.context.ActiveProfiles;
4133
import org.springframework.web.client.HttpStatusCodeException;
@@ -306,5 +298,53 @@ void invalidCRTDLReturnsValidationException(String parametersFile) {
306298
headers.add("content-type", "application/fhir+json");
307299
testExecutor(parametersFile, "http://localhost:" + port + "/fhir/$extract-data", headers, 400);
308300
}
301+
302+
@Test
303+
void testPayloadJustBelow2Mb() {
304+
HttpHeaders headers = new HttpHeaders();
305+
headers.setContentType(MediaType.valueOf("application/fhir+json"));
306+
307+
// Generate JSON payload just below 2 MB
308+
String payload = buildJsonPayload(2 * 1024 * 1024 - 50); // 2MB - 50 bytes
309+
310+
TestRestTemplate restTemplate = new TestRestTemplate();
311+
HttpEntity<String> entity = new HttpEntity<>(payload, headers);
312+
313+
ResponseEntity<String> response = restTemplate.postForEntity(
314+
"http://localhost:" + port + "/fhir/$extract-data",
315+
entity,
316+
String.class
317+
);
318+
319+
assertThat(response.getStatusCode().value()).isEqualTo(400);
320+
}
321+
322+
@Test
323+
void testPayloadJustAbove2Mb() {
324+
HttpHeaders headers = new HttpHeaders();
325+
headers.setContentType(MediaType.valueOf("application/fhir+json"));
326+
327+
// Generate JSON payload just above 2 MB
328+
String payload = buildJsonPayload(2 * 1024 * 1024 + 50); // 2MB + 50 bytes
329+
330+
TestRestTemplate restTemplate = new TestRestTemplate();
331+
HttpEntity<String> entity = new HttpEntity<>(payload, headers);
332+
333+
ResponseEntity<String> response = restTemplate.postForEntity(
334+
"http://localhost:" + port + "/fhir/$extract-data",
335+
entity,
336+
String.class
337+
);
338+
339+
// Expect failure due to exceeding maxInMemorySize
340+
assertThat(response.getStatusCode().is5xxServerError()).isTrue();
341+
}
342+
343+
private String buildJsonPayload(int sizeInBytes) {
344+
// Simple JSON with a single string field
345+
return "{\"parameter\":[{\"name\":\"data\",\"valueString\":\"" +
346+
"x".repeat(Math.max(0, sizeInBytes)) +
347+
"\"}]}";
348+
}
309349
}
310350
}

0 commit comments

Comments
 (0)