Browse Source

Upgrade to Jetty 12.1 onWebSocketClose signature

Includes switch to catching Throwable instead of Exception.

See gh-35345
pull/35447/head
Juergen Hoeller 5 months ago
parent
commit
1107a43b65
  1. 17
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java
  2. 12
      spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java
  3. 3
      spring-websocket/src/test/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapterTests.java

17
spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java

@ -57,6 +57,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -146,4 +148,5 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener {
}
}
}
}

12
spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketHandlerAdapter.java

@ -102,7 +102,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}

3
spring-websocket/src/test/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapterTests.java

@ -16,6 +16,7 @@ @@ -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 { @@ -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"));
}

Loading…
Cancel
Save