Class StandardWebSocketSession
- java.lang.Object
- org.springframework.web.socket.adapter.AbstractWebSocketSession<Session>
- org.springframework.web.socket.adapter.standard.StandardWebSocketSession
- All Implemented Interfaces:
Closeable,AutoCloseable,NativeWebSocketSession,WebSocketSession
public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
AWebSocketSessionfor use with the standard WebSocket for Java API.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession
logger
Constructor Summary
Constructors Constructor Description StandardWebSocketSession(HttpHeaders headers, Map<String,Object> attributes, InetSocketAddress localAddress, InetSocketAddress remoteAddress)Constructor for a standard WebSocket session.StandardWebSocketSession(HttpHeaders headers, Map<String,Object> attributes, InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user)Constructor that associates a user with the WebSocket session.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseInternal(CloseStatus status)StringgetAcceptedProtocol()Return the negotiated sub-protocol.intgetBinaryMessageSizeLimit()Get the configured maximum size for an incoming binary message.List<WebSocketExtension>getExtensions()Determine the negotiated extensions.HttpHeadersgetHandshakeHeaders()Return the headers used in the handshake request (nevernull).StringgetId()Return a unique session identifier.InetSocketAddressgetLocalAddress()Return the address on which the request was received.PrincipalgetPrincipal()Return aPrincipalinstance containing the name of the authenticated user.InetSocketAddressgetRemoteAddress()Return the address of the remote client.intgetTextMessageSizeLimit()Get the configured maximum size for an incoming text message.URIgetUri()Return the URI used to open the WebSocket connection.voidinitializeNativeSession(Session session)booleanisOpen()Return whether the connection is still open.protected voidsendBinaryMessage(BinaryMessage message)protected voidsendPingMessage(PingMessage message)protected voidsendPongMessage(PongMessage message)protected voidsendTextMessage(TextMessage message)voidsetBinaryMessageSizeLimit(int messageSizeLimit)Configure the maximum size for an incoming binary message.voidsetTextMessageSizeLimit(int messageSizeLimit)Configure the maximum size for an incoming text message.Methods inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession
checkNativeSessionInitialized, close, close, getAttributes, getNativeSession, getNativeSession, sendMessage, toString
Constructor Detail
StandardWebSocketSession
public StandardWebSocketSession(HttpHeaders headers, Map<String,Object> attributes, InetSocketAddress localAddress, InetSocketAddress remoteAddress)
Constructor for a standard WebSocket session.- Parameters:
headers- the headers of the handshake requestattributes- attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.localAddress- the address on which the request was receivedremoteAddress- the address of the remote client
StandardWebSocketSession
public StandardWebSocketSession(HttpHeaders headers, Map<String,Object> attributes, InetSocketAddress localAddress, InetSocketAddress remoteAddress, Principal user)
Constructor that associates a user with the WebSocket session.- Parameters:
headers- the headers of the handshake requestattributes- attributes from the HTTP handshake to associate with the WebSocket sessionlocalAddress- the address on which the request was receivedremoteAddress- the address of the remote clientuser- the user associated with the session; ifnullwe'll fallback on the user available in the underlying WebSocket session
Method Detail
getId
public String getId()
Description copied from interface:WebSocketSessionReturn a unique session identifier.
getUri
public URI getUri()
Description copied from interface:WebSocketSessionReturn the URI used to open the WebSocket connection.
getHandshakeHeaders
public HttpHeaders getHandshakeHeaders()
Description copied from interface:WebSocketSessionReturn the headers used in the handshake request (nevernull).
getAcceptedProtocol
public String getAcceptedProtocol()
Description copied from interface:WebSocketSessionReturn the negotiated sub-protocol.- Returns:
- the protocol identifier, or
nullif no protocol was specified or negotiated successfully
getExtensions
public List<WebSocketExtension> getExtensions()
Description copied from interface:WebSocketSessionDetermine the negotiated extensions.- Returns:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
getPrincipal
public Principal getPrincipal()
Description copied from interface:WebSocketSessionReturn aPrincipalinstance containing the name of the authenticated user.If the user has not been authenticated, the method returns
null.
getLocalAddress
public InetSocketAddress getLocalAddress()
Description copied from interface:WebSocketSessionReturn the address on which the request was received.
getRemoteAddress
public InetSocketAddress getRemoteAddress()
Description copied from interface:WebSocketSessionReturn the address of the remote client.
setTextMessageSizeLimit
public void setTextMessageSizeLimit(int messageSizeLimit)
Description copied from interface:WebSocketSessionConfigure the maximum size for an incoming text message.
getTextMessageSizeLimit
public int getTextMessageSizeLimit()
Description copied from interface:WebSocketSessionGet the configured maximum size for an incoming text message.
setBinaryMessageSizeLimit
public void setBinaryMessageSizeLimit(int messageSizeLimit)
Description copied from interface:WebSocketSessionConfigure the maximum size for an incoming binary message.
getBinaryMessageSizeLimit
public int getBinaryMessageSizeLimit()
Description copied from interface:WebSocketSessionGet the configured maximum size for an incoming binary message.
isOpen
public boolean isOpen()
Description copied from interface:WebSocketSessionReturn whether the connection is still open.
initializeNativeSession
public void initializeNativeSession(Session session)
- Overrides:
initializeNativeSessionin classAbstractWebSocketSession<Session>
sendTextMessage
protected void sendTextMessage(TextMessage message) throws IOException
- Specified by:
sendTextMessagein classAbstractWebSocketSession<Session>- Throws:
IOException
sendBinaryMessage
protected void sendBinaryMessage(BinaryMessage message) throws IOException
- Specified by:
sendBinaryMessagein classAbstractWebSocketSession<Session>- Throws:
IOException
sendPingMessage
protected void sendPingMessage(PingMessage message) throws IOException
- Specified by:
sendPingMessagein classAbstractWebSocketSession<Session>- Throws:
IOException
sendPongMessage
protected void sendPongMessage(PongMessage message) throws IOException
- Specified by:
sendPongMessagein classAbstractWebSocketSession<Session>- Throws:
IOException
closeInternal
protected void closeInternal(CloseStatus status) throws IOException
- Specified by:
closeInternalin classAbstractWebSocketSession<Session>- Throws:
IOException