Class JettyWebSocketSession
java.lang.Object
org.springframework.web.socket.adapter.AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
org.springframework.web.socket.adapter.jetty.JettyWebSocketSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,NativeWebSocketSession
,WebSocketSession
public class JettyWebSocketSession
extends AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
A
WebSocketSession
for use with the Jetty 9.4 WebSocket API.- Since:
- 4.0
- Author:
- Phillip Webb, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
-
Field Summary
Fields inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession
idGenerator, logger
-
Constructor Summary
ConstructorDescriptionJettyWebSocketSession
(Map<String, Object> attributes) Create a newJettyWebSocketSession
instance.JettyWebSocketSession
(Map<String, Object> attributes, Principal user) Create a newJettyWebSocketSession
instance associated with the given user. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
closeInternal
(CloseStatus status) Return the negotiated sub-protocol.int
Get the configured maximum size for an incoming binary message.Determine the negotiated extensions.Return the headers used in the handshake request (nevernull
).getId()
Return a unique session identifier.Return the address on which the request was received.Return aPrincipal
instance containing the name of the authenticated user.Return the address of the remote client.int
Get the configured maximum size for an incoming text message.getUri()
Return the URI used to open the WebSocket connection.void
initializeNativeSession
(org.eclipse.jetty.websocket.api.Session session) boolean
isOpen()
Whether the underlying connection is open.protected void
sendBinaryMessage
(BinaryMessage message) protected void
sendPingMessage
(PingMessage message) protected void
sendPongMessage
(PongMessage message) protected void
sendTextMessage
(TextMessage message) void
setBinaryMessageSizeLimit
(int messageSizeLimit) This method is a no-op for Jetty.void
setTextMessageSizeLimit
(int messageSizeLimit) This method is a no-op for Jetty.Methods inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession
checkNativeSessionInitialized, close, close, getAttributes, getNativeSession, getNativeSession, sendMessage, toString
-
Constructor Details
-
JettyWebSocketSession
Create a newJettyWebSocketSession
instance.- Parameters:
attributes
- the attributes from the HTTP handshake to associate with the WebSocket session
-
JettyWebSocketSession
Create a newJettyWebSocketSession
instance associated with the given user.- Parameters:
attributes
- the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.user
- the user associated with the session; ifnull
we'll fallback on the user available viaSession.getUpgradeRequest()
-
-
Method Details
-
getId
Description copied from interface:WebSocketSession
Return a unique session identifier. -
getUri
Description copied from interface:WebSocketSession
Return the URI used to open the WebSocket connection. -
getHandshakeHeaders
Description copied from interface:WebSocketSession
Return the headers used in the handshake request (nevernull
). -
getAcceptedProtocol
Description copied from interface:WebSocketSession
Return the negotiated sub-protocol.- Returns:
- the protocol identifier, or
null
if no protocol was specified or negotiated successfully
-
getExtensions
Description copied from interface:WebSocketSession
Determine the negotiated extensions.- Returns:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
-
getPrincipal
Description copied from interface:WebSocketSession
Return aPrincipal
instance containing the name of the authenticated user.If the user has not been authenticated, the method returns
null
. -
getLocalAddress
Description copied from interface:WebSocketSession
Return the address on which the request was received. -
getRemoteAddress
Description copied from interface:WebSocketSession
Return the address of the remote client. -
setTextMessageSizeLimit
public void setTextMessageSizeLimit(int messageSizeLimit) This method is a no-op for Jetty. As perSession.getPolicy()
, the returnedWebSocketPolicy
is read-only and changing it has no effect. -
getTextMessageSizeLimit
public int getTextMessageSizeLimit()Description copied from interface:WebSocketSession
Get the configured maximum size for an incoming text message. -
setBinaryMessageSizeLimit
public void setBinaryMessageSizeLimit(int messageSizeLimit) This method is a no-op for Jetty. As perSession.getPolicy()
, the returnedWebSocketPolicy
is read-only and changing it has no effect. -
getBinaryMessageSizeLimit
public int getBinaryMessageSizeLimit()Description copied from interface:WebSocketSession
Get the configured maximum size for an incoming binary message. -
isOpen
public boolean isOpen()Description copied from interface:WebSocketSession
Whether the underlying connection is open. -
initializeNativeSession
public void initializeNativeSession(org.eclipse.jetty.websocket.api.Session session) - Overrides:
initializeNativeSession
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
-
sendTextMessage
- Specified by:
sendTextMessage
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
- Throws:
IOException
-
sendBinaryMessage
- Specified by:
sendBinaryMessage
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
- Throws:
IOException
-
sendPingMessage
- Specified by:
sendPingMessage
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
- Throws:
IOException
-
sendPongMessage
- Specified by:
sendPongMessage
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
- Throws:
IOException
-
closeInternal
- Specified by:
closeInternal
in classAbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
- Throws:
IOException
-