From 5157a7511929fdc27d4fd0aa24a11cf522ffb0b6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 13 May 2020 11:34:58 -0700 Subject: [PATCH 1/2] Polish --- .../CompositeHandlerExceptionResolver.java | 15 ++++++--------- ...ChildContextConfigurationIntegrationTests.java | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolver.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolver.java index 3fc31ffc596..62dbbd402a3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolver.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolver.java @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -52,15 +51,13 @@ class CompositeHandlerExceptionResolver implements HandlerExceptionResolver { if (this.resolvers == null) { this.resolvers = extractResolvers(); } - Optional modelAndView = this.resolvers.stream() + ModelAndView resolved = this.resolvers.stream() .map((resolver) -> resolver.resolveException(request, response, handler, ex)).filter(Objects::nonNull) - .findFirst(); - modelAndView.ifPresent((mav) -> { - if (mav.isEmpty()) { - request.setAttribute("javax.servlet.error.exception", ex); - } - }); - return modelAndView.orElse(null); + .findFirst().orElse(null); + if (resolved != null && resolved.isEmpty()) { + request.setAttribute("javax.servlet.error.exception", ex); + } + return resolved; } private List extractResolvers() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationIntegrationTests.java index 5ed26b0f28d..679f13b72a7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationIntegrationTests.java @@ -120,7 +120,7 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests { @SuppressWarnings("unchecked") private Map getResponseBody(ClientResponse response) { - return (Map) response.bodyToMono(Map.class).block(); + return response.bodyToMono(Map.class).block(); } @Endpoint(id = "fail") From daed512076796bb1de51f0d04ff5ca2ebdd3c322 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 13 May 2020 11:36:24 -0700 Subject: [PATCH 2/2] Restore getUseRelativeRedirects in deprecated form Restore the `getUseRelativeRedirects` method with a `Boolean` object result and introduce `isUseRelativeRedirects` for the primitive boolean variant. See gh-20796 --- .../boot/autoconfigure/web/ServerProperties.java | 7 ++++++- .../servlet/TomcatServletWebServerFactoryCustomizer.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index d3a548c6502..b379fa7b83b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -537,7 +537,12 @@ public class ServerProperties { this.redirectContextRoot = redirectContextRoot; } - public boolean getUseRelativeRedirects() { + @Deprecated + public Boolean getUseRelativeRedirects() { + return this.useRelativeRedirects; + } + + public boolean isUseRelativeRedirects() { return this.useRelativeRedirects; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java index 3b4184f4616..ba55a6f7856 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java @@ -54,7 +54,7 @@ public class TomcatServletWebServerFactoryCustomizer if (tomcatProperties.getRedirectContextRoot() != null) { customizeRedirectContextRoot(factory, tomcatProperties.getRedirectContextRoot()); } - customizeUseRelativeRedirects(factory, tomcatProperties.getUseRelativeRedirects()); + customizeUseRelativeRedirects(factory, tomcatProperties.isUseRelativeRedirects()); factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled()); }