Class JettyRequestUpgradeStrategy
- java.lang.Object
- org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy
- All Implemented Interfaces:
Aware,Lifecycle,ServletContextAware,RequestUpgradeStrategy
public class JettyRequestUpgradeStrategy extends Object implements RequestUpgradeStrategy, ServletContextAware, Lifecycle
ARequestUpgradeStrategyfor use with Jetty 9.1-9.4. Based on Jetty's internalorg.eclipse.jetty.websocket.server.WebSocketHandlerclass.- Since:
- 4.0
- Author:
- Phillip Webb, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
Constructor Summary
Constructors Constructor Description JettyRequestUpgradeStrategy()Default constructor that createsWebSocketServerFactorythrough its default constructor thus using a defaultWebSocketPolicy.JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.api.WebSocketPolicy policy)A constructor accepting aWebSocketPolicyto be used when creating theWebSocketServerFactoryinstance.JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.server.WebSocketServerFactory factory)A constructor accepting aWebSocketServerFactory.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<WebSocketExtension>getSupportedExtensions(ServerHttpRequest request)Return the WebSocket protocol extensions supported by the underlying WebSocket server.String[]getSupportedVersions()Return the supported WebSocket protocol versions.booleanisRunning()Check whether this component is currently running.voidsetServletContext(ServletContext servletContext)Set theServletContextthat this object runs in.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.voidupgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String,Object> attributes)Perform runtime specific steps to complete the upgrade.
Constructor Detail
JettyRequestUpgradeStrategy
public JettyRequestUpgradeStrategy()
Default constructor that createsWebSocketServerFactorythrough its default constructor thus using a defaultWebSocketPolicy.
JettyRequestUpgradeStrategy
public JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.api.WebSocketPolicy policy)
A constructor accepting aWebSocketPolicyto be used when creating theWebSocketServerFactoryinstance.- Parameters:
policy- the policy to use- Since:
- 4.3.5
JettyRequestUpgradeStrategy
public JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.server.WebSocketServerFactory factory)
A constructor accepting aWebSocketServerFactory.- Parameters:
factory- the pre-configured factory to use
Method Detail
setServletContext
public void setServletContext(ServletContext servletContext)
Description copied from interface:ServletContextAwareSet theServletContextthat this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's
afterPropertiesSetor a custom init-method. Invoked after ApplicationContextAware'ssetApplicationContext.- Specified by:
setServletContextin interfaceServletContextAware- Parameters:
servletContext- ServletContext object to be used by this object- See Also:
InitializingBean.afterPropertiesSet(),ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
start
public void start()
Description copied from interface:LifecycleStart 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.
- Specified by:
startin interfaceLifecycle- See Also:
SmartLifecycle.isAutoStartup()
stop
public void stop()
Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans 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.
- Specified by:
stopin interfaceLifecycle- See Also:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
isRunning
public boolean isRunning()
Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running.
getSupportedVersions
public String[] getSupportedVersions()
Description copied from interface:RequestUpgradeStrategyReturn the supported WebSocket protocol versions.- Specified by:
getSupportedVersionsin interfaceRequestUpgradeStrategy
getSupportedExtensions
public List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request)
Description copied from interface:RequestUpgradeStrategyReturn the WebSocket protocol extensions supported by the underlying WebSocket server.- Specified by:
getSupportedExtensionsin interfaceRequestUpgradeStrategy
upgrade
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String,Object> attributes) throws HandshakeFailureException
Description copied from interface:RequestUpgradeStrategyPerform runtime specific steps to complete the upgrade. Invoked after successful negotiation of the handshake request.- Specified by:
upgradein interfaceRequestUpgradeStrategy- Parameters:
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 viaHandshakeInterceptorand thus made available to theWebSocketHandler- Throws:
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.