Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Try to use WebFilter in Spring Boot Webflux in order to log request body
package com.blazemeter.dagger.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
public class ExampleWebFilter implements WebFilter {
public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
ObjectMapper mapper = new ObjectMapper();
return serverWebExchange
.flatMap(body -> {
try {
return Mono.just(mapper.readValue(body.asInputStream(), String.class));
} catch (IOException e) {
return Mono.error(e);
.flatMap((String s) -> {;
return webFilterChain.filter(serverWebExchange);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.