我的全局筛选器仅记录成功的请求(200)。例如,代码500不通过ServerHttpRequestDecorator和ServerHttpResponseDecorator。
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequestDecorator requestMutated = new ServerHttpRequestDecorator(exchange.getRequest()) {
@Override
public Flux<DataBuffer> getBody() {
Logger requestLogger = new Logger(getDelegate());
if(LOGGABLE_CONTENT_TYPES.contains(String.valueOf(getHeaders().getContentType()).toLowerCase())) {
return super.getBody().map(ds -> {
requestLogger.appendBody(ds.asByteBuffer());
return ds;
}).doFinally(s -> requestLogger.log());
} else {
requestLogger.log();
return super.getBody();
}
}
};
ServerHttpResponseDecorator responseMutated = new ServerHttpResponseDecorator(exchange.getResponse()) {
@Override
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
Logger responseLogger = new Logger(getDelegate());
if(LOGGABLE_CONTENT_TYPES.contains(String.valueOf(getHeaders().getContentType()).toLowerCase())) {
return join(body).flatMap(db -> {
responseLogger.appendBody(db.asByteBuffer());
responseLogger.log();
return getDelegate().writeWith(Mono.just(db));
});
} else {
responseLogger.log();
return getDelegate().writeWith(body);
}
}
};
return chain.filter(exchange.mutate().request(requestMutated).response(responseMutated).build());
ServerResponse.status(HttpStatus.valueOf(statusCode)) .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromValue(errorPropertiesMap))
=〉不记录请求和响应;
我做错什么了?谢谢你的帮助。
1条答案
按热度按时间yzuktlbb1#
尝试在application.yml中启用这些属性: