diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java index d94c32aeae..9949f4a01b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java @@ -47,6 +47,7 @@ import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerResult; import org.springframework.web.reactive.result.method.InvocableHandlerMethod; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.util.DisconnectedClientHelper; /** * Supports the invocation of @@ -61,6 +62,16 @@ public class RequestMappingHandlerAdapter private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class); + /** + * Log category to use for network failure after a client has gone away. + * @see DisconnectedClientHelper + */ + private static final String DISCONNECTED_CLIENT_LOG_CATEGORY = + "org.springframework.web.reactive.result.method.annotation.DisconnectedClient"; + + private static final DisconnectedClientHelper disconnectedClientHelper = + new DisconnectedClientHelper(DISCONNECTED_CLIENT_LOG_CATEGORY); + private List> messageReaders = Collections.emptyList(); @@ -298,10 +309,12 @@ public class RequestMappingHandlerAdapter return invocable.invoke(exchange, bindingContext, arguments); } catch (Throwable invocationEx) { - // Any other than the original exception (or a cause) is unintended here, - // probably an accident (e.g. failed assertion or the like). - if (!exceptions.contains(invocationEx) && logger.isWarnEnabled()) { - logger.warn(exchange.getLogPrefix() + "Failure in @ExceptionHandler " + invocable, invocationEx); + if (!disconnectedClientHelper.checkAndLogClientDisconnectedException(invocationEx)) { + // Any other than the original exception (or a cause) is unintended here, + // probably an accident (e.g. failed assertion or the like). + if (!exceptions.contains(invocationEx) && logger.isWarnEnabled()) { + logger.warn(exchange.getLogPrefix() + "Failure in @ExceptionHandler " + invocable, invocationEx); + } } } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java index 067fb5af9c..3e5d1f0dd8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java @@ -58,6 +58,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionRes import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; import org.springframework.web.servlet.support.RequestContextUtils; +import org.springframework.web.util.DisconnectedClientHelper; /** * An {@link AbstractHandlerMethodExceptionResolver} that resolves exceptions @@ -76,6 +77,17 @@ import org.springframework.web.servlet.support.RequestContextUtils; public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements ApplicationContextAware, InitializingBean { + /** + * Log category to use for network failure after a client has gone away. + * @see DisconnectedClientHelper + */ + private static final String DISCONNECTED_CLIENT_LOG_CATEGORY = + "org.springframework.web.servlet.mvc.method.annotation.DisconnectedClient"; + + private static final DisconnectedClientHelper disconnectedClientHelper = + new DisconnectedClientHelper(DISCONNECTED_CLIENT_LOG_CATEGORY); + + @Nullable private List customArgumentResolvers; @@ -420,10 +432,12 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, arguments); } catch (Throwable invocationEx) { - // Any other than the original exception (or a cause) is unintended here, - // probably an accident (e.g. failed assertion or the like). - if (!exceptions.contains(invocationEx) && logger.isWarnEnabled()) { - logger.warn("Failure in @ExceptionHandler " + exceptionHandlerMethod, invocationEx); + if (!disconnectedClientHelper.checkAndLogClientDisconnectedException(invocationEx)) { + // Any other than the original exception (or a cause) is unintended here, + // probably an accident (e.g. failed assertion or the like). + if (!exceptions.contains(invocationEx) && logger.isWarnEnabled()) { + logger.warn("Failure in @ExceptionHandler " + exceptionHandlerMethod, invocationEx); + } } // Continue with default processing of the original exception... return null;