mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Exclude DataAccessException and MessagingException in DisconnectedClientHelper
Closes gh-36134
This commit is contained in:
@@ -76,6 +76,8 @@ dependencies {
|
||||
testImplementation(testFixtures(project(":spring-beans")))
|
||||
testImplementation(testFixtures(project(":spring-context")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation(testFixtures(project(":spring-messaging")))
|
||||
testImplementation(testFixtures(project(":spring-tx")))
|
||||
testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8")
|
||||
testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||
testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -48,11 +48,13 @@ public class DisconnectedClientHelper {
|
||||
Set.of("AbortedException", "ClientAbortException",
|
||||
"EOFException", "EofException", "AsyncRequestNotUsableException");
|
||||
|
||||
private static final Set<Class<?>> CLIENT_EXCEPTION_TYPES = new HashSet<>(2);
|
||||
private static final Set<Class<?>> EXCLUDED_EXCEPTION_TYPES = new LinkedHashSet<>(4);
|
||||
|
||||
static {
|
||||
registerClientExceptionType("org.springframework.web.client.RestClientException");
|
||||
registerClientExceptionType("org.springframework.web.reactive.function.client.WebClientException");
|
||||
addExcludedExceptionType("org.springframework.web.client.RestClientException");
|
||||
addExcludedExceptionType("org.springframework.web.reactive.function.client.WebClientException");
|
||||
addExcludedExceptionType("org.springframework.dao.DataAccessException");
|
||||
addExcludedExceptionType("org.springframework.messaging.MessagingException");
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +105,7 @@ public class DisconnectedClientHelper {
|
||||
Throwable lastEx = null;
|
||||
while (currentEx != null && currentEx != lastEx) {
|
||||
// Ignore onward connection issues to other servers (500 error)
|
||||
for (Class<?> exceptionType : CLIENT_EXCEPTION_TYPES) {
|
||||
for (Class<?> exceptionType : EXCLUDED_EXCEPTION_TYPES) {
|
||||
if (exceptionType.isInstance(currentEx)) {
|
||||
return false;
|
||||
}
|
||||
@@ -128,10 +130,10 @@ public class DisconnectedClientHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void registerClientExceptionType(String type) {
|
||||
private static void addExcludedExceptionType(String type) {
|
||||
try {
|
||||
ClassLoader classLoader = DisconnectedClientHelper.class.getClassLoader();
|
||||
CLIENT_EXCEPTION_TYPES.add(ClassUtils.forName(type, classLoader));
|
||||
EXCLUDED_EXCEPTION_TYPES.add(ClassUtils.forName(type, classLoader));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// ignore
|
||||
|
||||
+11
-7
@@ -28,7 +28,9 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import reactor.netty.channel.AbortedException;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
import org.springframework.web.context.request.async.AsyncRequestNotUsableException;
|
||||
import org.springframework.web.testfixture.http.MockHttpInputMessage;
|
||||
@@ -78,16 +80,18 @@ public class DisconnectedClientHelperTests {
|
||||
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue();
|
||||
}
|
||||
|
||||
@Test // gh-34264
|
||||
void onwardClientDisconnectedExceptionPhrase() {
|
||||
Exception ex = new ResourceAccessException("I/O error", new EOFException("Connection reset by peer"));
|
||||
@ParameterizedTest // gh-34264
|
||||
@MethodSource("excludedExceptionsTypes")
|
||||
void excludedExceptionTypes(Exception ex) {
|
||||
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void onwardClientDisconnectedExceptionType() {
|
||||
Exception ex = new ResourceAccessException("I/O error", new EOFException());
|
||||
assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isFalse();
|
||||
static List<Exception> excludedExceptionsTypes() {
|
||||
EOFException cause = new EOFException();
|
||||
return List.of(
|
||||
new ResourceAccessException("", cause),
|
||||
new DataAccessResourceFailureException("", new EOFException()),
|
||||
new MessagingException("", cause));
|
||||
}
|
||||
|
||||
@Test // gh-34533
|
||||
|
||||
Reference in New Issue
Block a user