有没有一种方法可以捕获Spring Webflux中的响应主体。我知道这违反了反应性原则,但是我需要捕获身体并返回响应。我正在使用ExchangeFilterFunction。
public Optional<ExchangeFilterFunction> buildEnricher() {
return Optional.of(ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
return clientResponse.bodyToMono(String.class)
.flatMap(body -> {
System.out.println(body);
return Mono.just(clientResponse);
});
}));
这将最终消耗主体并发送空的客户端响应。反正我还能把尸体寄回去吗?
您可以选择克隆客户端响应。
ClientResponse responseClone = ClientResponse.from(clientResponse)
您现在可以排干身体responseClone
并返回Mono.just(clientResponse)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句