|
|
@ -73,11 +73,11 @@ public class HttpTraceWebFilter implements WebFilter, Ordered {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
|
|
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
|
|
|
Mono<?> principal = this.includes.contains(Include.PRINCIPAL)
|
|
|
|
Mono<?> principal = (this.includes.contains(Include.PRINCIPAL)
|
|
|
|
? exchange.getPrincipal().cast(Object.class).defaultIfEmpty(NONE)
|
|
|
|
? exchange.getPrincipal().cast(Object.class).defaultIfEmpty(NONE)
|
|
|
|
: Mono.just(NONE);
|
|
|
|
: Mono.just(NONE));
|
|
|
|
Mono<?> session = this.includes.contains(Include.SESSION_ID)
|
|
|
|
Mono<?> session = (this.includes.contains(Include.SESSION_ID)
|
|
|
|
? exchange.getSession() : Mono.just(NONE);
|
|
|
|
? exchange.getSession() : Mono.just(NONE));
|
|
|
|
return Mono.zip(principal, session)
|
|
|
|
return Mono.zip(principal, session)
|
|
|
|
.flatMap((tuple) -> filter(exchange, chain,
|
|
|
|
.flatMap((tuple) -> filter(exchange, chain,
|
|
|
|
asType(tuple.getT1(), Principal.class),
|
|
|
|
asType(tuple.getT1(), Principal.class),
|
|
|
@ -97,17 +97,17 @@ public class HttpTraceWebFilter implements WebFilter, Ordered {
|
|
|
|
exchange);
|
|
|
|
exchange);
|
|
|
|
HttpTrace trace = this.tracer.receivedRequest(request);
|
|
|
|
HttpTrace trace = this.tracer.receivedRequest(request);
|
|
|
|
return chain.filter(exchange).doAfterSuccessOrError((aVoid, ex) -> {
|
|
|
|
return chain.filter(exchange).doAfterSuccessOrError((aVoid, ex) -> {
|
|
|
|
this.tracer.sendingResponse(trace,
|
|
|
|
TraceableServerHttpResponse response = new TraceableServerHttpResponse(
|
|
|
|
new TraceableServerHttpResponse(ex == null ? exchange.getResponse()
|
|
|
|
(ex != null ? new CustomStatusResponseDecorator(ex,
|
|
|
|
: new CustomStatusResponseDecorator(ex,
|
|
|
|
exchange.getResponse()) : exchange.getResponse()));
|
|
|
|
exchange.getResponse())),
|
|
|
|
this.tracer.sendingResponse(trace, response, () -> principal,
|
|
|
|
() -> principal, () -> getStartedSessionId(session));
|
|
|
|
() -> getStartedSessionId(session));
|
|
|
|
this.repository.add(trace);
|
|
|
|
this.repository.add(trace);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getStartedSessionId(WebSession session) {
|
|
|
|
private String getStartedSessionId(WebSession session) {
|
|
|
|
return (session != null && session.isStarted()) ? session.getId() : null;
|
|
|
|
return (session != null && session.isStarted() ? session.getId() : null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final class CustomStatusResponseDecorator
|
|
|
|
private static final class CustomStatusResponseDecorator
|
|
|
@ -117,9 +117,9 @@ public class HttpTraceWebFilter implements WebFilter, Ordered {
|
|
|
|
|
|
|
|
|
|
|
|
private CustomStatusResponseDecorator(Throwable ex, ServerHttpResponse delegate) {
|
|
|
|
private CustomStatusResponseDecorator(Throwable ex, ServerHttpResponse delegate) {
|
|
|
|
super(delegate);
|
|
|
|
super(delegate);
|
|
|
|
this.status = ex instanceof ResponseStatusException
|
|
|
|
this.status = (ex instanceof ResponseStatusException
|
|
|
|
? ((ResponseStatusException) ex).getStatus()
|
|
|
|
? ((ResponseStatusException) ex).getStatus()
|
|
|
|
: HttpStatus.INTERNAL_SERVER_ERROR;
|
|
|
|
: HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|