org.springframework.web.socket.server.jetty

## Class JettyRequestUpgradeStrategy

- java.lang.Object
- - org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.context.Lifecycle, org.springframework.web.context.ServletContextAware, RequestUpgradeStrategy

    public class JettyRequestUpgradeStrategy
    extends Object
    implements RequestUpgradeStrategy, org.springframework.web.context.ServletContextAware, org.springframework.context.Lifecycle

A `RequestUpgradeStrategy` for use with Jetty 9.4. Based on Jetty's internal `org.eclipse.jetty.websocket.server.WebSocketHandler` class.

Since:
  4.0
Author:
  Phillip Webb, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller

### Constructor Summary

Constructors
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`.

### Method Summary

All Methods Instance Methods Concrete Methods
`List<WebSocketExtension>` `getSupportedExtensions(org.springframework.http.server.ServerHttpRequest request)` Return the WebSocket protocol extensions supported by the underlying WebSocket server.
`String[]` `getSupportedVersions()` Return the supported WebSocket protocol versions.
`boolean` `isRunning()`
`void` `setServletContext(ServletContext servletContext)`
`void` `start()`
`void` `stop()`
`void` `upgrade(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String,Object> attributes)` Perform runtime specific steps to complete the upgrade.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JettyRequestUpgradeStrategy

    public JettyRequestUpgradeStrategy()

Default constructor that creates `WebSocketServerFactory` through its default constructor thus using a default `WebSocketPolicy`.

#### JettyRequestUpgradeStrategy

    public JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.api.WebSocketPolicy policy)

A constructor accepting a `WebSocketPolicy` to be used when creating the `WebSocketServerFactory` instance.

Parameters:
  `policy` - the policy to use
Since:
  4.3.5

#### JettyRequestUpgradeStrategy

    public JettyRequestUpgradeStrategy(org.eclipse.jetty.websocket.server.WebSocketServerFactory factory)

A constructor accepting a `WebSocketServerFactory`.

Parameters:
  `factory` - the pre-configured factory to use

### Method Detail

#### setServletContext

    public void setServletContext(ServletContext servletContext)

Specified by:
  `setServletContext` in interface `org.springframework.web.context.ServletContextAware`

#### start

    public void start()

Specified by:
  `start` in interface `org.springframework.context.Lifecycle`

#### stop

    public void stop()

Specified by:
  `stop` in interface `org.springframework.context.Lifecycle`

#### isRunning

    public boolean isRunning()

Specified by:
  `isRunning` in interface `org.springframework.context.Lifecycle`

#### getSupportedVersions

    public String[] getSupportedVersions()

Description copied from interface: `RequestUpgradeStrategy`
Return the supported WebSocket protocol versions.

Specified by:
  `getSupportedVersions` in interface `RequestUpgradeStrategy`

#### getSupportedExtensions

    public List<WebSocketExtension> getSupportedExtensions(org.springframework.http.server.ServerHttpRequest request)

Description copied from interface: `RequestUpgradeStrategy`
Return the WebSocket protocol extensions supported by the underlying WebSocket server.

Specified by:
  `getSupportedExtensions` in interface `RequestUpgradeStrategy`

#### upgrade

    public void upgrade(org.springframework.http.server.ServerHttpRequest request,
                        org.springframework.http.server.ServerHttpResponse response,
                        @Nullable
                        String selectedProtocol,
                        List<WebSocketExtension> selectedExtensions,
                        @Nullable
                        Principal user,
                        WebSocketHandler wsHandler,
                        Map<String,Object> attributes)
                 throws HandshakeFailureException

Description copied from interface: `RequestUpgradeStrategy`
Perform runtime specific steps to complete the upgrade. Invoked after successful negotiation of the handshake request.

Specified by:
  `upgrade` in interface `RequestUpgradeStrategy`
Parameters:
  `request` - the current request
  `response` - the current response
  `selectedProtocol` - the selected sub-protocol, if any
  `selectedExtensions` - the selected WebSocket protocol extensions
  `user` - the user to associate with the WebSocket session
  `wsHandler` - the handler for WebSocket messages
  `attributes` - handshake request specific attributes to be set on the WebSocket session via `HandshakeInterceptor` and thus made available to the `WebSocketHandler`
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.