Skip to content

Commit 3fb58cd

Browse files
committed
Wrap Jetty WebSocketException
Issue: SPR-14267
1 parent 1e003a1 commit 3fb58cd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,9 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
2728
import org.eclipse.jetty.websocket.api.Session;
29+
import org.eclipse.jetty.websocket.api.WebSocketException;
2830
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
2931

3032
import org.springframework.http.HttpHeaders;
@@ -185,22 +187,31 @@ public void initializeNativeSession(Session session) {
185187

186188
@Override
187189
protected void sendTextMessage(TextMessage message) throws IOException {
188-
getNativeSession().getRemote().sendString(message.getPayload());
190+
getRemoteEndpoint().sendString(message.getPayload());
189191
}
190192

191193
@Override
192194
protected void sendBinaryMessage(BinaryMessage message) throws IOException {
193-
getNativeSession().getRemote().sendBytes(message.getPayload());
195+
getRemoteEndpoint().sendBytes(message.getPayload());
194196
}
195197

196198
@Override
197199
protected void sendPingMessage(PingMessage message) throws IOException {
198-
getNativeSession().getRemote().sendPing(message.getPayload());
200+
getRemoteEndpoint().sendPing(message.getPayload());
199201
}
200202

201203
@Override
202204
protected void sendPongMessage(PongMessage message) throws IOException {
203-
getNativeSession().getRemote().sendPong(message.getPayload());
205+
getRemoteEndpoint().sendPong(message.getPayload());
206+
}
207+
208+
private RemoteEndpoint getRemoteEndpoint() throws IOException {
209+
try {
210+
return getNativeSession().getRemote();
211+
}
212+
catch (WebSocketException ex) {
213+
throw new IOException("Unable to obtain RemoteEndpoint in session=" + getId(), ex);
214+
}
204215
}
205216

206217
@Override

0 commit comments

Comments
 (0)