From 8f383faf7866a6b417ff3241d69f8100f219b0b8 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 28 Aug 2019 10:03:46 +1000 Subject: [PATCH] Issue #3872 Javax Websocket Packaging (#3873) * Issue #3872 Javax Websocket Packaging Moved JaxaxWebSocketConfiguration and SCI to config package. Limited classpath exposure in JavaxConfiguration (more needed) Updated tests with work around for those that needs more classes exposed Signed-off-by: Greg Wilkins * Issue #3872 Javax Websocket Packaging Moved all remaining classes from org.eclipse.jetty.websocket.javax.server to org.eclipse.jetty.websocket.javax.server.internal. This works when running on the classpath, but the tests fail when running on the modulepath (eg in commandline mvn run). The issue appears to be that the tests don't load test classes from WEB-INF/lib or WEB-INF/classes. Instead the test classes were themselves in org.eclipse.jetty.websocket.javax.server, which is no longer exported from module-info.java. The hacked "fix" for this has been to create a org.eclipse.jetty.websocket.javax.server.tests package which is exported and to move all the tests to that. A better fix is needed. Signed-off-by: Greg Wilkins * Issue #3872 Javax Websocket Packaging improve comments tighten exposed classes more Signed-off-by: Greg Wilkins * Issue #3872 - fixing tests Signed-off-by: Lachlan Roberts * Issue #3872 - move ContainerDefaultConfigurator to config package Signed-off-by: Lachlan Roberts * Issue #3873 - fix javax websocket test classloader issues move websocket endpoints for test webapps to com.acme.websocket package Signed-off-by: Lachlan Roberts --- .../jetty/embedded/WebSocketJsrServer.java | 2 +- .../jetty-osgi-boot/jettyhome/etc/jetty.xml | 2 +- .../config/etc/jetty-with-custom-class.xml | 2 +- .../src/test/config/etc/jetty.xml | 2 +- .../src/main/java/module-info.java | 8 +- .../ContainerDefaultConfigurator.java | 2 +- .../JavaxWebSocketConfiguration.java | 5 +- ...xWebSocketServletContainerInitializer.java | 3 +- .../AnnotatedServerEndpointConfig.java | 2 +- .../JavaxWebSocketServerContainer.java | 6 +- ...vaxWebSocketServerFrameHandlerFactory.java | 4 +- .../UndefinedServerEndpointConfig.java | 2 +- .../javax.servlet.ServletContainerInitializer | 2 +- ...t.server.ServerEndpointConfig$Configurator | 2 +- .../org.eclipse.jetty.webapp.Configuration | 2 +- .../websocket/javax/server/PathParamTest.java | 61 ---------- .../server/browser/JsrBrowserDebugTool.java | 2 +- .../WebSocketServerExamplesTest.java | 20 ++-- .../websocket/javax/tests/LocalServer.java | 6 +- .../jetty/websocket/javax/tests/WSServer.java | 2 +- .../com/acme/websocket/BasicEchoEndpoint.java | 46 ++++++++ ...asicEchoEndpointConfigContextListener.java | 54 +++++++++ .../websocket/IdleTimeoutContextListener.java | 54 +++++++++ .../websocket/IdleTimeoutOnOpenEndpoint.java | 44 ++++++++ .../websocket/IdleTimeoutOnOpenSocket.java | 50 +++++++++ .../websocket/LargeEchoContextListener.java | 39 +++++++ .../websocket/LargeEchoDefaultSocket.java} | 14 ++- .../websocket/OnOpenIdleTimeoutEndpoint.java | 44 ++++++++ .../acme/websocket/PongContextListener.java | 61 ++++++++++ .../acme/websocket/PongMessageEndpoint.java | 66 +++++++++++ .../java/com/acme/websocket/PongSocket.java | 67 +++++++++++ .../websocket/javax/tests/PathParamTest.java | 104 ++++++++++++++++++ .../javax/tests/RestartContextTest.java | 4 +- ...tJavaxWebSocketServerFrameHandlerTest.java | 4 +- .../tests/server/DeploymentExceptionTest.java | 2 +- .../tests/server/EndpointViaConfigTest.java | 61 +--------- .../javax/tests/server/IdleTimeoutTest.java | 6 +- .../JettyServerEndpointConfiguratorTest.java | 2 +- .../tests/server/LargeContainerTest.java | 34 +----- .../javax/tests/server/MemoryUsageTest.java | 2 +- .../javax/tests/server/PingPongTest.java | 103 +---------------- .../WebSocketServerContainerExecutorTest.java | 6 +- .../basic-echo-endpoint-config-web.xml | 2 +- .../resources/idle-timeout-config-web.xml | 2 +- .../test/resources/large-echo-config-web.xml | 2 +- .../src/test/resources/pong-config-web.xml | 2 +- .../src/main/java/module-info.java | 1 + 47 files changed, 698 insertions(+), 315 deletions(-) rename jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/{ => config}/ContainerDefaultConfigurator.java (98%) rename jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/{ => config}/JavaxWebSocketConfiguration.java (89%) rename jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/{ => config}/JavaxWebSocketServletContainerInitializer.java (98%) rename jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/{ => internal}/JavaxWebSocketServerContainer.java (97%) rename jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/{ => internal}/JavaxWebSocketServerFrameHandlerFactory.java (92%) delete mode 100644 jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/PathParamTest.java rename jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/{ => examples}/WebSocketServerExamplesTest.java (90%) create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpoint.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpointConfigContextListener.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutContextListener.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenEndpoint.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoContextListener.java rename jetty-websocket/{javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/DummyServerContainer.java => javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoDefaultSocket.java} (70%) create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/OnOpenIdleTimeoutEndpoint.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongContextListener.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongMessageEndpoint.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongSocket.java create mode 100644 jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/PathParamTest.java diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java index d3ac32dafbd..473fae972ab 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java @@ -26,7 +26,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; /** * Example of setting up a javax.websocket server with Jetty embedded diff --git a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty.xml b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty.xml index 17f38f2776d..70c174072ab 100644 --- a/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty.xml +++ b/jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty.xml @@ -96,7 +96,7 @@ org.eclipse.jetty.webapp.JmxConfiguration org.eclipse.jetty.osgi.annotations.AnnotationConfiguration org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration - org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration + org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-with-custom-class.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-with-custom-class.xml index 9cc5f6f72e7..6c2b9d68082 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-with-custom-class.xml +++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-with-custom-class.xml @@ -82,7 +82,7 @@ org.eclipse.jetty.plus.webapp.EnvConfiguration org.eclipse.jetty.webapp.JmxConfiguration org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration - org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration + org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration org.eclipse.jetty.osgi.annotations.AnnotationConfiguration org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml index 291fccd1873..ad2b008c33a 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml +++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml @@ -85,7 +85,7 @@ org.eclipse.jetty.webapp.JmxConfiguration org.eclipse.jetty.osgi.annotations.AnnotationConfiguration org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration - org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration + org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration diff --git a/jetty-websocket/javax-websocket-server/src/main/java/module-info.java b/jetty-websocket/javax-websocket-server/src/main/java/module-info.java index 3c20f2e9d1d..8ef5adc7618 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/module-info.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/module-info.java @@ -20,13 +20,13 @@ import javax.servlet.ServletContainerInitializer; import javax.websocket.server.ServerEndpointConfig; import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; module org.eclipse.jetty.websocket.javax.server { - exports org.eclipse.jetty.websocket.javax.server; + exports org.eclipse.jetty.websocket.javax.server.config; requires jetty.servlet.api; requires jetty.websocket.api; diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/ContainerDefaultConfigurator.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/ContainerDefaultConfigurator.java similarity index 98% rename from jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/ContainerDefaultConfigurator.java rename to jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/ContainerDefaultConfigurator.java index b4acdeb8b01..9906438cc3f 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/ContainerDefaultConfigurator.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/ContainerDefaultConfigurator.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.config; import java.util.List; import java.util.ServiceLoader; diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketConfiguration.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java similarity index 89% rename from jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketConfiguration.java rename to jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java index 57255fad3b2..d0baa67fb5b 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketConfiguration.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketConfiguration.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.config; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.FragmentConfiguration; @@ -38,6 +38,7 @@ public class JavaxWebSocketConfiguration extends AbstractConfiguration addDependencies(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class, FragmentConfiguration.class); addDependents("org.eclipse.jetty.annotations.AnnotationConfiguration", WebAppConfiguration.class.getName()); protectAndExpose("org.eclipse.jetty.websocket.servlet."); // For WebSocketUpgradeFilter - protectAndExpose("org.eclipse.jetty.websocket.javax."); // TODO Do we need all classes? + protectAndExpose("org.eclipse.jetty.websocket.javax.server.config."); + hide("org.eclipse.jetty.websocket.javax.server.internal"); } } diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServletContainerInitializer.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java similarity index 98% rename from jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServletContainerInitializer.java rename to jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java index 9261f8356be..0780290b912 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServletContainerInitializer.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.config; import java.util.HashSet; import java.util.Set; @@ -39,6 +39,7 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.ThreadClassLoaderScope; import org.eclipse.jetty.websocket.core.WebSocketComponents; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer; import org.eclipse.jetty.websocket.servlet.WebSocketMapping; import org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter; diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/AnnotatedServerEndpointConfig.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/AnnotatedServerEndpointConfig.java index 277fa42daec..f3d03450cec 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/AnnotatedServerEndpointConfig.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/AnnotatedServerEndpointConfig.java @@ -33,7 +33,7 @@ import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer; -import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator; +import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator; public class AnnotatedServerEndpointConfig implements ServerEndpointConfig { diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java similarity index 97% rename from jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java rename to jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java index ffe0ae7bc6b..276c1015cb7 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerContainer.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.internal; import java.util.ArrayList; import java.util.List; @@ -41,9 +41,7 @@ import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketException; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.javax.client.JavaxWebSocketClientContainer; -import org.eclipse.jetty.websocket.javax.server.internal.AnnotatedServerEndpointConfig; -import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketCreator; -import org.eclipse.jetty.websocket.javax.server.internal.UndefinedServerEndpointConfig; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.servlet.WebSocketMapping; @ManagedObject("JSR356 Server Container") diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerFrameHandlerFactory.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java similarity index 92% rename from jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerFrameHandlerFactory.java rename to jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java index 8a5bdee8907..b16b5b2af02 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerFrameHandlerFactory.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/JavaxWebSocketServerFrameHandlerFactory.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.internal; import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; @@ -27,8 +27,6 @@ import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketContainer; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerFactory; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketFrameHandlerMetadata; -import org.eclipse.jetty.websocket.javax.server.internal.DelegatedJavaxServletUpgradeRequest; -import org.eclipse.jetty.websocket.javax.server.internal.PathParamIdentifier; import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/UndefinedServerEndpointConfig.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/UndefinedServerEndpointConfig.java index 8fdaf945db5..a5361a48d6a 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/UndefinedServerEndpointConfig.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/internal/UndefinedServerEndpointConfig.java @@ -27,7 +27,7 @@ import javax.websocket.Encoder; import javax.websocket.Extension; import javax.websocket.server.ServerEndpointConfig; -import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator; +import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator; public class UndefinedServerEndpointConfig implements ServerEndpointConfig { diff --git a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer index 86c5fef3534..68d8b37077c 100644 --- a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer +++ b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer @@ -1 +1 @@ -org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer \ No newline at end of file +org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator index b925d25755c..e9f7fc540a4 100644 --- a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator +++ b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/javax.websocket.server.ServerEndpointConfig$Configurator @@ -1 +1 @@ -org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator \ No newline at end of file +org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration index 280be7ed694..9c5a60b0447 100644 --- a/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration +++ b/jetty-websocket/javax-websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.webapp.Configuration @@ -1 +1 @@ -org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration \ No newline at end of file +org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/PathParamTest.java b/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/PathParamTest.java deleted file mode 100644 index 796ee693ca6..00000000000 --- a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/PathParamTest.java +++ /dev/null @@ -1,61 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.server; - -import javax.websocket.DeploymentException; -import javax.websocket.OnMessage; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class PathParamTest -{ - private JavaxWebSocketServerContainer container; - - @BeforeEach - public void startContainer() throws Exception - { - container = new DummyServerContainer(); - container.start(); - } - - @AfterEach - public void stopContainer() throws Exception - { - container.stop(); - } - - @ServerEndpoint("/pathparam/basic/{name}") - public static class BasicPathParamSocket - { - @OnMessage - public void onMessage(String message, @PathParam("name") String name) - { - } - } - - @Test - public void testBasicPathParamSocket() throws DeploymentException - { - container.addEndpoint(BasicPathParamSocket.class); - } -} diff --git a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/browser/JsrBrowserDebugTool.java b/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/browser/JsrBrowserDebugTool.java index ccb71039385..be0468ed9b3 100644 --- a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/browser/JsrBrowserDebugTool.java +++ b/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/browser/JsrBrowserDebugTool.java @@ -33,7 +33,7 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; /** * Tool to help debug JSR based websocket circumstances reported around browsers. diff --git a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/WebSocketServerExamplesTest.java b/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/examples/WebSocketServerExamplesTest.java similarity index 90% rename from jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/WebSocketServerExamplesTest.java rename to jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/examples/WebSocketServerExamplesTest.java index 56438ccfb47..dffb3e5179c 100644 --- a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/WebSocketServerExamplesTest.java +++ b/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/examples/WebSocketServerExamplesTest.java @@ -16,7 +16,7 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package org.eclipse.jetty.websocket.javax.server.examples; import java.net.URI; import java.util.concurrent.ArrayBlockingQueue; @@ -45,9 +45,7 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Credential; -import org.eclipse.jetty.websocket.javax.server.examples.GetHttpSessionSocket; -import org.eclipse.jetty.websocket.javax.server.examples.MyAuthedSocket; -import org.eclipse.jetty.websocket.javax.server.examples.StreamingEchoSocket; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -93,15 +91,15 @@ public class WebSocketServerExamplesTest } static Server _server; - static ServerConnector connector; + static ServerConnector _connector; static ServletContextHandler _context; @BeforeAll public static void setup() throws Exception { _server = new Server(); - connector = new ServerConnector(_server); - _server.addConnector(connector); + _connector = new ServerConnector(_server); + _server.addConnector(_connector); _context = new ServletContextHandler(ServletContextHandler.SESSIONS); _context.setContextPath("/"); @@ -116,7 +114,7 @@ public class WebSocketServerExamplesTest }); _server.start(); - System.setProperty("org.eclipse.jetty.websocket.port", Integer.toString(connector.getLocalPort())); + System.setProperty("org.eclipse.jetty.websocket.port", Integer.toString(_connector.getLocalPort())); } @AfterAll @@ -155,7 +153,7 @@ public class WebSocketServerExamplesTest public void testMyAuthedSocket() throws Exception { //HttpClient is configured for BasicAuthentication with the XmlHttpClientProvider - URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/secured/socket"); + URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/secured/socket"); WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); ClientSocket clientEndpoint = new ClientSocket(); @@ -172,7 +170,7 @@ public class WebSocketServerExamplesTest @Test public void testStreamingEchoSocket() throws Exception { - URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/echo"); + URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/echo"); WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); ClientSocket clientEndpoint = new ClientSocket(); @@ -189,7 +187,7 @@ public class WebSocketServerExamplesTest @Test public void testGetHttpSessionSocket() throws Exception { - URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/example"); + URI uri = URI.create("ws://localhost:" + _connector.getLocalPort() + "/example"); WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); ClientSocket clientEndpoint = new ClientSocket(); 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 5a638ab8cd0..9ed2a87aa3c 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 @@ -50,9 +50,9 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.websocket.core.internal.Parser; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSession; import org.eclipse.jetty.websocket.javax.common.JavaxWebSocketSessionListener; -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.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerFrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; diff --git a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/WSServer.java b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/WSServer.java index 817fcc2a7ed..52beae928fb 100644 --- a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/WSServer.java +++ b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/WSServer.java @@ -39,7 +39,7 @@ 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.webapp.WebAppContext; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketConfiguration; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpoint.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpoint.java new file mode 100644 index 00000000000..81ac929eb70 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpoint.java @@ -0,0 +1,46 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/echo") +public class BasicEchoEndpoint extends Endpoint implements MessageHandler.Whole +{ + private Session session; + + @Override + public void onMessage(String msg) + { + // reply with echo + session.getAsyncRemote().sendText(msg); + } + + @OnOpen + public void onOpen(Session session, EndpointConfig config) + { + this.session = session; + session.addMessageHandler(this); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpointConfigContextListener.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpointConfigContextListener.java new file mode 100644 index 00000000000..4b8ddb988a8 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/BasicEchoEndpointConfigContextListener.java @@ -0,0 +1,54 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.websocket.DeploymentException; +import javax.websocket.server.ServerEndpointConfig; + +public class BasicEchoEndpointConfigContextListener implements ServletContextListener +{ + @Override + public void contextDestroyed(ServletContextEvent sce) + { + /* do nothing */ + } + + @Override + public void contextInitialized(ServletContextEvent sce) + { + javax.websocket.server.ServerContainer container = (javax.websocket.server.ServerContainer)sce.getServletContext() + .getAttribute(javax.websocket.server.ServerContainer.class.getName()); + if (container == null) + throw new IllegalStateException("No Websocket ServerContainer in " + sce.getServletContext()); + + // Build up a configuration with a specific path + String path = "/echo"; + ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, path); + try + { + container.addEndpoint(builder.build()); + } + catch (DeploymentException e) + { + throw new RuntimeException("Unable to add endpoint via config file", e); + } + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutContextListener.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutContextListener.java new file mode 100644 index 00000000000..e58ba1b9726 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutContextListener.java @@ -0,0 +1,54 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.websocket.DeploymentException; +import javax.websocket.server.ServerContainer; +import javax.websocket.server.ServerEndpointConfig; + +/** + * Example of adding a server WebSocket (extending {@link javax.websocket.Endpoint}) programmatically via config + */ +public class IdleTimeoutContextListener implements ServletContextListener +{ + @Override + public void contextDestroyed(ServletContextEvent sce) + { + /* do nothing */ + } + + @Override + public void contextInitialized(ServletContextEvent sce) + { + ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName()); + // Build up a configuration with a specific path + String path = "/idle-onopen-endpoint"; + ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(OnOpenIdleTimeoutEndpoint.class, path); + try + { + container.addEndpoint(builder.build()); + } + catch (DeploymentException e) + { + throw new RuntimeException("Unable to add endpoint via config file", e); + } + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenEndpoint.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenEndpoint.java new file mode 100644 index 00000000000..8ad113ec775 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenEndpoint.java @@ -0,0 +1,44 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.Session; + +public class IdleTimeoutOnOpenEndpoint extends Endpoint implements MessageHandler.Whole +{ + private Session session; + + @Override + public void onOpen(Session session, EndpointConfig config) + { + this.session = session; + session.addMessageHandler(this); + session.setMaxIdleTimeout(500); + } + + @Override + public void onMessage(String message) + { + // echo message back (this is an indication of timeout failure) + session.getAsyncRemote().sendText(message); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java new file mode 100644 index 00000000000..3278e6594db --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/IdleTimeoutOnOpenSocket.java @@ -0,0 +1,50 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.websocket.core.WebSocketTimeoutException; + +@ServerEndpoint(value = "/idle-onopen-socket") +public class IdleTimeoutOnOpenSocket +{ + @OnOpen + public void onOpen(Session session) + { + session.setMaxIdleTimeout(500); + } + + @OnMessage + public String onMessage(String msg) + { + return msg; + } + + @OnError + public void onError(Throwable cause) + { + if (!(cause instanceof WebSocketTimeoutException)) + throw new RuntimeException(cause); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoContextListener.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoContextListener.java new file mode 100644 index 00000000000..813caf986df --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoContextListener.java @@ -0,0 +1,39 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.websocket.server.ServerContainer; + +public class LargeEchoContextListener implements ServletContextListener +{ + @Override + public void contextDestroyed(ServletContextEvent sce) + { + /* do nothing */ + } + + @Override + public void contextInitialized(ServletContextEvent sce) + { + ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName()); + container.setDefaultMaxTextMessageBufferSize(128 * 1024); + } +} diff --git a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/DummyServerContainer.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoDefaultSocket.java similarity index 70% rename from jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/DummyServerContainer.java rename to jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoDefaultSocket.java index c39c5169bea..f5b9ddbfb9b 100644 --- a/jetty-websocket/javax-websocket-server/src/test/java/org/eclipse/jetty/websocket/javax/server/DummyServerContainer.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/LargeEchoDefaultSocket.java @@ -16,14 +16,18 @@ // ======================================================================== // -package org.eclipse.jetty.websocket.javax.server; +package com.acme.websocket; -import org.eclipse.jetty.websocket.servlet.WebSocketMapping; +import javax.websocket.OnMessage; +import javax.websocket.server.ServerEndpoint; -public class DummyServerContainer extends JavaxWebSocketServerContainer +@ServerEndpoint(value = "/echo/large") +public class LargeEchoDefaultSocket { - public DummyServerContainer() + @OnMessage + public void echo(javax.websocket.Session session, String msg) { - super(new WebSocketMapping()); + // reply with echo + session.getAsyncRemote().sendText(msg); } } diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/OnOpenIdleTimeoutEndpoint.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/OnOpenIdleTimeoutEndpoint.java new file mode 100644 index 00000000000..71c305fa353 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/OnOpenIdleTimeoutEndpoint.java @@ -0,0 +1,44 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.Session; + +public class OnOpenIdleTimeoutEndpoint extends Endpoint implements MessageHandler.Whole +{ + private Session session; + + @Override + public void onOpen(Session session, EndpointConfig config) + { + this.session = session; + session.addMessageHandler(this); + session.setMaxIdleTimeout(500); + } + + @Override + public void onMessage(String message) + { + // echo message back (this is an indication of timeout failure) + session.getAsyncRemote().sendText(message); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongContextListener.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongContextListener.java new file mode 100644 index 00000000000..68e47ecd086 --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongContextListener.java @@ -0,0 +1,61 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.websocket.DeploymentException; +import javax.websocket.HandshakeResponse; +import javax.websocket.server.HandshakeRequest; +import javax.websocket.server.ServerContainer; +import javax.websocket.server.ServerEndpointConfig; + +public class PongContextListener implements ServletContextListener +{ + public static class Config extends ServerEndpointConfig.Configurator + { + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) + { + sec.getUserProperties().put("path", sec.getPath()); + super.modifyHandshake(sec, request, response); + } + } + + @Override + public void contextDestroyed(ServletContextEvent sce) + { + /* do nothing */ + } + + @Override + public void contextInitialized(ServletContextEvent sce) + { + ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName()); + try + { + ServerEndpointConfig.Configurator config = new Config(); + container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").configurator(config).build()); + } + catch (DeploymentException e) + { + throw new RuntimeException("Unable to add endpoint directly", e); + } + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongMessageEndpoint.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongMessageEndpoint.java new file mode 100644 index 00000000000..b7253c13fdf --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongMessageEndpoint.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.PongMessage; +import javax.websocket.Session; + +public class PongMessageEndpoint extends Endpoint implements MessageHandler.Whole +{ + private String path = "?"; + private Session session; + + @Override + public void onOpen(Session session, EndpointConfig config) + { + this.session = session; + this.session.addMessageHandler(this); + this.path = (String)config.getUserProperties().get("path"); + } + + @Override + public void onMessage(PongMessage pong) + { + byte[] buf = toArray(pong.getApplicationData()); + String message = new String(buf, StandardCharsets.UTF_8); + this.session.getAsyncRemote().sendText("PongMessageEndpoint.onMessage(PongMessage):[" + path + "]:" + message); + } + + public static byte[] toArray(ByteBuffer buffer) + { + if (buffer.hasArray()) + { + byte[] array = buffer.array(); + int from = buffer.arrayOffset() + buffer.position(); + return Arrays.copyOfRange(array, from, from + buffer.remaining()); + } + else + { + byte[] to = new byte[buffer.remaining()]; + buffer.slice().get(to); + return to; + } + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongSocket.java b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongSocket.java new file mode 100644 index 00000000000..5a0385d5ddb --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/com/acme/websocket/PongSocket.java @@ -0,0 +1,67 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package com.acme.websocket; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import javax.websocket.EndpointConfig; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.PongMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint(value = "/pong-socket", configurator = PongContextListener.Config.class) +public class PongSocket +{ + private String path = "?"; + private Session session; + + @OnOpen + public void onOpen(Session session, EndpointConfig config) + { + this.session = session; + this.path = (String)config.getUserProperties().get("path"); + } + + @OnMessage + public void onPong(PongMessage pong) + { + byte[] buf = toArray(pong.getApplicationData()); + String message = new String(buf, StandardCharsets.UTF_8); + this.session.getAsyncRemote().sendText("PongSocket.onPong(PongMessage)[" + path + "]:" + message); + } + + public static byte[] toArray(ByteBuffer buffer) + { + if (buffer.hasArray()) + { + byte[] array = buffer.array(); + int from = buffer.arrayOffset() + buffer.position(); + return Arrays.copyOfRange(array, from, from + buffer.remaining()); + } + else + { + byte[] to = new byte[buffer.remaining()]; + buffer.slice().get(to); + return to; + } + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/PathParamTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/PathParamTest.java new file mode 100644 index 00000000000..1796eb4caeb --- /dev/null +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/PathParamTest.java @@ -0,0 +1,104 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests; + +import java.net.URI; +import java.util.concurrent.TimeUnit; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +public class PathParamTest +{ + private Server _server; + private ServerConnector _connector; + private ServletContextHandler _context; + + @BeforeEach + public void startContainer() throws Exception + { + _server = new Server(); + _connector = new ServerConnector(_server); + _server.addConnector(_connector); + + _context = new ServletContextHandler(ServletContextHandler.SESSIONS); + _context.setContextPath("/"); + _server.setHandler(_context); + + JavaxWebSocketServletContainerInitializer.configure(_context, (context, container) -> + container.addEndpoint(EchoParamSocket.class)); + + _server.start(); + } + + @AfterEach + public void stopContainer() throws Exception + { + _server.stop(); + } + + @ServerEndpoint("/pathparam/echo/{name}") + public static class EchoParamSocket + { + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(String message, @PathParam("name") String name) + { + session.getAsyncRemote().sendText(message+"-"+name); + } + } + + @Test + public void testBasicPathParamSocket() throws Exception + { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + EventSocket clientEndpoint = new EventSocket(); + + URI serverUri = URI.create("ws://localhost:"+ _connector.getLocalPort()+"/pathparam/echo/myParam"); + Session session = container.connectToServer(clientEndpoint, serverUri); + session.getBasicRemote().sendText("echo"); + + String resp = clientEndpoint.messageQueue.poll(1, TimeUnit.SECONDS); + assertThat("Response echo", resp, is("echo-myParam")); + session.close(); + clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS); + } +} diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/RestartContextTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/RestartContextTest.java index 2499f5a5017..80a0265c382 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/RestartContextTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/RestartContextTest.java @@ -37,8 +37,8 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/AbstractJavaxWebSocketServerFrameHandlerTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/AbstractJavaxWebSocketServerFrameHandlerTest.java index 548526309ee..ae920dae9ad 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/AbstractJavaxWebSocketServerFrameHandlerTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/AbstractJavaxWebSocketServerFrameHandlerTest.java @@ -27,8 +27,8 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.websocket.javax.client.EmptyClientEndpointConfig; import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders; import org.eclipse.jetty.websocket.javax.common.encoders.AvailableEncoders; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/DeploymentExceptionTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/DeploymentExceptionTest.java index 052d8f87e3f..b38868cbfc0 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/DeploymentExceptionTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/DeploymentExceptionTest.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.websocket.javax.common.util.InvalidSignatureException; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidCloseIntSocket; import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidErrorErrorSocket; import org.eclipse.jetty.websocket.javax.tests.server.sockets.InvalidErrorIntSocket; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java index 69f27b6c05d..43f0e5dbe8c 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/EndpointViaConfigTest.java @@ -21,16 +21,9 @@ package org.eclipse.jetty.websocket.javax.tests.server; import java.net.URI; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.websocket.DeploymentException; -import javax.websocket.EndpointConfig; -import javax.websocket.MessageHandler; -import javax.websocket.OnOpen; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; -import javax.websocket.server.ServerEndpointConfig; +import com.acme.websocket.BasicEchoEndpoint; +import com.acme.websocket.BasicEchoEndpointConfigContextListener; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.Callback; @@ -41,7 +34,6 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; -import org.eclipse.jetty.websocket.javax.tests.WSEventTracker; import org.eclipse.jetty.websocket.javax.tests.WSServer; import org.eclipse.jetty.websocket.javax.tests.framehandlers.FrameHandlerTracker; import org.junit.jupiter.api.Test; @@ -59,55 +51,6 @@ public class EndpointViaConfigTest { private static final Logger LOG = Log.getLogger(EndpointViaConfigTest.class); - @ServerEndpoint("/echo") - public static class BasicEchoEndpoint extends WSEventTracker implements MessageHandler.Whole - { - @Override - public void onMessage(String msg) - { - super.onWsText(msg); - // reply with echo - session.getAsyncRemote().sendText(msg); - } - - @OnOpen - public void onOpen(Session session, EndpointConfig config) - { - super.onWsOpen(session, config); - this.session.addMessageHandler(this); - } - } - - public static class BasicEchoEndpointConfigContextListener implements ServletContextListener - { - @Override - public void contextDestroyed(ServletContextEvent sce) - { - /* do nothing */ - } - - @Override - public void contextInitialized(ServletContextEvent sce) - { - javax.websocket.server.ServerContainer container = (javax.websocket.server.ServerContainer)sce.getServletContext() - .getAttribute(javax.websocket.server.ServerContainer.class.getName()); - if (container == null) - throw new IllegalStateException("No Websocket ServerContainer in " + sce.getServletContext()); - - // Build up a configuration with a specific path - String path = "/echo"; - ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, path); - try - { - container.addEndpoint(builder.build()); - } - catch (DeploymentException e) - { - throw new RuntimeException("Unable to add endpoint via config file", e); - } - } - } - public WorkDir testdir; @Test diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java index 261f265c3d0..b3561a78b92 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/IdleTimeoutTest.java @@ -21,6 +21,9 @@ package org.eclipse.jetty.websocket.javax.tests.server; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; +import com.acme.websocket.IdleTimeoutContextListener; +import com.acme.websocket.IdleTimeoutOnOpenEndpoint; +import com.acme.websocket.IdleTimeoutOnOpenSocket; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.log.StacklessLogging; import org.eclipse.jetty.webapp.WebAppContext; @@ -29,8 +32,6 @@ import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.OpCode; import org.eclipse.jetty.websocket.javax.tests.Fuzzer; import org.eclipse.jetty.websocket.javax.tests.WSServer; -import org.eclipse.jetty.websocket.javax.tests.server.sockets.IdleTimeoutOnOpenEndpoint; -import org.eclipse.jetty.websocket.javax.tests.server.sockets.IdleTimeoutOnOpenSocket; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -59,7 +60,6 @@ public class IdleTimeoutTest WebAppContext webapp = server.createWebAppContext(); server.deployWebapp(webapp); - // wsb.dump(); } @AfterAll diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JettyServerEndpointConfiguratorTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JettyServerEndpointConfiguratorTest.java index 0c28d087267..61ab2aca1f2 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JettyServerEndpointConfiguratorTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JettyServerEndpointConfiguratorTest.java @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.ServiceLoader; import javax.websocket.server.ServerEndpointConfig; -import org.eclipse.jetty.websocket.javax.server.ContainerDefaultConfigurator; +import org.eclipse.jetty.websocket.javax.server.config.ContainerDefaultConfigurator; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java index 21ffd70a40a..fbdf26ce9db 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/LargeContainerTest.java @@ -23,12 +23,8 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.websocket.OnMessage; -import javax.websocket.server.ServerContainer; -import javax.websocket.server.ServerEndpoint; +import com.acme.websocket.LargeEchoDefaultSocket; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.Callback; @@ -51,33 +47,6 @@ import static org.hamcrest.Matchers.is; @ExtendWith(WorkDirExtension.class) public class LargeContainerTest { - @ServerEndpoint(value = "/echo/large") - public static class LargeEchoDefaultSocket - { - @OnMessage - public void echo(javax.websocket.Session session, String msg) - { - // reply with echo - session.getAsyncRemote().sendText(msg); - } - } - - public static class LargeEchoContextListener implements ServletContextListener - { - @Override - public void contextDestroyed(ServletContextEvent sce) - { - /* do nothing */ - } - - @Override - public void contextInitialized(ServletContextEvent sce) - { - ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName()); - container.setDefaultMaxTextMessageBufferSize(128 * 1024); - } - } - public WorkDir testdir; @SuppressWarnings("Duplicates") @@ -95,7 +64,6 @@ public class LargeContainerTest WebAppContext webapp = wsb.createWebAppContext(); wsb.deployWebapp(webapp); - // wsb.dump(); WebSocketCoreClient client = new WebSocketCoreClient(); try diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java index e5e0a6821a6..1cb415d913f 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java @@ -35,7 +35,7 @@ import javax.websocket.server.ServerEndpointConfig; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java index 1b44cdc23f0..e323ff87ea5 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/PingPongTest.java @@ -19,33 +19,17 @@ package org.eclipse.jetty.websocket.javax.tests.server; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Duration; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.websocket.DeploymentException; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.HandshakeResponse; -import javax.websocket.MessageHandler; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.PongMessage; -import javax.websocket.Session; -import javax.websocket.server.HandshakeRequest; -import javax.websocket.server.ServerContainer; -import javax.websocket.server.ServerEndpoint; -import javax.websocket.server.ServerEndpointConfig; +import com.acme.websocket.PongContextListener; +import com.acme.websocket.PongMessageEndpoint; +import com.acme.websocket.PongSocket; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.core.Frame; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -64,87 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertTimeout; public class PingPongTest { - @ServerEndpoint(value = "/pong-socket", configurator = PongContextListener.Config.class) - public static class PongSocket - { - private static final Logger LOG = Log.getLogger(PongSocket.class); - private String path = "?"; - private Session session; - - @OnOpen - public void onOpen(Session session, EndpointConfig config) - { - this.session = session; - this.path = (String)config.getUserProperties().get("path"); - } - - @OnMessage - public void onPong(PongMessage pong) - { - if (LOG.isDebugEnabled()) - LOG.debug("PongSocket.onPong(): PongMessage.appData={}", BufferUtil.toDetailString(pong.getApplicationData())); - byte[] buf = BufferUtil.toArray(pong.getApplicationData()); - String message = new String(buf, StandardCharsets.UTF_8); - this.session.getAsyncRemote().sendText("PongSocket.onPong(PongMessage)[" + path + "]:" + message); - } - } - - public static class PongMessageEndpoint extends Endpoint implements MessageHandler.Whole - { - private String path = "?"; - private Session session; - - @Override - public void onOpen(Session session, EndpointConfig config) - { - this.session = session; - this.session.addMessageHandler(this); - this.path = (String)config.getUserProperties().get("path"); - } - - @Override - public void onMessage(PongMessage pong) - { - byte[] buf = BufferUtil.toArray(pong.getApplicationData()); - String message = new String(buf, StandardCharsets.UTF_8); - this.session.getAsyncRemote().sendText("PongMessageEndpoint.onMessage(PongMessage):[" + path + "]:" + message); - } - } - - public static class PongContextListener implements ServletContextListener - { - public static class Config extends ServerEndpointConfig.Configurator - { - @Override - public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) - { - sec.getUserProperties().put("path", sec.getPath()); - super.modifyHandshake(sec, request, response); - } - } - - @Override - public void contextDestroyed(ServletContextEvent sce) - { - /* do nothing */ - } - - @Override - public void contextInitialized(ServletContextEvent sce) - { - ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName()); - try - { - ServerEndpointConfig.Configurator config = new Config(); - container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").configurator(config).build()); - } - catch (DeploymentException e) - { - throw new RuntimeException("Unable to add endpoint directly", e); - } - } - } - private static WSServer server; private static WebSocketCoreClient client; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java index 7db6aa77bbe..e406aed6db6 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java @@ -44,12 +44,12 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.thread.QueuedThreadPool; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServerContainer; -import org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.server.internal.JavaxWebSocketServerContainer; import org.eclipse.jetty.websocket.javax.tests.WSURI; import org.junit.jupiter.api.Test; -import static org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE; +import static org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; diff --git a/jetty-websocket/javax-websocket-tests/src/test/resources/basic-echo-endpoint-config-web.xml b/jetty-websocket/javax-websocket-tests/src/test/resources/basic-echo-endpoint-config-web.xml index 2daa96edb6c..191ba7fff8b 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/resources/basic-echo-endpoint-config-web.xml +++ b/jetty-websocket/javax-websocket-tests/src/test/resources/basic-echo-endpoint-config-web.xml @@ -7,6 +7,6 @@ version="3.0"> - org.eclipse.jetty.websocket.javax.tests.server.EndpointViaConfigTest$BasicEchoEndpointConfigContextListener + com.acme.websocket.BasicEchoEndpointConfigContextListener \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-tests/src/test/resources/idle-timeout-config-web.xml b/jetty-websocket/javax-websocket-tests/src/test/resources/idle-timeout-config-web.xml index ecb89d2acd2..a60cea6c700 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/resources/idle-timeout-config-web.xml +++ b/jetty-websocket/javax-websocket-tests/src/test/resources/idle-timeout-config-web.xml @@ -7,6 +7,6 @@ version="3.0"> - org.eclipse.jetty.websocket.javax.tests.server.IdleTimeoutContextListener + com.acme.websocket.IdleTimeoutContextListener \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-tests/src/test/resources/large-echo-config-web.xml b/jetty-websocket/javax-websocket-tests/src/test/resources/large-echo-config-web.xml index c4dfacddef3..b032926b059 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/resources/large-echo-config-web.xml +++ b/jetty-websocket/javax-websocket-tests/src/test/resources/large-echo-config-web.xml @@ -7,6 +7,6 @@ version="3.0"> - org.eclipse.jetty.websocket.javax.tests.server.LargeContainerTest$LargeEchoContextListener + com.acme.websocket.LargeEchoContextListener \ No newline at end of file diff --git a/jetty-websocket/javax-websocket-tests/src/test/resources/pong-config-web.xml b/jetty-websocket/javax-websocket-tests/src/test/resources/pong-config-web.xml index aa16c7af156..a3478e35e2a 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/resources/pong-config-web.xml +++ b/jetty-websocket/javax-websocket-tests/src/test/resources/pong-config-web.xml @@ -7,6 +7,6 @@ version="3.0"> - org.eclipse.jetty.websocket.javax.tests.server.PingPongTest$PongContextListener + com.acme.websocket.PongContextListener \ No newline at end of file diff --git a/jetty-websocket/jetty-websocket-server/src/main/java/module-info.java b/jetty-websocket/jetty-websocket-server/src/main/java/module-info.java index 689f680ecea..005c0f64d7f 100644 --- a/jetty-websocket/jetty-websocket-server/src/main/java/module-info.java +++ b/jetty-websocket/jetty-websocket-server/src/main/java/module-info.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerI module org.eclipse.jetty.websocket.jetty.server { exports org.eclipse.jetty.websocket.server; + exports org.eclipse.jetty.websocket.server.config; requires jetty.servlet.api; requires org.eclipse.jetty.http;