【发布时间】:2021-07-15 13:54:15
【问题描述】:
我正在注册过滤器以记录来自 WebClient 的响应,但我只想记录 POST 和 PATCH 请求(没有大量我不感兴趣的 GET 请求)。如何只记录特定的 POST 和 PATCH 响应?
WebClient bean:
@Bean
public WebClient sfWebClient() {
return WebClient.builder()
.filter(logResponse())
.build();
}
logResponse 过滤器:
ExchangeFilterFunction logResponse() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
if (log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Request finished with the status: ").append(clientResponse.statusCode());
log.debug(sb.toString());
}
return Mono.just(clientResponse);
});
}
【问题讨论】:
标签: java spring-boot rest logging webclient