类 WebSocketTransportHandler
- java.lang.Object
- org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler
- org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler
- 所有已实现的接口:
Aware
,Lifecycle
,ServletContextAware
,HandshakeHandler
,SockJsSessionFactory
,TransportHandler
public class WebSocketTransportHandler extends AbstractTransportHandler implements SockJsSessionFactory, HandshakeHandler, Lifecycle, ServletContextAware
WebSocket-basedTransportHandler
. UsesSockJsWebSocketHandler
andWebSocketServerSockJsSession
to add SockJS processing.Also implements
HandshakeHandler
to support raw WebSocket communication at SockJS URL "/websocket".- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler
logger, UTF8_CHARSET
构造器概要
构造器 构造器 说明 WebSocketTransportHandler(HandshakeHandler handshakeHandler)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
checkSessionType(SockJsSession session)
Check whether the type of the given session matches the transport type of thisTransportHandler
where session id and the transport type are extracted from the SockJS URL.AbstractSockJsSession
createSession(String id, WebSocketHandler handler, Map<String,Object> attrs)
Create a new SockJS session.boolean
doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, Map<String,Object> attributes)
Initiate the handshake.HandshakeHandler
getHandshakeHandler()
TransportType
getTransportType()
Return the transport type supported by this handler.void
handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession)
Handle the given request and delegate messages to the providedWebSocketHandler
.boolean
isRunning()
Check whether this component is currently running.void
setServletContext(ServletContext servletContext)
Set theServletContext
that this object runs in.void
start()
Start this component.void
stop()
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.从类继承的方法 org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler
getServiceConfig, initialize
构造器详细资料
WebSocketTransportHandler
public WebSocketTransportHandler(HandshakeHandler handshakeHandler)
方法详细资料
getTransportType
public TransportType getTransportType()
从接口复制的说明:TransportHandler
Return the transport type supported by this handler.- 指定者:
getTransportType
在接口中TransportHandler
getHandshakeHandler
public HandshakeHandler getHandshakeHandler()
setServletContext
public void setServletContext(ServletContext servletContext)
从接口复制的说明:ServletContextAware
Set theServletContext
that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's
afterPropertiesSet
or a custom init-method. Invoked after ApplicationContextAware'ssetApplicationContext
.- 指定者:
setServletContext
在接口中ServletContextAware
- 参数:
servletContext
- ServletContext object to be used by this object- 另请参阅:
InitializingBean.afterPropertiesSet()
,ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
start
public void start()
从接口复制的说明:Lifecycle
Start this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate the start signal to all components that apply.
- 指定者:
start
在接口中Lifecycle
- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public void stop()
从接口复制的说明:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(Runnable)
variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecycle
beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
- 指定者:
stop
在接口中Lifecycle
- 另请参阅:
SmartLifecycle.stop(Runnable)
,DisposableBean.destroy()
isRunning
public boolean isRunning()
从接口复制的说明:Lifecycle
Check whether this component is currently running.In the case of a container, this will return
true
only if all components that apply are currently running.
checkSessionType
public boolean checkSessionType(SockJsSession session)
从接口复制的说明:TransportHandler
Check whether the type of the given session matches the transport type of thisTransportHandler
where session id and the transport type are extracted from the SockJS URL.- 指定者:
checkSessionType
在接口中TransportHandler
- 返回:
true
if the session matches (and would therefore get accepted byTransportHandler.handleRequest(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, org.springframework.web.socket.WebSocketHandler, org.springframework.web.socket.sockjs.transport.SockJsSession)
), orfalse
otherwise
createSession
public AbstractSockJsSession createSession(String id, WebSocketHandler handler, Map<String,Object> attrs)
从接口复制的说明:SockJsSessionFactory
Create a new SockJS session.- 指定者:
createSession
在接口中SockJsSessionFactory
- 参数:
id
- the ID of the sessionhandler
- the underlyingWebSocketHandler
attrs
- handshake request specific attributes- 返回:
- a new session, never
null
handleRequest
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException
从接口复制的说明:TransportHandler
Handle the given request and delegate messages to the providedWebSocketHandler
.- 指定者:
handleRequest
在接口中TransportHandler
- 参数:
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocketHandler (nevernull
)wsSession
- the SockJS session (nevernull
)- 抛出:
SockJsException
- raised when request processing fails as explained inSockJsService
doHandshake
public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, Map<String,Object> attributes) throws HandshakeFailureException
从接口复制的说明:HandshakeHandler
Initiate the handshake.- 指定者:
doHandshake
在接口中HandshakeHandler
- 参数:
request
- the current requestresponse
- the current responsehandler
- the handler to process WebSocket messages; seePerConnectionWebSocketHandler
for providing a handler with per-connection lifecycle.attributes
- attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.- 返回:
- whether the handshake negotiation was successful or not. In either case the response status, headers, and body will have been updated to reflect the result of the negotiation
- 抛出:
HandshakeFailureException
- thrown when handshake processing failed to complete due to an internal, unrecoverable error, i.e. a server error as opposed to a failure to successfully negotiate the handshake.