Class WebSocketUpgradeFilter

java.lang.Object
org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter
All Implemented Interfaces:
javax.servlet.Filter, org.eclipse.jetty.util.component.Dumpable, MappedWebSocketCreator

@ManagedObject("WebSocket Upgrade Filter") public class WebSocketUpgradeFilter extends Object implements javax.servlet.Filter, MappedWebSocketCreator, org.eclipse.jetty.util.component.Dumpable

Inline Servlet Filter to capture WebSocket upgrade requests and perform path mappings to WebSocketCreator objects.

Embedded Jetty Users should initialize this filter using the configure(ServletContextHandler) method. If you also want to establish some mappings of PathSpec to WebSocketCreator against this WebSocketUpgradeFilter then these actions must occur during the Servlet Initialization Phase. A convenience method is provided with NativeWebSocketServletContainerInitializer.configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator) to create a lambda that will execute during the appropriate Servlet Initialization Phase.

     ServletContextHandler contextHandler = new ServletContextHandler(...);
     WebSocketUpgradeFilter.configure(contextHandler);
     NativeWebSocketServletContainerInitializer.configure(contextHandler, (context, container) -> {
         container.getPolicy().setMaxTextMessageBufferSize(65535);
         container.getPolicy().setInputBufferSize(16384);
         container.addMapping("/echo", ServerEchoSocket.class);
         container.addMapping(new ServletPathSpec("/api"), (req, resp) -> new ServerApiSocket());
     });