Skip to content

Commit 6dff3c5

Browse files
committed
Adapt to change in Framework's disconnected client detection
See gh-38666
1 parent ad5b844 commit 6dff3c5

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818

1919
import java.util.Collections;
2020
import java.util.Date;
21-
import java.util.HashSet;
2221
import java.util.List;
2322
import java.util.Map;
24-
import java.util.Set;
2523

2624
import org.apache.commons.logging.Log;
2725
import reactor.core.publisher.Mono;
@@ -33,7 +31,6 @@
3331
import org.springframework.boot.web.reactive.error.ErrorAttributes;
3432
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
3533
import org.springframework.context.ApplicationContext;
36-
import org.springframework.core.NestedExceptionUtils;
3734
import org.springframework.core.io.Resource;
3835
import org.springframework.core.log.LogMessage;
3936
import org.springframework.http.HttpLogging;
@@ -49,6 +46,7 @@
4946
import org.springframework.web.reactive.function.server.ServerResponse;
5047
import org.springframework.web.reactive.result.view.ViewResolver;
5148
import org.springframework.web.server.ServerWebExchange;
49+
import org.springframework.web.util.DisconnectedClientHelper;
5250
import org.springframework.web.util.HtmlUtils;
5351

5452
/**
@@ -61,19 +59,6 @@
6159
*/
6260
public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExceptionHandler, InitializingBean {
6361

64-
/**
65-
* Currently duplicated from Spring Web's DisconnectedClientHelper.
66-
*/
67-
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS;
68-
69-
static {
70-
Set<String> exceptions = new HashSet<>();
71-
exceptions.add("ClientAbortException");
72-
exceptions.add("EOFException");
73-
exceptions.add("EofException");
74-
DISCONNECTED_CLIENT_EXCEPTIONS = Collections.unmodifiableSet(exceptions);
75-
}
76-
7762
private static final Log logger = HttpLogging.forLogName(AbstractErrorWebExceptionHandler.class);
7863

7964
private final ApplicationContext applicationContext;
@@ -305,13 +290,7 @@ public Mono<Void> handle(ServerWebExchange exchange, Throwable throwable) {
305290
}
306291

307292
private boolean isDisconnectedClientError(Throwable ex) {
308-
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())
309-
|| isDisconnectedClientErrorMessage(NestedExceptionUtils.getMostSpecificCause(ex).getMessage());
310-
}
311-
312-
private boolean isDisconnectedClientErrorMessage(String message) {
313-
message = (message != null) ? message.toLowerCase() : "";
314-
return (message.contains("broken pipe") || message.contains("connection reset by peer"));
293+
return DisconnectedClientHelper.isClientDisconnectedException(ex);
315294
}
316295

317296
/**

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333
import org.springframework.http.codec.ServerCodecConfigurer;
3434
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
3535
import org.springframework.mock.web.server.MockServerWebExchange;
36-
import org.springframework.test.util.ReflectionTestUtils;
3736
import org.springframework.web.reactive.function.server.ServerRequest;
3837
import org.springframework.web.reactive.result.view.View;
3938
import org.springframework.web.reactive.result.view.ViewResolver;
4039
import org.springframework.web.server.ServerWebExchange;
41-
import org.springframework.web.util.DisconnectedClientHelper;
4240

4341
import static org.assertj.core.api.Assertions.assertThat;
4442
import static org.mockito.ArgumentMatchers.any;
@@ -54,14 +52,6 @@
5452
*/
5553
class DefaultErrorWebExceptionHandlerTests {
5654

57-
@Test
58-
void disconnectedClientExceptionsMatchesFramework() {
59-
Object errorHandlers = ReflectionTestUtils.getField(AbstractErrorWebExceptionHandler.class,
60-
"DISCONNECTED_CLIENT_EXCEPTIONS");
61-
Object webHandlers = ReflectionTestUtils.getField(DisconnectedClientHelper.class, "EXCEPTION_TYPE_NAMES");
62-
assertThat(errorHandlers).isNotNull().isEqualTo(webHandlers);
63-
}
64-
6555
@Test
6656
void nonStandardErrorStatusCodeShouldNotFail() {
6757
ErrorAttributes errorAttributes = mock(ErrorAttributes.class);

0 commit comments

Comments
 (0)