public class JettyRequestUpgradeStrategy extends java.lang.Object implements RequestUpgradeStrategy, ServletContextAware, Lifecycle
RequestUpgradeStrategy
for use with Jetty 9.4. Based on Jetty's
internal org.eclipse.jetty.websocket.server.WebSocketHandler
class.Constructor and Description |
---|
JettyRequestUpgradeStrategy()
Default constructor that creates
WebSocketServerFactory through
its default constructor thus using a default WebSocketPolicy . |
JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.api.WebSocketPolicy policy)
A constructor accepting a
WebSocketPolicy to be used when
creating the WebSocketServerFactory instance. |
JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.server.WebSocketServerFactory factory)
A constructor accepting a
WebSocketServerFactory . |
Modifier and Type | Method and Description |
---|---|
java.util.List<WebSocketExtension> |
getSupportedExtensions(ServerHttpRequest request)
Return the WebSocket protocol extensions supported by the underlying WebSocket server.
|
java.lang.String[] |
getSupportedVersions()
Return the supported WebSocket protocol versions.
|
boolean |
isRunning()
Check whether this component is currently running.
|
void |
setServletContext(ServletContext servletContext)
Set the
ServletContext 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.
|
void |
upgrade(ServerHttpRequest request,
ServerHttpResponse response,
java.lang.String selectedProtocol,
java.util.List<WebSocketExtension> selectedExtensions,
java.security.Principal user,
WebSocketHandler wsHandler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Perform runtime specific steps to complete the upgrade.
|
public JettyRequestUpgradeStrategy()
WebSocketServerFactory
through
its default constructor thus using a default WebSocketPolicy
.public JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.api.WebSocketPolicy policy)
WebSocketPolicy
to be used when
creating the WebSocketServerFactory
instance.policy
- the policy to usepublic JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.server.WebSocketServerFactory factory)
WebSocketServerFactory
.factory
- the pre-configured factory to usepublic void setServletContext(ServletContext servletContext)
ServletContextAware
ServletContext
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's
setApplicationContext
.
setServletContext
in interface ServletContextAware
servletContext
- the ServletContext object to be used by this objectInitializingBean.afterPropertiesSet()
,
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
public void start()
Lifecycle
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
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
SmartLifecycle
and its stop(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
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
public java.lang.String[] getSupportedVersions()
RequestUpgradeStrategy
getSupportedVersions
in interface RequestUpgradeStrategy
public java.util.List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request)
RequestUpgradeStrategy
getSupportedExtensions
in interface RequestUpgradeStrategy
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, java.lang.String selectedProtocol, java.util.List<WebSocketExtension> selectedExtensions, java.security.Principal user, WebSocketHandler wsHandler, java.util.Map<java.lang.String,java.lang.Object> attributes) throws HandshakeFailureException
RequestUpgradeStrategy
upgrade
in interface RequestUpgradeStrategy
request
- the current requestresponse
- the current responseselectedProtocol
- the selected sub-protocol, if anyselectedExtensions
- the selected WebSocket protocol extensionsuser
- the user to associate with the WebSocket sessionwsHandler
- the handler for WebSocket messagesattributes
- handshake request specific attributes to be set on the WebSocket
session via HandshakeInterceptor
and
thus made available to the WebSocketHandler
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 requirements of the
handshake request.