From dc74bcf4ccc5d70dc8ef60643bdbc0fe2ceb1309 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 8 Oct 2020 09:16:59 +1100 Subject: [PATCH 1/2] throw ISE if WebSocketSCI.configure() is called on started ServletContextHandler Signed-off-by: Lachlan Roberts --- .../config/JavaxWebSocketServletContainerInitializer.java | 3 +++ .../config/JettyWebSocketServletContainerInitializer.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java index af4cca34fe3..2b5d3d644b5 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java @@ -99,6 +99,9 @@ public class JavaxWebSocketServletContainerInitializer implements ServletContain */ public static void configure(ServletContextHandler context, Configurator configurator) { + if (context.isStarted()) + throw new IllegalStateException("configure should be called before starting"); + // In this embedded-jetty usage, allow ServletContext.addListener() to // add other ServletContextListeners (such as the ContextDestroyListener) after // the initialization phase is over. (important for this SCI to function) diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java index 4740fbc75f8..be3f63ec51c 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java @@ -53,6 +53,9 @@ public class JettyWebSocketServletContainerInitializer implements ServletContain */ public static void configure(ServletContextHandler context, Configurator configurator) { + if (context.isStarted()) + throw new IllegalStateException("configure should be called before starting"); + context.addEventListener( ContainerInitializer .asContextListener(new JettyWebSocketServletContainerInitializer()) From 7ed6998a9c63417ac42cff0396fe4f40d7316068 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 15 Oct 2020 16:36:04 +1100 Subject: [PATCH 2/2] changes from review Signed-off-by: Lachlan Roberts --- .../config/JavaxWebSocketServletContainerInitializer.java | 2 +- .../config/JettyWebSocketServletContainerInitializer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java index 2b5d3d644b5..576fd96ad28 100644 --- a/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java +++ b/jetty-websocket/websocket-javax-server/src/main/java/org/eclipse/jetty/websocket/javax/server/config/JavaxWebSocketServletContainerInitializer.java @@ -99,7 +99,7 @@ public class JavaxWebSocketServletContainerInitializer implements ServletContain */ public static void configure(ServletContextHandler context, Configurator configurator) { - if (context.isStarted()) + if (!context.isStopped()) throw new IllegalStateException("configure should be called before starting"); // In this embedded-jetty usage, allow ServletContext.addListener() to diff --git a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java index be3f63ec51c..a8d19f58035 100644 --- a/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java +++ b/jetty-websocket/websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/config/JettyWebSocketServletContainerInitializer.java @@ -53,7 +53,7 @@ public class JettyWebSocketServletContainerInitializer implements ServletContain */ public static void configure(ServletContextHandler context, Configurator configurator) { - if (context.isStarted()) + if (!context.isStopped()) throw new IllegalStateException("configure should be called before starting"); context.addEventListener(