Skip to content

Commit 1107a43

Browse files
committed
Upgrade to Jetty 12.1 onWebSocketClose signature
Includes switch to catching Throwable instead of Exception. See spring-projectsgh-35345
1 parent 3fb3b3d commit 1107a43

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public JettyWebSocketHandlerAdapter(WebSocketHandler webSocketHandler, JettyWebS
5757
this.wsSession = wsSession;
5858
}
5959

60+
6061
@Override
6162
public void onWebSocketOpen(Session session) {
6263
try {
@@ -65,7 +66,7 @@ public void onWebSocketOpen(Session session) {
6566
this.webSocketHandler.afterConnectionEstablished(this.wsSession);
6667
this.nativeSession.demand();
6768
}
68-
catch (Exception ex) {
69+
catch (Throwable ex) {
6970
tryCloseWithError(ex);
7071
}
7172
}
@@ -78,7 +79,7 @@ public void onWebSocketText(String payload) {
7879
this.webSocketHandler.handleMessage(this.wsSession, message);
7980
this.nativeSession.demand();
8081
}
81-
catch (Exception ex) {
82+
catch (Throwable ex) {
8283
tryCloseWithError(ex);
8384
}
8485
}
@@ -92,7 +93,7 @@ public void onWebSocketBinary(ByteBuffer payload, Callback callback) {
9293
this.webSocketHandler.handleMessage(this.wsSession, message);
9394
this.nativeSession.demand();
9495
}
95-
catch (Exception ex) {
96+
catch (Throwable ex) {
9697
tryCloseWithError(ex);
9798
}
9899
}
@@ -105,18 +106,19 @@ public void onWebSocketPong(ByteBuffer payload) {
105106
this.webSocketHandler.handleMessage(this.wsSession, message);
106107
this.nativeSession.demand();
107108
}
108-
catch (Exception ex) {
109+
catch (Throwable ex) {
109110
tryCloseWithError(ex);
110111
}
111112
}
112113

113114
@Override
114-
public void onWebSocketClose(int statusCode, String reason) {
115+
public void onWebSocketClose(int statusCode, String reason, Callback callback) {
115116
CloseStatus closeStatus = new CloseStatus(statusCode, reason);
117+
callback.succeed();
116118
try {
117119
this.webSocketHandler.afterConnectionClosed(this.wsSession, closeStatus);
118120
}
119-
catch (Exception ex) {
121+
catch (Throwable ex) {
120122
if (logger.isWarnEnabled()) {
121123
logger.warn("Unhandled exception from afterConnectionClosed for " + this, ex);
122124
}
@@ -128,7 +130,7 @@ public void onWebSocketError(Throwable cause) {
128130
try {
129131
this.webSocketHandler.handleTransportError(this.wsSession, cause);
130132
}
131-
catch (Exception ex) {
133+
catch (Throwable ex) {
132134
if (logger.isWarnEnabled()) {
133135
logger.warn("Unhandled exception from handleTransportError for " + this, ex);
134136
}
@@ -146,4 +148,5 @@ private void tryCloseWithError(Throwable t) {
146148
}
147149
}
148150
}
151+
149152
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void onMessage(jakarta.websocket.PongMessage message) {
102102
try {
103103
this.handler.afterConnectionEstablished(this.wsSession);
104104
}
105-
catch (Exception ex) {
105+
catch (Throwable ex) {
106106
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
107107
}
108108
}
@@ -112,7 +112,7 @@ private void handleTextMessage(jakarta.websocket.Session session, String payload
112112
try {
113113
this.handler.handleMessage(this.wsSession, textMessage);
114114
}
115-
catch (Exception ex) {
115+
catch (Throwable ex) {
116116
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
117117
}
118118
}
@@ -122,7 +122,7 @@ private void handleBinaryMessage(jakarta.websocket.Session session, ByteBuffer p
122122
try {
123123
this.handler.handleMessage(this.wsSession, binaryMessage);
124124
}
125-
catch (Exception ex) {
125+
catch (Throwable ex) {
126126
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
127127
}
128128
}
@@ -132,7 +132,7 @@ private void handlePongMessage(jakarta.websocket.Session session, ByteBuffer pay
132132
try {
133133
this.handler.handleMessage(this.wsSession, pongMessage);
134134
}
135-
catch (Exception ex) {
135+
catch (Throwable ex) {
136136
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
137137
}
138138
}
@@ -143,7 +143,7 @@ public void onClose(jakarta.websocket.Session session, CloseReason reason) {
143143
try {
144144
this.handler.afterConnectionClosed(this.wsSession, closeStatus);
145145
}
146-
catch (Exception ex) {
146+
catch (Throwable ex) {
147147
if (logger.isWarnEnabled()) {
148148
logger.warn("Unhandled on-close exception for " + this.wsSession, ex);
149149
}
@@ -155,7 +155,7 @@ public void onError(jakarta.websocket.Session session, Throwable exception) {
155155
try {
156156
this.handler.handleTransportError(this.wsSession, exception);
157157
}
158-
catch (Exception ex) {
158+
catch (Throwable ex) {
159159
ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
160160
}
161161
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.socket.adapter.jetty;
1818

19+
import org.eclipse.jetty.websocket.api.Callback;
1920
import org.eclipse.jetty.websocket.api.Session;
2021
import org.junit.jupiter.api.BeforeEach;
2122
import org.junit.jupiter.api.Test;
@@ -57,7 +58,7 @@ void onOpen() throws Exception {
5758

5859
@Test
5960
void onClose() throws Exception {
60-
this.adapter.onWebSocketClose(1000, "reason");
61+
this.adapter.onWebSocketClose(1000, "reason", Callback.NOOP);
6162
verify(this.webSocketHandler).afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL.withReason("reason"));
6263
}
6364

0 commit comments

Comments
 (0)