Remove ServerWebExchange dependency in ServerRequestObservationContext

Avoiding cycle between http.server and web.server packages.

See gh-30013
This commit is contained in:
Juergen Hoeller
2023-06-14 21:57:27 +02:00
parent 220995b830
commit f00a8cb3a3
7 changed files with 40 additions and 22 deletions

View File

@@ -51,6 +51,7 @@ class HttpWebHandlerAdapterObservabilityTests {
private final MockServerHttpResponse response = new MockServerHttpResponse();
@Test
void handlerShouldSetObservationContextOnExchange() {
HttpStatusSuccessStubWebHandler targetHandler = new HttpStatusSuccessStubWebHandler(HttpStatus.OK);
@@ -97,6 +98,7 @@ class HttpWebHandlerAdapterObservabilityTests {
.hasObservationWithNameEqualTo("http.server.requests").that();
}
private static class HttpStatusSuccessStubWebHandler implements WebHandler {
private final HttpStatus responseStatus;
@@ -109,12 +111,13 @@ class HttpWebHandlerAdapterObservabilityTests {
@Override
public Mono<Void> handle(ServerWebExchange exchange) {
this.observationContext = ServerRequestObservationContext.findCurrent(exchange);
this.observationContext = ServerRequestObservationContext.findCurrent(exchange.getAttributes());
exchange.getResponse().setStatusCode(this.responseStatus);
return Mono.empty();
}
}
private static class ReactorContextWebHandler implements WebHandler {
ContextView contextView;
@@ -129,6 +132,7 @@ class HttpWebHandlerAdapterObservabilityTests {
}
}
private static class ThrowingExceptionWebHandler implements WebHandler {
private final Throwable exception;
@@ -141,11 +145,12 @@ class HttpWebHandlerAdapterObservabilityTests {
@Override
public Mono<Void> handle(ServerWebExchange exchange) {
this.observationContext = ServerRequestObservationContext.findCurrent(exchange);
this.observationContext = ServerRequestObservationContext.findCurrent(exchange.getAttributes());
return Mono.error(this.exception);
}
}
private static class BadRequestExceptionHandler implements WebExceptionHandler {
@Override