diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java index e34d3407edd..4f5a51439b6 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketServer.java @@ -24,10 +24,8 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketMapping; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; /** * Example of setting up a Jetty WebSocket server @@ -53,10 +51,10 @@ public class WebSocketServer * Servlet layer */ @SuppressWarnings("serial") - public static class EchoServlet extends WebSocketServlet + public static class EchoServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.addMapping(factory.parsePathSpec("/"), (req,res)->new EchoSocket()); } diff --git a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java index 04698f54526..23eb305153b 100644 --- a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java +++ b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.javax.tests; import java.net.URI; import java.util.Map; import java.util.function.BiConsumer; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.websocket.OnMessage; @@ -48,7 +49,10 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.websocket.core.internal.Parser; +import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer; +import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerFrameHandlerFactory; import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; @@ -256,12 +260,20 @@ public class LocalServer extends ContainerLifeCycle implements LocalFuzzer.Provi { ServletHolder holder = new ServletHolder(new WebSocketServlet() { + JavaxWebSocketServerFrameHandlerFactory factory = new JavaxWebSocketServerFrameHandlerFactory(JavaxWebSocketServerContainer.ensureContainer(getServletContext())); + @Override public void configure(WebSocketServletFactory factory) { PathSpec pathSpec = factory.parsePathSpec("/"); factory.addMapping(pathSpec, creator); } + + @Override + public FrameHandlerFactory getFactory() + { + return factory; + } }); servletContextHandler.addServlet(holder, urlPattern); } diff --git a/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerFrameHandlerFactory.java b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerFrameHandlerFactory.java index 2b9050215e2..a348cffd212 100644 --- a/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerFrameHandlerFactory.java +++ b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyServerFrameHandlerFactory.java @@ -38,6 +38,12 @@ public class JettyServerFrameHandlerFactory extends JettyWebSocketFrameHandlerFactory implements FrameHandlerFactory, LifeCycle.Listener { + public static JettyServerFrameHandlerFactory getFactory(ServletContext context) + { + ServletContextHandler contextHandler = ServletContextHandler.getServletContextHandler(context, "JettyServerFrameHandlerFactory"); + return contextHandler.getBean(JettyServerFrameHandlerFactory.class); + } + public JettyServerFrameHandlerFactory(WebSocketContainer container) { super(container); diff --git a/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java new file mode 100644 index 00000000000..43a50b510ee --- /dev/null +++ b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServlet.java @@ -0,0 +1,27 @@ +package org.eclipse.jetty.websocket.server; + +import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; +import org.eclipse.jetty.websocket.servlet.WebSocketServlet; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; + +public abstract class JettyWebSocketServlet extends WebSocketServlet +{ + protected abstract void configure(JettyWebSocketServletFactory factory); + + @Override + protected final void configure(WebSocketServletFactory factory) + { + configure(new JettyWebSocketServletFactory(factory)); + } + + @Override + public FrameHandlerFactory getFactory() + { + JettyServerFrameHandlerFactory frameHandlerFactory = JettyServerFrameHandlerFactory.getFactory(getServletContext()); + + if (frameHandlerFactory==null) + throw new IllegalStateException("JettyServerFrameHandlerFactory not found"); + + return frameHandlerFactory; + } +} diff --git a/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServletFactory.java b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServletFactory.java new file mode 100644 index 00000000000..4a908f8aa7c --- /dev/null +++ b/jetty-websocket/jetty-websocket-server/src/main/java/org/eclipse/jetty/websocket/server/JettyWebSocketServletFactory.java @@ -0,0 +1,224 @@ +package org.eclipse.jetty.websocket.server; + +import java.time.Duration; +import java.util.Set; + +import org.eclipse.jetty.http.pathmap.PathSpec; +import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; +import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; +import org.eclipse.jetty.websocket.servlet.WebSocketCreator; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; + + +public class JettyWebSocketServletFactory +{ + private WebSocketServletFactory factory; + + public JettyWebSocketServletFactory(WebSocketServletFactory factory) + { + this.factory = factory; + } + + public Set getAvailableExtensionNames() + { + return factory.getExtensionRegistry().getAvailableExtensionNames(); + } + + public Duration getIdleTimeout() + { + return factory.getIdleTimeout(); + } + + public void setIdleTimeout(Duration duration) + { + factory.setIdleTimeout(duration); + } + + public int getInputBufferSize() + { + return factory.getInputBufferSize(); + } + + public void setInputBufferSize(int bufferSize) + { + factory.setInputBufferSize(bufferSize); + } + + public long getMaxFrameSize() + { + return factory.getMaxFrameSize(); + } + + public void setMaxFrameSize(long maxFrameSize) + { + factory.setMaxFrameSize(maxFrameSize); + } + + public long getMaxBinaryMessageSize() + { + return factory.getMaxFrameSize(); + } + + public void setMaxBinaryMessageSize(long bufferSize) + { + factory.setMaxBinaryMessageSize(bufferSize); + } + + public long getMaxTextMessageSize() + { + return factory.getMaxTextMessageSize(); + } + + public void setMaxTextMessageSize(long bufferSize) + { + factory.setMaxBinaryMessageSize(bufferSize); + } + + public int getOutputBufferSize() + { + return factory.getOutputBufferSize(); + } + + public void setOutputBufferSize(int bufferSize) + { + factory.setOutputBufferSize(bufferSize); + } + + public boolean isAutoFragment() + { + return factory.isAutoFragment(); + } + + public void setAutoFragment(boolean autoFragment) + { + factory.setAutoFragment(autoFragment); + } + + public void addMapping(String pathSpec, JettyWebSocketCreator creator) + { + factory.addMapping(pathSpec, new WrappedCreator(creator)); + } + + /** + * add a WebSocket mapping to a provided {@link JettyWebSocketCreator}. + *

+ * If mapping is added before this configuration is started, then it is persisted through + * stop/start of this configuration's lifecycle. Otherwise it will be removed when + * this configuration is stopped. + *

+ * + * @param pathSpec the pathspec to respond on + * @param creator the WebSocketCreator to use + * @since 10.0 + */ + public void addMapping(PathSpec pathSpec, JettyWebSocketCreator creator) + { + factory.addMapping(pathSpec, new WrappedCreator(creator)); + } + + /** + * Add a WebSocket mapping at PathSpec "/" for a creator which creates the endpointClass + * + * @param endpointClass the WebSocket class to use + */ + public void register(Class endpointClass) + { + factory.register(endpointClass); + } + + /** + * Add a WebSocket mapping at PathSpec "/" for a creator + * + * @param creator the WebSocketCreator to use + */ + public void setCreator(JettyWebSocketCreator creator) + { + factory.setCreator(new WrappedCreator(creator)); + } + + /** + * Returns the creator for the given path spec. + * + * @param pathSpec the pathspec to respond on + * @return the websocket creator if path spec exists, or null + */ + public JettyWebSocketCreator getMapping(PathSpec pathSpec) + { + WebSocketCreator creator = factory.getMapping(pathSpec); + if (creator instanceof WrappedCreator) + return ((WrappedCreator)creator).getCreator(); + + return null; + } + + /** + * Get the MappedResource for the given target path. + * + * @param target the target path + * @return the MappedResource if matched, or null if not matched. + */ + public JettyWebSocketCreator getMatch(String target) + { + WebSocketCreator creator = factory.getMatch(target); + if (creator instanceof WrappedCreator) + return ((WrappedCreator)creator).getCreator(); + + return null; + } + + + /** + * Parse a PathSpec string into a PathSpec instance. + *

+ * Recognized Path Spec syntaxes: + *

+ *
+ *
/path/to or / or *.ext or servlet|{spec}
+ *
Servlet Syntax
+ *
^{spec} or regex|{spec}
+ *
Regex Syntax
+ *
uri-template|{spec}
+ *
URI Template (see JSR356 and RFC6570 level 1)
+ *
+ * + * @param rawSpec the raw path spec as String to parse. + * @return the {@link PathSpec} implementation for the rawSpec + */ + public PathSpec parsePathSpec(String rawSpec) + { + return factory.parsePathSpec(rawSpec); + } + + /** + * Removes the mapping based on the given path spec. + * + * @param pathSpec the pathspec to respond on + * @return true if underlying mapping were altered, false otherwise + */ + public boolean removeMapping(PathSpec pathSpec) + { + return factory.removeMapping(pathSpec); + } + + + private static class WrappedCreator implements WebSocketCreator + { + private JettyWebSocketCreator creator; + + private WrappedCreator(JettyWebSocketCreator creator) + { + this.creator = creator; + } + + public JettyWebSocketCreator getCreator() + { + return creator; + } + + @Override + public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + { + return creator.createWebSocket(new JettyServerUpgradeRequest(req), new JettyServerUpgradeResponse(resp)); + } + } +} diff --git a/jetty-websocket/jetty-websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java b/jetty-websocket/jetty-websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java index 4c4c209dbe4..4b25fadf684 100644 --- a/jetty-websocket/jetty-websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java +++ b/jetty-websocket/jetty-websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java @@ -42,13 +42,13 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.websocket.core.ExtensionConfig; +import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; /** * Tool to help debug websocket circumstances reported around browsers. @@ -137,10 +137,10 @@ public class BrowserDebugTool server.stop(); } - public static class BrowserSocketServlet extends WebSocketServlet + public static class BrowserSocketServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) { + public void configure(JettyWebSocketServletFactory factory) { LOG.debug("Configuring WebSocketServerFactory ..."); // Setup the desired Socket to use for all incoming upgrade requests @@ -160,10 +160,10 @@ public class BrowserDebugTool } } - public static class BrowserSocketCreator implements WebSocketCreator + public static class BrowserSocketCreator implements JettyWebSocketCreator { @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { LOG.debug("Creating BrowserSocket"); @@ -182,7 +182,7 @@ public class BrowserDebugTool // manually negotiate extensions List negotiated = new ArrayList<>(); // adding frame debug - negotiated.add(new ExtensionConfig("@frame-capture; output-dir=target")); + negotiated.add(ExtensionConfig.parse("@frame-capture; output-dir=target")); for (ExtensionConfig config : req.getExtensions()) { if (config.getName().equals("permessage-deflate")) diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoCreator.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoCreator.java index c9cc46b144a..61be8ec2617 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoCreator.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoCreator.java @@ -18,14 +18,14 @@ package org.eclipse.jetty.websocket.tests; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; -public class EchoCreator implements WebSocketCreator +public class EchoCreator implements JettyWebSocketCreator { @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { if (req.hasSubProtocol("echo")) { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java index 830f8041094..041c2c4a896 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java @@ -27,9 +27,9 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,10 +40,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class JettyWebSocketServletTest { - public static class MyWebSocketServlet extends WebSocketServlet + public static class MyWebSocketServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.addMapping("/",(req, resp)->new EventSocket.EchoSocket()); } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java index 555472bcdc1..795120cbd29 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStatsTest.java @@ -45,9 +45,9 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.internal.Generator; import org.eclipse.jetty.websocket.core.internal.WebSocketConnection; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -103,10 +103,10 @@ public class WebSocketStatsTest } } - public static class MyWebSocketServlet extends WebSocketServlet + public static class MyWebSocketServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setAutoFragment(false); factory.addMapping("/",(req, resp)->new EchoSocket()); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java index 0f69e01848a..12ee07f919e 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java @@ -37,9 +37,9 @@ import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WebSocketListener; import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -75,10 +75,10 @@ public class BadNetworkTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder holder = new ServletHolder(new WebSocketServlet() + ServletHolder holder = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setIdleTimeout(Duration.ofSeconds(10)); factory.setMaxTextMessageSize(1024 * 1024 * 2); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java index 37296c29015..b0e43f7d5c1 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java @@ -38,7 +38,6 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.api.CloseException; import org.eclipse.jetty.websocket.api.Frame; import org.eclipse.jetty.websocket.api.MessageTooLargeException; import org.eclipse.jetty.websocket.api.Session; @@ -50,9 +49,9 @@ import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.OpCode; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -121,10 +120,10 @@ public class ClientCloseTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder holder = new ServletHolder(new WebSocketServlet() + ServletHolder holder = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setIdleTimeout(Duration.ofSeconds(10)); factory.setMaxTextMessageSize(1024 * 1024 * 2); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java index 93b844f478c..7054af27dfd 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java @@ -39,9 +39,9 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.WebSocketSessionListener; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.eclipse.jetty.websocket.tests.EchoCreator; import org.junit.jupiter.api.AfterEach; @@ -69,10 +69,10 @@ public class ClientSessionsTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder holder = new ServletHolder(new WebSocketServlet() + ServletHolder holder = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setIdleTimeout(Duration.ofSeconds(10)); factory.setMaxTextMessageSize(1024 * 1024 * 2); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java index c0c6cef0d3c..d373e1c13cb 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java @@ -32,9 +32,9 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.eclipse.jetty.websocket.tests.EchoSocket; import org.junit.jupiter.api.AfterEach; @@ -72,10 +72,10 @@ public class SlowClientTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder websocket = new ServletHolder(new WebSocketServlet() + ServletHolder websocket = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.register(EchoSocket.class); } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoCreator.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoCreator.java index 00b43224cd9..6e87475cddb 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoCreator.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoCreator.java @@ -18,11 +18,11 @@ package org.eclipse.jetty.websocket.tests.examples; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; -public class MyAdvancedEchoCreator implements WebSocketCreator +public class MyAdvancedEchoCreator implements JettyWebSocketCreator { private MyBinaryEchoSocket binaryEcho; private MyEchoSocket textEcho; @@ -35,7 +35,7 @@ public class MyAdvancedEchoCreator implements WebSocketCreator } @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { for (String subprotocol : req.getSubProtocols()) { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoServlet.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoServlet.java index d0dcb0a9c23..a0f7fb723ff 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoServlet.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAdvancedEchoServlet.java @@ -22,15 +22,15 @@ import java.time.Duration; import javax.servlet.annotation.WebServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; @SuppressWarnings("serial") @WebServlet(name = "MyAdvanced Echo WebSocket Servlet", urlPatterns = { "/advecho" }) -public class MyAdvancedEchoServlet extends WebSocketServlet +public class MyAdvancedEchoServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { // set a 10 second timeout factory.setIdleTimeout(Duration.ofSeconds(10)); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedCreator.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedCreator.java index 424dc83d7bc..c5f15c69a60 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedCreator.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedCreator.java @@ -21,14 +21,14 @@ package org.eclipse.jetty.websocket.tests.examples; import java.io.IOException; import java.security.Principal; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; -public class MyAuthedCreator implements WebSocketCreator +public class MyAuthedCreator implements JettyWebSocketCreator { @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { try { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedServlet.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedServlet.java index e1b8511e8e9..bd3304d8446 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedServlet.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyAuthedServlet.java @@ -18,14 +18,14 @@ package org.eclipse.jetty.websocket.tests.examples; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; @SuppressWarnings("serial") -public class MyAuthedServlet extends WebSocketServlet +public class MyAuthedServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setCreator(new MyAuthedCreator()); } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyEchoServlet.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyEchoServlet.java index 4bbd1e7044d..f403968d149 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyEchoServlet.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/examples/MyEchoServlet.java @@ -22,15 +22,15 @@ import java.time.Duration; import javax.servlet.annotation.WebServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; @SuppressWarnings("serial") @WebServlet(name = "MyEcho WebSocket Servlet", urlPatterns = { "/echo" }) -public class MyEchoServlet extends WebSocketServlet +public class MyEchoServlet extends JettyWebSocketServlet { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { // set a 10 second timeout factory.setIdleTimeout(Duration.ofSeconds(10)); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java index fd507d2a5fa..6f89b87402b 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseCreator.java @@ -19,29 +19,30 @@ package org.eclipse.jetty.websocket.tests.server; import java.util.concurrent.LinkedBlockingQueue; + import javax.servlet.ServletContext; import org.eclipse.jetty.websocket.common.WebSocketContainer; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.EchoSocket; import static java.util.concurrent.TimeUnit.SECONDS; -public class ServerCloseCreator implements WebSocketCreator +public class ServerCloseCreator implements JettyWebSocketCreator { - private final WebSocketServletFactory serverFactory; + private final JettyWebSocketServletFactory serverFactory; private LinkedBlockingQueue createdSocketQueue = new LinkedBlockingQueue<>(); - public ServerCloseCreator(WebSocketServletFactory serverFactory) + public ServerCloseCreator(JettyWebSocketServletFactory serverFactory) { this.serverFactory = serverFactory; } @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { AbstractCloseEndpoint closeSocket = null; diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java index 161ee51248f..78930118a0e 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java @@ -37,9 +37,9 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.core.internal.WebSocketChannel; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -73,10 +73,10 @@ public class ServerCloseTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder closeEndpoint = new ServletHolder(new WebSocketServlet() + ServletHolder closeEndpoint = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.setIdleTimeout(Duration.ofSeconds(2)); serverEndpointCreator = new ServerCloseCreator(factory); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java index 722b7913d57..20508c90a18 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java @@ -32,9 +32,9 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -72,10 +72,10 @@ public class SlowServerTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - ServletHolder websocket = new ServletHolder(new WebSocketServlet() + ServletHolder websocket = new ServletHolder(new JettyWebSocketServlet() { @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.register(SlowServerEndpoint.class); } diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java index 3e63669737a..06e85d1246b 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -90,8 +89,6 @@ import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry; @SuppressWarnings("serial") public abstract class WebSocketServlet extends HttpServlet { - // TODO This servlet should be split into an API neutral version and a Jetty API specific one. - private static final Logger LOG = Log.getLogger(WebSocketServlet.class); private final CustomizedWebSocketServletFactory customizer = new CustomizedWebSocketServletFactory(); @@ -105,7 +102,12 @@ public abstract class WebSocketServlet extends HttpServlet * {@link ContextHandler}, which in practise will mostly the the Jetty WebSocket API factory. * @param factory the WebSocketServletFactory */ - public abstract void configure(WebSocketServletFactory factory); + protected abstract void configure(WebSocketServletFactory factory); + + /** + * @return the instance of {@link FrameHandlerFactory} to be used to create the FrameHandler + */ + public abstract FrameHandlerFactory getFactory(); @Override public void init() throws ServletException @@ -175,6 +177,7 @@ public abstract class WebSocketServlet extends HttpServlet private class CustomizedWebSocketServletFactory extends FrameHandler.ConfigurationCustomizer implements WebSocketServletFactory { + @Override public WebSocketExtensionRegistry getExtensionRegistry() { return components.getExtensionRegistry(); @@ -189,16 +192,7 @@ public abstract class WebSocketServlet extends HttpServlet @Override public void addMapping(PathSpec pathSpec, WebSocketCreator creator) { - ServletContext servletContext = getServletContext(); - ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "WebSocketServlet"); - - // TODO: a bit fragile, this code knows that only the JettyFHF is added as a bean - FrameHandlerFactory frameHandlerFactory = contextHandler.getBean(FrameHandlerFactory.class); - - if (frameHandlerFactory==null) - throw new IllegalStateException("No known FrameHandlerFactory"); - - mapping.addMapping(pathSpec, creator, frameHandlerFactory, this); + mapping.addMapping(pathSpec, creator, getFactory(), this); } @Override diff --git a/tests/test-webapps/test-jetty-webapp/pom.xml b/tests/test-webapps/test-jetty-webapp/pom.xml index 27b738317df..883f39d2821 100644 --- a/tests/test-webapps/test-jetty-webapp/pom.xml +++ b/tests/test-webapps/test-jetty-webapp/pom.xml @@ -207,7 +207,7 @@ org.eclipse.jetty.websocket - websocket-servlet + jetty-websocket-server ${project.version} provided @@ -217,12 +217,6 @@ ${project.version} test - - org.eclipse.jetty.websocket - jetty-websocket-server - ${project.version} - test - diff --git a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java index b2074c3f918..7bf79fac398 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java +++ b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.List; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -32,16 +33,14 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; -import org.eclipse.jetty.websocket.servlet.WebSocketMapping; -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest; +import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse; +import org.eclipse.jetty.websocket.server.JettyWebSocketCreator; +import org.eclipse.jetty.websocket.server.JettyWebSocketServlet; +import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory; @SuppressWarnings("serial") -public class WebSocketChatServlet extends WebSocketServlet implements WebSocketCreator +public class WebSocketChatServlet extends JettyWebSocketServlet implements JettyWebSocketCreator { /** Holds active sockets to other members of the chat */ private final List members = new CopyOnWriteArrayList(); @@ -53,7 +52,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC } @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + public Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) { if (req.hasSubProtocol("chat")) { @@ -64,7 +63,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC } @Override - public void configure(WebSocketServletFactory factory) + public void configure(JettyWebSocketServletFactory factory) { factory.addMapping(factory.parsePathSpec("/"), this); }