-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
Describe the bug
When I try to read or modify the request body in spring-cloud-gateway-mvc, the body is removed from the request and this exception is thrown:
java.lang.NullPointerException: Cannot invoke "java.util.Map.put(Object, Object)" because the return value of "org.springframework.cloud.gateway.server.mvc.common.MvcUtils.getGatewayAttributes(org.springframework.web.servlet.function.ServerRequest)" is null
I'm using Spring Boot 3.2.2 and cloud 2023.0.0
Sample
I have tried using the BeforeFilterFunctions.modifyRequestBody:
.before(modifyRequestBody(String.class, String.class, MediaType.APPLICATION_JSON_VALUE, (serverRequest, s) -> s))
.. and also a regular filter like this:
.filter((request, next) -> {
byte[] bytes = StreamUtils.copyToByteArray(request.servletRequest().getInputStream());
String requestBody = new String(bytes, StandardCharsets.UTF_8);
LOGGER.info(requestBody);
return next.handle(request);
})
I have used the example from the documentation: ModifyRequestBody Filter
Reactions are currently unavailable