I'm new to Spring Cloud Gateway (spring boot 2.0.5.RELEASE). I try to read the request body from a web filter and the request is just stuck and cannot flow through the chain. Sample code:
@Component
public class TestFilter implements GlobalFilter, Ordered {
private static final Logger logger = LoggerFactory.getLogger(TestFilter.class);
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest serverHttpRequest = exchange.getRequest();
try {
/* whenever I put the following line. The request cannot get through */
ByteBuffer byteBuffer = Mono.from(serverHttpRequest.getBody()).toFuture().get().asByteBuffer();
} catch (Exception ex) {
ex.printStackTrace();
}
return chain.filter(exchange);
}
}
If I remove the getBody() line, everything works fine. Any clue? Thx!