mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Upgrade to Jetty 12.1 onWebSocketClose signature
Includes switch to catching Throwable instead of Exception. See gh-35345
This commit is contained in:
+10
-7
@@ -57,6 +57,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
this.wsSession = wsSession;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onWebSocketOpen(Session session) {
|
||||
try {
|
||||
@@ -65,7 +66,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
this.webSocketHandler.afterConnectionEstablished(this.wsSession);
|
||||
this.nativeSession.demand();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
tryCloseWithError(ex);
|
||||
}
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
this.webSocketHandler.handleMessage(this.wsSession, message);
|
||||
this.nativeSession.demand();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
tryCloseWithError(ex);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +93,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
this.webSocketHandler.handleMessage(this.wsSession, message);
|
||||
this.nativeSession.demand();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
tryCloseWithError(ex);
|
||||
}
|
||||
}
|
||||
@@ -105,18 +106,19 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
this.webSocketHandler.handleMessage(this.wsSession, message);
|
||||
this.nativeSession.demand();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
tryCloseWithError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketClose(int statusCode, String reason) {
|
||||
public void onWebSocketClose(int statusCode, String reason, Callback callback) {
|
||||
CloseStatus closeStatus = new CloseStatus(statusCode, reason);
|
||||
callback.succeed();
|
||||
try {
|
||||
this.webSocketHandler.afterConnectionClosed(this.wsSession, closeStatus);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unhandled exception from afterConnectionClosed for " + this, ex);
|
||||
}
|
||||
@@ -128,7 +130,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
try {
|
||||
this.webSocketHandler.handleTransportError(this.wsSession, cause);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unhandled exception from handleTransportError for " + this, ex);
|
||||
}
|
||||
@@ -146,4 +148,5 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -102,7 +102,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.afterConnectionEstablished(this.wsSession);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.handleMessage(this.wsSession, textMessage);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.handleMessage(this.wsSession, binaryMessage);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.handleMessage(this.wsSession, pongMessage);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.afterConnectionClosed(this.wsSession, closeStatus);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unhandled on-close exception for " + this.wsSession, ex);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
try {
|
||||
this.handler.handleTransportError(this.wsSession, exception);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.socket.adapter.jetty;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Callback;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -57,7 +58,7 @@ class JettyWebSocketHandlerAdapterTests {
|
||||
|
||||
@Test
|
||||
void onClose() throws Exception {
|
||||
this.adapter.onWebSocketClose(1000, "reason");
|
||||
this.adapter.onWebSocketClose(1000, "reason", Callback.NOOP);
|
||||
verify(this.webSocketHandler).afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL.withReason("reason"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user