Top Description Fields Constructors Methods
org.springframework.web.socket.adapter.standard

public Class StandardWebSocketSession

extends AbstractWebSocketSession<Session>
Class Inheritance
Imports
java.io.IOException, java.net.InetSocketAddress, .URI, java.security.Principal, java.util.ArrayList, .Collections, .List, .Map, jakarta.websocket.CloseReason, .CloseReason.CloseCodes, .Extension, .Session, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, org.springframework.web.socket.BinaryMessage, .CloseStatus, .PingMessage, .PongMessage, .TextMessage, .WebSocketExtension, .WebSocketSession, org.springframework.web.socket.adapter.AbstractWebSocketSession

A WebSocketSession for use with the standard WebSocket for Java API.
Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private String
private List<WebSocketExtension>
private final HttpHeaders
private final String
private final InetSocketAddress
private final InetSocketAddress
private URI
private Principal
Inherited from org.springframework.web.socket.adapter.AbstractWebSocketSession:
idGeneratorlogger

Constructor Summary

AccessConstructor and Description
public
StandardWebSocketSession(HttpHeaders
the headers of the handshake request
headers
,
Map<String, Object>
the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
attributes
,
InetSocketAddress
the address on which the request was received
localAddress
,
InetSocketAddress
the address of the remote client
remoteAddress
)

Constructor for a standard WebSocket session.

public
StandardWebSocketSession(HttpHeaders
the headers of the handshake request
headers
,
Map<String, Object>
the attributes from the HTTP handshake to associate with the WebSocket session
attributes
,
InetSocketAddress
the address on which the request was received
localAddress
,
InetSocketAddress
the address of the remote client
remoteAddress
,
Principal
the user associated with the session; if null we'll fall back on the user available in the underlying WebSocket session
user
)

Constructor that associates a user with the WebSocket session.

Method Summary

Modifier and TypeMethod and Description
protected void
public String
public int
getBinaryMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Get the configured maximum size for an incoming binary message.

public List<WebSocketExtension>
getExtensions()

Implements org.springframework.web.socket.WebSocketSession.getExtensions.

Determine the negotiated extensions.

public HttpHeaders
getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

public String
getId()

Implements org.springframework.web.socket.WebSocketSession.getId.

Return a unique session identifier.

public InetSocketAddress
getLocalAddress()

Implements org.springframework.web.socket.WebSocketSession.getLocalAddress.

Return the address on which the request was received.

public Principal
getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

public InetSocketAddress
getRemoteAddress()

Implements org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Return the address of the remote client.

public int
getTextMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Get the configured maximum size for an incoming text message.

public URI
getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

public void
public boolean
isOpen()

Implements org.springframework.web.socket.WebSocketSession.isOpen.

Whether the underlying connection is open.

protected void
protected void
protected void
protected void
public void
setBinaryMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Configure the maximum size for an incoming binary message.

public void
setTextMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Configure the maximum size for an incoming text message.

Inherited from org.springframework.web.socket.adapter.AbstractWebSocketSession:
checkNativeSessionInitializedcloseclosegetAttributesgetNativeSessiongetNativeSessionsendMessagetoString

Field Detail

acceptedProtocolback to summary
private String acceptedProtocol
Annotations
@Nullable
extensionsback to summary
private List<WebSocketExtension> extensions
Annotations
@Nullable
handshakeHeadersback to summary
private final HttpHeaders handshakeHeaders
idback to summary
private final String id
localAddressback to summary
private final InetSocketAddress localAddress
Annotations
@Nullable
remoteAddressback to summary
private final InetSocketAddress remoteAddress
Annotations
@Nullable
uriback to summary
private URI uri
Annotations
@Nullable
userback to summary
private Principal user
Annotations
@Nullable

Constructor Detail

StandardWebSocketSessionback to summary
public StandardWebSocketSession(HttpHeaders headers, Map<String, Object> attributes, InetSocketAddress localAddress, InetSocketAddress remoteAddress)

Constructor for a standard WebSocket session.

Parameters
headers:HttpHeaders

the headers of the handshake request

attributes:Map<String, Object>

the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.

localAddress:InetSocketAddress

the address on which the request was received

remoteAddress:InetSocketAddress

the address of the remote client

