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