public class JettyWebSocketSession extends AbstractWebSocketSession<Session>
WebSocketSession
for use with the Jetty 9.3/9.4 WebSocket API.Modifier and Type | Field and Description |
---|---|
private java.lang.String |
acceptedProtocol |
private static boolean |
directInterfaceCalls |
private java.util.List<WebSocketExtension> |
extensions |
private static java.lang.reflect.Method |
getAcceptedSubProtocol |
private static java.lang.reflect.Method |
getExtensions |
private static java.lang.reflect.Method |
getHeaders |
private static java.lang.reflect.Method |
getRequestURI |
private static java.lang.reflect.Method |
getUpgradeRequest |
private static java.lang.reflect.Method |
getUpgradeResponse |
private static java.lang.reflect.Method |
getUserPrincipal |
private HttpHeaders |
headers |
private java.lang.String |
id |
private java.net.URI |
uri |
private java.security.Principal |
user |
logger
Constructor and Description |
---|
JettyWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes)
Create a new
JettyWebSocketSession instance. |
JettyWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes,
java.security.Principal user)
Create a new
JettyWebSocketSession instance associated with the given user. |
Modifier and Type | Method and Description |
---|---|
protected void |
closeInternal(CloseStatus status) |
java.lang.String |
getAcceptedProtocol()
Return the negotiated sub-protocol.
|
int |
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.
|
java.util.List<WebSocketExtension> |
getExtensions()
Determine the negotiated extensions.
|
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request (never
null ). |
java.lang.String |
getId()
Return a unique session identifier.
|
java.net.InetSocketAddress |
getLocalAddress()
Return the address on which the request was received.
|
java.security.Principal |
getPrincipal()
Return a
Principal instance containing the name
of the authenticated user. |
java.net.InetSocketAddress |
getRemoteAddress()
Return the address of the remote client.
|
private RemoteEndpoint |
getRemoteEndpoint() |
int |
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.
|
java.net.URI |
getUri()
Return the URI used to open the WebSocket connection.
|
private void |
initializeJettySessionDirectly(Session session) |
private void |
initializeJettySessionReflectively(Session session) |
void |
initializeNativeSession(Session session) |
boolean |
isOpen()
Return whether the connection is still 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)
Configure the maximum size for an incoming binary message.
|
void |
setTextMessageSizeLimit(int messageSizeLimit)
Configure the maximum size for an incoming text message.
|
checkNativeSessionInitialized, close, close, getAttributes, getNativeSession, getNativeSession, sendMessage, toString
private static final boolean directInterfaceCalls
private static java.lang.reflect.Method getUpgradeRequest
private static java.lang.reflect.Method getUpgradeResponse
private static java.lang.reflect.Method getRequestURI
private static java.lang.reflect.Method getHeaders
private static java.lang.reflect.Method getUserPrincipal
private static java.lang.reflect.Method getAcceptedSubProtocol
private static java.lang.reflect.Method getExtensions
private java.lang.String id
private java.net.URI uri
private HttpHeaders headers
private java.lang.String acceptedProtocol
private java.util.List<WebSocketExtension> extensions
private java.security.Principal user
public JettyWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes)
JettyWebSocketSession
instance.attributes
- attributes from the HTTP handshake to associate with the WebSocket sessionpublic JettyWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes, java.security.Principal user)
JettyWebSocketSession
instance associated with the given user.attributes
- 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; if null
we'll fallback on the
user available via org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()
public java.lang.String getId()
WebSocketSession
public java.net.URI getUri()
WebSocketSession
public HttpHeaders getHandshakeHeaders()
WebSocketSession
null
).public java.lang.String getAcceptedProtocol()
WebSocketSession
null
if no protocol
was specified or negotiated successfullypublic java.util.List<WebSocketExtension> getExtensions()
WebSocketSession
public java.security.Principal getPrincipal()
WebSocketSession
Principal
instance containing the name
of the authenticated user.
If the user has not been authenticated, the method returns null
.
public java.net.InetSocketAddress getLocalAddress()
WebSocketSession
public java.net.InetSocketAddress getRemoteAddress()
WebSocketSession
public void setTextMessageSizeLimit(int messageSizeLimit)
WebSocketSession
public int getTextMessageSizeLimit()
WebSocketSession
public void setBinaryMessageSizeLimit(int messageSizeLimit)
WebSocketSession
public int getBinaryMessageSizeLimit()
WebSocketSession
public boolean isOpen()
WebSocketSession
public void initializeNativeSession(Session session)
initializeNativeSession
in class AbstractWebSocketSession<Session>
private void initializeJettySessionDirectly(Session session)
private void initializeJettySessionReflectively(Session session)
protected void sendTextMessage(TextMessage message) throws java.io.IOException
sendTextMessage
in class AbstractWebSocketSession<Session>
java.io.IOException
protected void sendBinaryMessage(BinaryMessage message) throws java.io.IOException
sendBinaryMessage
in class AbstractWebSocketSession<Session>
java.io.IOException
protected void sendPingMessage(PingMessage message) throws java.io.IOException
sendPingMessage
in class AbstractWebSocketSession<Session>
java.io.IOException
protected void sendPongMessage(PongMessage message) throws java.io.IOException
sendPongMessage
in class AbstractWebSocketSession<Session>
java.io.IOException
private RemoteEndpoint getRemoteEndpoint() throws java.io.IOException
java.io.IOException
protected void closeInternal(CloseStatus status) throws java.io.IOException
closeInternal
in class AbstractWebSocketSession<Session>
java.io.IOException