类 AbstractHttpSockJsSession
- java.lang.Object
- org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
- org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession
- 所有已实现的接口:
Closeable
,AutoCloseable
,SockJsSession
,WebSocketSession
public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession
An abstract base class for use with HTTP transport SockJS sessions.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
DISCONNECTED_CLIENT_LOG_CATEGORY, disconnectedClientLogger, logger, responseLock
构造器概要
构造器 构造器 说明 AbstractHttpSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler wsHandler, Map<String,Object> attributes)
方法概要
所有方法 实例方法 抽象方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected void
disconnect(CloseStatus status)
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.protected abstract void
flushCache()
Called when the connection is active and ready to write to the response.String
getAcceptedProtocol()
Return the selected sub-protocol to use.int
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.List<WebSocketExtension>
getExtensions()
Determine the negotiated extensions.HttpHeaders
getHandshakeHeaders()
Return the headers used in the handshake request (nevernull
).InetSocketAddress
getLocalAddress()
Return the address on which the request was received.protected Queue<String>
getMessageCache()
Return the SockJS buffer for messages stored transparently between polling requests.Principal
getPrincipal()
Return aPrincipal
instance containing the name of the authenticated user.InetSocketAddress
getRemoteAddress()
Return the address of the remote client.int
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.URI
getUri()
Return the URI used to open the WebSocket connection.void
handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat)
Handle the first request for receiving messages on a SockJS HTTP transport based session.protected abstract void
handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, boolean initialRequest)
Invoked when a SockJS transport request is received.void
handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat)
Handle all requests, except the first one, to receive messages on a SockJS HTTP transport based session.boolean
isActive()
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.protected abstract boolean
isStreaming()
已过时。as of 4.2, since this method is no longer used.protected void
resetRequest()
protected void
sendMessageInternal(String message)
void
setAcceptedProtocol(String protocol)
Unlike WebSocket where sub-protocol negotiation is part of the initial handshake, in HTTP transports the same negotiation must be emulated and the selected protocol set through this setter.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.protected void
writeFrameInternal(SockJsFrame frame)
protected void
writePrelude(ServerHttpRequest request, ServerHttpResponse response)
已过时。as of 4.2 this method is deprecated since the prelude is written inhandleRequestInternal(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, boolean)
of the StreamingSockJsSession subclass.从类继承的方法 org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
cancelHeartbeat, close, close, delegateConnectionClosed, delegateConnectionEstablished, delegateError, delegateMessages, disableHeartbeat, getAttributes, getId, getMessageCodec, getSockJsServiceConfig, getTimeSinceLastActive, isClosed, isNew, isOpen, scheduleHeartbeat, sendHeartbeat, sendMessage, toString, tryCloseWithSockJsTransportError, updateLastActiveTime, writeFrame
构造器详细资料
AbstractHttpSockJsSession
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler wsHandler, Map<String,Object> attributes)
方法详细资料
getUri
public URI getUri()
从接口复制的说明:WebSocketSession
Return the URI used to open the WebSocket connection.
getHandshakeHeaders
public HttpHeaders getHandshakeHeaders()
从接口复制的说明:WebSocketSession
Return the headers used in the handshake request (nevernull
).
getPrincipal
public Principal getPrincipal()
从接口复制的说明:WebSocketSession
Return aPrincipal
instance containing the name of the authenticated user.If the user has not been authenticated, the method returns
null
.
getLocalAddress
public InetSocketAddress getLocalAddress()
从接口复制的说明:WebSocketSession
Return the address on which the request was received.
getRemoteAddress
public InetSocketAddress getRemoteAddress()
从接口复制的说明:WebSocketSession
Return the address of the remote client.
setAcceptedProtocol
public void setAcceptedProtocol(String protocol)
Unlike WebSocket where sub-protocol negotiation is part of the initial handshake, in HTTP transports the same negotiation must be emulated and the selected protocol set through this setter.- 参数:
protocol
- the sub-protocol to set
getAcceptedProtocol
public String getAcceptedProtocol()
Return the selected sub-protocol to use.- 返回:
- the protocol identifier, or
null
if no protocol was specified or negotiated successfully
getMessageCache
protected Queue<String> getMessageCache()
Return the SockJS buffer for messages stored transparently between polling requests. If the polling request takes longer than 5 seconds, the session is closed.
isActive
public boolean isActive()
从类复制的说明:AbstractSockJsSession
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through. During this "downtime" the session is still open but inactive and unable to send messages and therefore has to buffer them temporarily. A WebSocket session by contrast is stateful and remain active until closed.- 指定者:
isActive
在类中AbstractSockJsSession
setTextMessageSizeLimit
public void setTextMessageSizeLimit(int messageSizeLimit)
从接口复制的说明:WebSocketSession
Configure the maximum size for an incoming text message.
getTextMessageSizeLimit
public int getTextMessageSizeLimit()
从接口复制的说明:WebSocketSession
Get the configured maximum size for an incoming text message.
setBinaryMessageSizeLimit
public void setBinaryMessageSizeLimit(int messageSizeLimit)
从接口复制的说明:WebSocketSession
Configure the maximum size for an incoming binary message.
getBinaryMessageSizeLimit
public int getBinaryMessageSizeLimit()
从接口复制的说明:WebSocketSession
Get the configured maximum size for an incoming binary message.
getExtensions
public List<WebSocketExtension> getExtensions()
从接口复制的说明:WebSocketSession
Determine the negotiated extensions.- 返回:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
isStreaming
@Deprecated protected abstract boolean isStreaming()
已过时。as of 4.2, since this method is no longer used.
handleInitialRequest
public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
Handle the first request for receiving messages on a SockJS HTTP transport based session.Long polling-based transports (e.g. "xhr", "jsonp") complete the request after writing the open frame. Streaming-based transports ("xhr_streaming", "eventsource", and "htmlfile") leave the response open longer for further streaming of message frames but will also close it eventually after some amount of data has been sent.
- 参数:
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to use- 抛出:
SockJsException
handleSuccessiveRequest
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
Handle all requests, except the first one, to receive messages on a SockJS HTTP transport based session.Long polling-based transports (e.g. "xhr", "jsonp") complete the request after writing any buffered message frames (or the next one). Streaming-based transports ("xhr_streaming", "eventsource", and "htmlfile") leave the response open longer for further streaming of message frames but will also close it eventually after some amount of data has been sent.
- 参数:
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to use- 抛出:
SockJsException
handleRequestInternal
protected abstract void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, boolean initialRequest) throws IOException
Invoked when a SockJS transport request is received.- 参数:
request
- the current requestresponse
- the current responseinitialRequest
- whether it is the first request for the session- 抛出:
IOException
sendMessageInternal
protected final void sendMessageInternal(String message) throws SockJsTransportFailureException
flushCache
protected abstract void flushCache() throws SockJsTransportFailureException
Called when the connection is active and ready to write to the response. Subclasses should only call this method from a method where the "responseLock" is acquired.
writePrelude
@Deprecated protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException
已过时。as of 4.2 this method is deprecated since the prelude is written inhandleRequestInternal(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, boolean)
of the StreamingSockJsSession subclass.- 抛出:
IOException
disconnect
protected void disconnect(CloseStatus status)
从类复制的说明:AbstractSockJsSession
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.- 指定者:
disconnect
在类中AbstractSockJsSession
resetRequest
protected void resetRequest()
writeFrameInternal
protected void writeFrameInternal(SockJsFrame frame) throws IOException