diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java index 8b7daafd5c9..8afe4a624fd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java @@ -18,10 +18,8 @@ package org.springframework.boot.autoconfigure.web.reactive.error; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; import reactor.core.publisher.Mono; @@ -33,7 +31,6 @@ import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.reactive.error.ErrorAttributes; import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler; import org.springframework.context.ApplicationContext; -import org.springframework.core.NestedExceptionUtils; import org.springframework.core.io.Resource; import org.springframework.core.log.LogMessage; import org.springframework.http.HttpLogging; @@ -49,6 +46,7 @@ import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.util.DisconnectedClientHelper; import org.springframework.web.util.HtmlUtils; /** @@ -61,19 +59,6 @@ import org.springframework.web.util.HtmlUtils; */ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExceptionHandler, InitializingBean { - /** - * Currently duplicated from Spring Web's DisconnectedClientHelper. - */ - private static final Set DISCONNECTED_CLIENT_EXCEPTIONS; - - static { - Set exceptions = new HashSet<>(); - exceptions.add("ClientAbortException"); - exceptions.add("EOFException"); - exceptions.add("EofException"); - DISCONNECTED_CLIENT_EXCEPTIONS = Collections.unmodifiableSet(exceptions); - } - private static final Log logger = HttpLogging.forLogName(AbstractErrorWebExceptionHandler.class); private final ApplicationContext applicationContext; @@ -305,13 +290,7 @@ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExcept } private boolean isDisconnectedClientError(Throwable ex) { - return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName()) - || isDisconnectedClientErrorMessage(NestedExceptionUtils.getMostSpecificCause(ex).getMessage()); - } - - private boolean isDisconnectedClientErrorMessage(String message) { - message = (message != null) ? message.toLowerCase() : ""; - return (message.contains("broken pipe") || message.contains("connection reset by peer")); + return DisconnectedClientHelper.isClientDisconnectedException(ex); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java index a704411e835..8662c71bedb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java @@ -33,12 +33,10 @@ import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.result.view.View; import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.util.DisconnectedClientHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -54,14 +52,6 @@ import static org.mockito.Mockito.mock; */ class DefaultErrorWebExceptionHandlerTests { - @Test - void disconnectedClientExceptionsMatchesFramework() { - Object errorHandlers = ReflectionTestUtils.getField(AbstractErrorWebExceptionHandler.class, - "DISCONNECTED_CLIENT_EXCEPTIONS"); - Object webHandlers = ReflectionTestUtils.getField(DisconnectedClientHelper.class, "EXCEPTION_TYPE_NAMES"); - assertThat(errorHandlers).isNotNull().isEqualTo(webHandlers); - } - @Test void nonStandardErrorStatusCodeShouldNotFail() { ErrorAttributes errorAttributes = mock(ErrorAttributes.class);