diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java index 33d4310576..0250f19431 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java @@ -131,43 +131,36 @@ public final class RestTemplateExchangeTags { } /** - * Creates a {@code outcome} {@code Tag} derived from the + * Creates an {@code outcome} {@code Tag} derived from the * {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}. * @param response the response * @return the outcome tag * @since 2.2.0 */ public static Tag outcome(ClientHttpResponse response) { - HttpStatus status = extractStatus(response); - if (status != null) { - if (status.is1xxInformational()) { - return OUTCOME_INFORMATIONAL; - } - if (status.is2xxSuccessful()) { - return OUTCOME_SUCCESS; - } - if (status.is3xxRedirection()) { - return OUTCOME_REDIRECTION; - } - if (status.is4xxClientError()) { - return OUTCOME_CLIENT_ERROR; - } - if (status.is5xxServerError()) { - return OUTCOME_SERVER_ERROR; - } - } - return OUTCOME_UNKNOWN; - } - - private static HttpStatus extractStatus(ClientHttpResponse response) { try { if (response != null) { - return response.getStatusCode(); + HttpStatus statusCode = response.getStatusCode(); + if (statusCode.is1xxInformational()) { + return OUTCOME_INFORMATIONAL; + } + if (statusCode.is2xxSuccessful()) { + return OUTCOME_SUCCESS; + } + if (statusCode.is3xxRedirection()) { + return OUTCOME_REDIRECTION; + } + if (statusCode.is4xxClientError()) { + return OUTCOME_CLIENT_ERROR; + } + if (statusCode.is5xxServerError()) { + return OUTCOME_SERVER_ERROR; + } } - return null; + return OUTCOME_UNKNOWN; } - catch (IOException | IllegalArgumentException exc) { - return null; + catch (IOException | IllegalArgumentException ex) { + return OUTCOME_UNKNOWN; } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java index 8d488c25ae..25adc976d1 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java @@ -126,7 +126,7 @@ public final class WebClientExchangeTags { } /** - * Creates a {@code outcome} {@code Tag} derived from the + * Creates an {@code outcome} {@code Tag} derived from the * {@link ClientResponse#statusCode() status} of the given {@code response}. * @param response the response * @return the outcome tag diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java index 14614b53e6..6f1c7cc16a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java @@ -34,12 +34,11 @@ import static org.mockito.Mockito.mock; * * @author Nishant Raut * @author Brian Clozel - * @author Brian Clozel */ public class RestTemplateExchangeTagsTests { @Test - public void outcomeTagIsUnknownWhenResponseStatusIsNull() { + public void outcomeTagIsUnknownWhenResponseIsNull() { Tag tag = RestTemplateExchangeTags.outcome(null); assertThat(tag.getValue()).isEqualTo("UNKNOWN"); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java index 686db658a5..5133bd8527 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java @@ -34,7 +34,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; /** - * Tests for {@link WebClientExchangeTags} + * Tests for {@link WebClientExchangeTags}. * * @author Brian Clozel * @author Nishant Raut @@ -115,7 +115,7 @@ public class WebClientExchangeTagsTests { } @Test - public void outcomeTagIsUnknownWhenResponseStatusIsNull() { + public void outcomeTagIsUnknownWhenResponseIsNull() { Tag tag = WebClientExchangeTags.outcome(null); assertThat(tag.getValue()).isEqualTo("UNKNOWN"); } @@ -156,7 +156,7 @@ public class WebClientExchangeTagsTests { } @Test - public void outcomeTagIsUknownWhenResponseStatusIsUknown() { + public void outcomeTagIsUnknownWhenResponseStatusIsUnknown() { given(this.response.statusCode()).willThrow(IllegalArgumentException.class); Tag tag = WebClientExchangeTags.outcome(this.response); assertThat(tag.getValue()).isEqualTo("UNKNOWN");