diff options
author | Emmanuel Bourg <ebourg@apache.org> | 2017-07-04 11:41:53 +0200 |
---|---|---|
committer | Emmanuel Bourg <ebourg@apache.org> | 2017-07-04 11:41:53 +0200 |
commit | 16cac1f52d8e8159e0e688b2fda3f89291cec969 (patch) | |
tree | 027fd3c0b671bf73a45f27af2a16881c4098f7e7 /spring-websocket/src/main/java | |
parent | 5b251f9ca7596793d669a9a36eb0d83ccd56f983 (diff) |
New upstream version 4.3.9
Diffstat (limited to 'spring-websocket/src/main/java')
2 files changed, 28 insertions, 31 deletions
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/handler/ExceptionWebSocketHandlerDecorator.java b/spring-websocket/src/main/java/org/springframework/web/socket/handler/ExceptionWebSocketHandlerDecorator.java index 72863562..5e0ea0b8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/handler/ExceptionWebSocketHandlerDecorator.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/handler/ExceptionWebSocketHandlerDecorator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,8 +86,8 @@ public class ExceptionWebSocketHandlerDecorator extends WebSocketHandlerDecorato public static void tryCloseWithError(WebSocketSession session, Throwable exception, Log logger) { - if (logger.isDebugEnabled()) { - logger.debug("Closing due to exception for " + session, exception); + if (logger.isErrorEnabled()) { + logger.error("Closing session due to exception for " + session, exception); } if (session.isOpen()) { try { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java index c8a45096..925f36b6 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java @@ -19,7 +19,6 @@ package org.springframework.web.socket.sockjs.transport.session; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -31,7 +30,7 @@ import java.util.concurrent.ScheduledFuture; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.core.NestedCheckedException; +import org.springframework.core.NestedExceptionUtils; import org.springframework.util.Assert; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; @@ -71,24 +70,21 @@ public abstract class AbstractSockJsSession implements SockJsSession { "org.springframework.web.socket.sockjs.DisconnectedClient"; /** + * Tomcat: ClientAbortException or EOFException + * Jetty: EofException + * WildFly, GlassFish: java.io.IOException "Broken pipe" (already covered) + * @see #indicatesDisconnectedClient(Throwable) + */ + private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = + new HashSet<String>(Arrays.asList("ClientAbortException", "EOFException", "EofException")); + + + /** * Separate logger to use on network IO failure after a client has gone away. * @see #DISCONNECTED_CLIENT_LOG_CATEGORY */ protected static final Log disconnectedClientLogger = LogFactory.getLog(DISCONNECTED_CLIENT_LOG_CATEGORY); - - private static final Set<String> disconnectedClientExceptions; - - static { - Set<String> set = new HashSet<String>(4); - set.add("ClientAbortException"); // Tomcat - set.add("EOFException"); // Tomcat - set.add("EofException"); // Jetty - // java.io.IOException "Broken pipe" on WildFly, Glassfish (already covered) - disconnectedClientExceptions = Collections.unmodifiableSet(set); - } - - protected final Log logger = LogFactory.getLog(getClass()); protected final Object responseLock = new Object(); @@ -340,28 +336,28 @@ public abstract class AbstractSockJsSession implements SockJsSession { } } - private void logWriteFrameFailure(Throwable failure) { - @SuppressWarnings("serial") - NestedCheckedException nestedException = new NestedCheckedException("", failure) {}; - - if ("Broken pipe".equalsIgnoreCase(nestedException.getMostSpecificCause().getMessage()) || - disconnectedClientExceptions.contains(failure.getClass().getSimpleName())) { + protected abstract void writeFrameInternal(SockJsFrame frame) throws IOException; + private void logWriteFrameFailure(Throwable ex) { + if (indicatesDisconnectedClient(ex)) { if (disconnectedClientLogger.isTraceEnabled()) { - disconnectedClientLogger.trace("Looks like the client has gone away", failure); + disconnectedClientLogger.trace("Looks like the client has gone away", ex); } else if (disconnectedClientLogger.isDebugEnabled()) { - disconnectedClientLogger.debug("Looks like the client has gone away: " + - nestedException.getMessage() + " (For full stack trace, set the '" + - DISCONNECTED_CLIENT_LOG_CATEGORY + "' log category to TRACE level)"); + disconnectedClientLogger.debug("Looks like the client has gone away: " + ex + + " (For a full stack trace, set the log category '" + DISCONNECTED_CLIENT_LOG_CATEGORY + + "' to TRACE level.)"); } } else { - logger.debug("Terminating connection after failure to send message to client", failure); + logger.debug("Terminating connection after failure to send message to client", ex); } } - protected abstract void writeFrameInternal(SockJsFrame frame) throws IOException; + private boolean indicatesDisconnectedClient(Throwable ex) { + return ("Broken pipe".equalsIgnoreCase(NestedExceptionUtils.getMostSpecificCause(ex).getMessage()) || + DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())); + } // Delegation methods @@ -421,7 +417,8 @@ public abstract class AbstractSockJsSession implements SockJsSession { delegateError(error); } catch (Throwable delegateException) { - // ignore + // Ignore + logger.debug("Exception from error handling delegate", delegateException); } try { close(closeStatus); |