Use ServerHttpResponse.getRawStatusCode() in WebFluxTags

See gh-19987
pull/20523/head
Johnny Lim 5 years ago committed by Stephane Nicoll
parent 8f61a4bf39
commit 1721aeccb0

@ -22,7 +22,6 @@ import io.micrometer.core.instrument.Tag;
import org.springframework.boot.actuate.metrics.http.Outcome;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.HandlerMapping;
@ -164,11 +163,9 @@ public final class WebFluxTags {
private static Integer extractStatusCode(ServerWebExchange exchange) {
ServerHttpResponse response = exchange.getResponse();
if (response instanceof AbstractServerHttpResponse) {
Integer statusCode = ((AbstractServerHttpResponse) response).getStatusCodeValue();
if (statusCode != null) {
return statusCode;
}
Integer statusCode = response.getRawStatusCode();
if (statusCode != null) {
return statusCode;
}
HttpStatus status = response.getStatusCode();
return (status != null) ? status.value() : null;

@ -21,8 +21,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.web.reactive.HandlerMapping;
@ -123,9 +123,9 @@ class WebFluxTagsTests {
void outcomeTagIsSuccessWhenResponseStatusIsAvailableFromUnderlyingServer() {
ServerWebExchange exchange = mock(ServerWebExchange.class);
ServerHttpRequest request = mock(ServerHttpRequest.class);
AbstractServerHttpResponse response = mock(AbstractServerHttpResponse.class);
ServerHttpResponse response = mock(ServerHttpResponse.class);
given(response.getStatusCode()).willReturn(HttpStatus.OK);
given(response.getStatusCodeValue()).willReturn(null);
given(response.getRawStatusCode()).willReturn(null);
given(exchange.getRequest()).willReturn(request);
given(exchange.getResponse()).willReturn(response);
Tag tag = WebFluxTags.outcome(exchange);

Loading…
Cancel
Save