diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java index e819f6050257..0c414a6b11eb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -71,7 +71,7 @@ public void onWebSocketConnect(Session session) { this.wsSession.initializeNativeSession(session); this.webSocketHandler.afterConnectionEstablished(this.wsSession); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -82,7 +82,7 @@ public void onWebSocketText(String payload) { try { this.webSocketHandler.handleMessage(this.wsSession, message); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -93,7 +93,7 @@ public void onWebSocketBinary(byte[] payload, int offset, int length) { try { this.webSocketHandler.handleMessage(this.wsSession, message); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -106,7 +106,7 @@ public void onWebSocketFrame(Frame frame) { try { this.webSocketHandler.handleMessage(this.wsSession, message); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -118,7 +118,7 @@ public void onWebSocketClose(int statusCode, String reason) { try { this.webSocketHandler.afterConnectionClosed(this.wsSession, closeStatus); } - catch (Throwable ex) { + catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn("Unhandled exception after connection closed for " + this, ex); } @@ -130,7 +130,7 @@ public void onWebSocketError(Throwable cause) { try { this.webSocketHandler.handleTransportError(this.wsSession, cause); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java index 787511f18d65..c4c11a30d963 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -103,7 +103,7 @@ public void onMessage(javax.websocket.PongMessage message) { try { this.handler.afterConnectionEstablished(this.wsSession); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -113,7 +113,7 @@ private void handleTextMessage(javax.websocket.Session session, String payload, try { this.handler.handleMessage(this.wsSession, textMessage); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -123,7 +123,7 @@ private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer pay try { this.handler.handleMessage(this.wsSession, binaryMessage); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -133,7 +133,7 @@ private void handlePongMessage(javax.websocket.Session session, ByteBuffer paylo try { this.handler.handleMessage(this.wsSession, pongMessage); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } @@ -144,7 +144,7 @@ public void onClose(javax.websocket.Session session, CloseReason reason) { try { this.handler.afterConnectionClosed(this.wsSession, closeStatus); } - catch (Throwable ex) { + catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn("Unhandled on-close exception for " + this.wsSession, ex); } @@ -156,7 +156,7 @@ public void onError(javax.websocket.Session session, Throwable exception) { try { this.handler.handleTransportError(this.wsSession, exception); } - catch (Throwable ex) { + catch (Exception ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } } 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 104e70371b39..96d7a2d697b2 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-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -47,7 +47,7 @@ public void afterConnectionEstablished(WebSocketSession session) { try { getDelegate().afterConnectionEstablished(session); } - catch (Throwable ex) { + catch (Exception ex) { tryCloseWithError(session, ex, logger); } } @@ -57,7 +57,7 @@ public void handleMessage(WebSocketSession session, WebSocketMessage message) try { getDelegate().handleMessage(session, message); } - catch (Throwable ex) { + catch (Exception ex) { tryCloseWithError(session, ex, logger); } } @@ -67,7 +67,7 @@ public void handleTransportError(WebSocketSession session, Throwable exception) try { getDelegate().handleTransportError(session, exception); } - catch (Throwable ex) { + catch (Exception ex) { tryCloseWithError(session, ex, logger); } } @@ -77,7 +77,7 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus closeSta try { getDelegate().afterConnectionClosed(session, closeStatus); } - catch (Throwable ex) { + catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn("Unhandled exception after connection closed for " + this, ex); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java index b0d8828f8b3d..47384d84b498 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -157,7 +157,7 @@ else if (websphereWsPresent) { Class clazz = ClassUtils.forName(className, AbstractHandshakeHandler.class.getClassLoader()); return (RequestUpgradeStrategy) ReflectionUtils.accessibleConstructor(clazz).newInstance(); } - catch (Throwable ex) { + catch (Exception ex) { throw new IllegalStateException( "Failed to instantiate RequestUpgradeStrategy: " + className, ex); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeInterceptorChain.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeInterceptorChain.java index f853aa51f339..5484a5229824 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeInterceptorChain.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeInterceptorChain.java @@ -77,7 +77,7 @@ public void applyAfterHandshake( try { interceptor.afterHandshake(request, response, this.wsHandler, failure); } - catch (Throwable ex) { + catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn(interceptor + " threw exception in afterHandshake: " + ex); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHttpRequestHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHttpRequestHandler.java index 279cf8f9f60b..d4abeba3ace9 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHttpRequestHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHttpRequestHandler.java @@ -171,7 +171,7 @@ public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse catch (HandshakeFailureException ex) { failure = ex; } - catch (Throwable ex) { + catch (Exception ex) { failure = new HandshakeFailureException("Uncaught failure for request " + request.getURI(), ex); } finally { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java index 974ee2680455..03338f9bfae1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -244,7 +244,7 @@ private void handleOpenFrame() { this.webSocketHandler.afterConnectionEstablished(this); this.connectFuture.set(this); } - catch (Throwable ex) { + catch (Exception ex) { if (logger.isErrorEnabled()) { logger.error("WebSocketHandler.afterConnectionEstablished threw exception in " + this, ex); } @@ -293,7 +293,7 @@ private void handleMessageFrame(SockJsFrame frame) { try { this.webSocketHandler.handleMessage(this, new TextMessage(message)); } - catch (Throwable ex) { + catch (Exception ex) { logger.error("WebSocketHandler.handleMessage threw an exception on " + frame + " in " + this, ex); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java index b8c7ff362093..ba8deed6e498 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransport.java @@ -118,7 +118,7 @@ protected void connectInternal(final TransportRequest transportRequest, final We getRestTemplate().execute(receiveUrl, HttpMethod.POST, requestCallback, responseExtractor); requestCallback = requestCallbackAfterHandshake; } - catch (Throwable ex) { + catch (Exception ex) { if (!connectFuture.isDone()) { connectFuture.setException(ex); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java index f9eac2bd4166..88d81e71586f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -260,7 +260,7 @@ public final ListenableFuture doHandshake( ServerInfo serverInfo = getServerInfo(sockJsUrlInfo, getHttpRequestHeaders(headers)); createRequest(sockJsUrlInfo, headers, serverInfo).connect(handler, connectFuture); } - catch (Throwable exception) { + catch (Exception exception) { if (logger.isErrorEnabled()) { logger.error("Initial SockJS \"Info\" request to server failed, url=" + url, exception); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java index c158d3bb502f..887864d570aa 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 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. @@ -133,7 +133,7 @@ public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse try { this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler); } - catch (Throwable ex) { + catch (Exception ex) { throw new SockJsException("Uncaught failure in SockJS request, uri=" + request.getURI(), ex); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java index fc13a2ef5ab3..40a19881077c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -215,10 +215,10 @@ protected void handleRawWebSocketRequest(ServerHttpRequest request, ServerHttpRe catch (HandshakeFailureException ex) { failure = ex; } - catch (Throwable ex) { + catch (Exception ex) { failure = new HandshakeFailureException("Uncaught failure for request " + request.getURI(), ex); } - finally { + finally { if (failure != null) { chain.applyAfterHandshake(request, response, failure); throw failure; @@ -316,7 +316,7 @@ else if (transportType.supportsCors()) { catch (SockJsException ex) { failure = ex; } - catch (Throwable ex) { + catch (Exception ex) { failure = new SockJsException("Uncaught failure for request " + request.getURI(), sessionId, ex); } finally { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java index 60e396368807..1e3e933dac86 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -72,7 +72,7 @@ protected void handleRequestInternal(ServerHttpRequest request, ServerHttpRespon } return; } - catch (Throwable ex) { + catch (Exception ex) { logger.error("Failed to read message", ex); handleReadError(response, "Failed to read message(s)", sockJsSession.getId()); return; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java index 60423319dc6d..77e7bbe2f0c9 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java @@ -124,7 +124,7 @@ public void handleRequest(ServerHttpRequest request, ServerHttpResponse response wsHandler = new SockJsWebSocketHandler(getServiceConfig(), wsHandler, sockJsSession); this.handshakeHandler.doHandshake(request, response, wsHandler, sockJsSession.getAttributes()); } - catch (Throwable ex) { + catch (Exception ex) { sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("WebSocket handshake failure", wsSession.getId(), ex); } 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 9115f64d9b85..cc950ea4870d 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 @@ -324,7 +324,7 @@ protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureExcept try { writeFrameInternal(frame); } - catch (Throwable ex) { + catch (Exception ex) { logWriteFrameFailure(ex); try { // Force disconnect (so we won't try to send close frame) @@ -388,7 +388,7 @@ public void delegateMessages(String... messages) throws SockJsMessageDeliveryExc undelivered.remove(0); } } - catch (Throwable ex) { + catch (Exception ex) { throw new SockJsMessageDeliveryException(this.id, undelivered, ex); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java index 35d73332b577..a8ed9363270d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java @@ -166,7 +166,7 @@ public void initializeDelegateSession(WebSocketSession session) { scheduleHeartbeat(); this.openFrameSent = true; } - catch (Throwable ex) { + catch (Exception ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); } } @@ -186,7 +186,7 @@ public void handleMessage(TextMessage message, WebSocketSession wsSession) throw try { messages = getSockJsServiceConfig().getMessageCodec().decode(payload); } - catch (Throwable ex) { + catch (Exception ex) { logger.error("Broken data received. Terminating WebSocket connection abruptly", ex); tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA); return;