StandardWebSocketSessionback to summary
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:HttpHeaders

the headers of the handshake request

attributes:Map<String, Object>

the attributes from the HTTP handshake to associate with the WebSocket session

localAddress:InetSocketAddress

the address on which the request was received

remoteAddress:InetSocketAddress

the address of the remote client

user:Principal

the user associated with the session; if null we'll fall back on the user available in the underlying WebSocket session

Method Detail

closeInternalback to summary
protected void closeInternal(CloseStatus status) throws IOException

Implements abstract org.springframework.web.socket.adapter.AbstractWebSocketSession.closeInternal.

Annotations
@Override
getAcceptedProtocolback to summary
public String getAcceptedProtocol()

Implements org.springframework.web.socket.WebSocketSession.getAcceptedProtocol.

Doc from org.springframework.web.socket.WebSocketSession.getAcceptedProtocol.

Return the negotiated sub-protocol.

Returns:String

the protocol identifier, or null if no protocol was specified or negotiated successfully

Annotations
@Override
getBinaryMessageSizeLimitback to summary
public int getBinaryMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Get the configured maximum size for an incoming binary message.

Annotations
@Override
getExtensionsback to summary
public List<WebSocketExtension> getExtensions()

Implements org.springframework.web.socket.WebSocketSession.getExtensions.

Doc from org.springframework.web.socket.WebSocketSession.getExtensions.

Determine the negotiated extensions.

Returns:List<WebSocketExtension>

the list of extensions, or an empty list if no extension was specified or negotiated successfully

Annotations
@Override
getHandshakeHeadersback to summary
public HttpHeaders getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Doc from org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

Annotations
@Override
getIdback to summary
public String getId()

Implements org.springframework.web.socket.WebSocketSession.getId.

Doc from org.springframework.web.socket.WebSocketSession.getId.

Return a unique session identifier.

Annotations
@Override
getLocalAddressback to summary
public InetSocketAddress getLocalAddress()

Implements org.springframework.web.socket.WebSocketSession.getLocalAddress.

Doc from org.springframework.web.socket.WebSocketSession.getLocalAddress.

Return the address on which the request was received.

Annotations
@Override
@Nullable
getPrincipalback to summary
public Principal getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Doc from org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

If the user has not been authenticated, the method returns null.

Annotations
@Override
getRemoteAddressback to summary
public InetSocketAddress getRemoteAddress()

Implements org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Doc from org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Return the address of the remote client.

Annotations
@Override
@Nullable
getTextMessageSizeLimitback to summary
public int getTextMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Get the configured maximum size for an incoming text message.

Annotations
@Override
getUriback to summary
public URI getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Doc from org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

Annotations
@Override
@Nullable
initializeNativeSessionback to summary
public void initializeNativeSession(Session session)

Overrides org.springframework.web.socket.adapter.AbstractWebSocketSession.initializeNativeSession.

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Implements org.springframework.web.socket.WebSocketSession.isOpen.

Doc from org.springframework.web.socket.WebSocketSession.isOpen.

Whether the underlying connection is open.

Annotations
@Override
sendBinaryMessageback to summary
protected void sendBinaryMessage(BinaryMessage message) throws IOException

Implements abstract org.springframework.web.socket.adapter.AbstractWebSocketSession.sendBinaryMessage.

Annotations
@Override
sendPingMessageback to summary
protected void sendPingMessage(PingMessage message) throws IOException

Implements abstract org.springframework.web.socket.adapter.AbstractWebSocketSession.sendPingMessage.

Annotations
@Override
sendPongMessageback to summary
protected void sendPongMessage(PongMessage message) throws IOException

Implements abstract org.springframework.web.socket.adapter.AbstractWebSocketSession.sendPongMessage.

Annotations
@Override
sendTextMessageback to summary
protected void sendTextMessage(TextMessage message) throws IOException

Implements abstract org.springframework.web.socket.adapter.AbstractWebSocketSession.sendTextMessage.

Annotations
@Override
setBinaryMessageSizeLimitback to summary
public void setBinaryMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Configure the maximum size for an incoming binary message.

Annotations
@Override
setTextMessageSizeLimitback to summary
public void setTextMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Configure the maximum size for an incoming text message.

Annotations
@Override