|
1 | 1 | /* |
2 | | - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
24 | 24 | import java.util.List; |
25 | 25 | import java.util.Map; |
26 | 26 |
|
| 27 | +import org.eclipse.jetty.websocket.api.RemoteEndpoint; |
27 | 28 | import org.eclipse.jetty.websocket.api.Session; |
| 29 | +import org.eclipse.jetty.websocket.api.WebSocketException; |
28 | 30 | import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; |
29 | 31 |
|
30 | 32 | import org.springframework.http.HttpHeaders; |
@@ -185,22 +187,31 @@ public void initializeNativeSession(Session session) { |
185 | 187 |
|
186 | 188 | @Override |
187 | 189 | protected void sendTextMessage(TextMessage message) throws IOException { |
188 | | - getNativeSession().getRemote().sendString(message.getPayload()); |
| 190 | + getRemoteEndpoint().sendString(message.getPayload()); |
189 | 191 | } |
190 | 192 |
|
191 | 193 | @Override |
192 | 194 | protected void sendBinaryMessage(BinaryMessage message) throws IOException { |
193 | | - getNativeSession().getRemote().sendBytes(message.getPayload()); |
| 195 | + getRemoteEndpoint().sendBytes(message.getPayload()); |
194 | 196 | } |
195 | 197 |
|
196 | 198 | @Override |
197 | 199 | protected void sendPingMessage(PingMessage message) throws IOException { |
198 | | - getNativeSession().getRemote().sendPing(message.getPayload()); |
| 200 | + getRemoteEndpoint().sendPing(message.getPayload()); |
199 | 201 | } |
200 | 202 |
|
201 | 203 | @Override |
202 | 204 | 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 | + } |
204 | 215 | } |
205 | 216 |
|
206 | 217 | @Override |
|
0 commit comments