diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index be1c5041d5c..314125d8e89 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -96,7 +96,19 @@ public class ServletContextHandler extends ContextHandler public final static int GZIP=4; public final static int NO_SESSIONS=0; public final static int NO_SECURITY=0; - + + public static ServletContextHandler getServletContextHandler(ServletContext servletContext, String purpose) + { + ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); + if (contextHandler == null) + throw new IllegalStateException("No Jetty ContextHandler, " + purpose+ " unavailable"); + + if (!(contextHandler instanceof ServletContextHandler)) + throw new IllegalStateException("No Jetty ServletContextHandler, " + purpose + " unavailable"); + + return (ServletContextHandler)contextHandler; + } + public interface ServletContainerInitializerCaller extends LifeCycle {}; protected final DecoratedObjectFactory _objFactory; diff --git a/jetty-websocket/javax-websocket-client/src/main/java/org/eclipse/jetty/websocket/javax/client/JavaxWebSocketClientContainer.java b/jetty-websocket/javax-websocket-client/src/main/java/org/eclipse/jetty/websocket/javax/client/JavaxWebSocketClientContainer.java index 3986d8e6ef4..4e48a37b7e6 100644 --- a/jetty-websocket/javax-websocket-client/src/main/java/org/eclipse/jetty/websocket/javax/client/JavaxWebSocketClientContainer.java +++ b/jetty-websocket/javax-websocket-client/src/main/java/org/eclipse/jetty/websocket/javax/client/JavaxWebSocketClientContainer.java @@ -25,6 +25,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.function.Supplier; + import javax.websocket.ClientEndpoint; import javax.websocket.ClientEndpointConfig; import javax.websocket.DeploymentException; @@ -61,7 +62,11 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple public JavaxWebSocketClientContainer() { - this(() -> new WebSocketCoreClient()); + this(() -> { + WebSocketCoreClient coreClient = new WebSocketCoreClient(); + coreClient.getHttpClient().setName("Javax-WebSocketClient@" + Integer.toHexString(coreClient.getHttpClient().hashCode())); + return coreClient; + }); } public JavaxWebSocketClientContainer(Supplier coreClientFactory) @@ -75,7 +80,7 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple { super(); this.coreClient = coreClient; - this.addBean(this.coreClient); + this.addBean(coreClient); this.objectFactory = new DecoratedObjectFactory(); this.extensionRegistry = new WebSocketExtensionRegistry(); this.frameHandlerFactory = new JavaxWebSocketClientFrameHandlerFactory(this); @@ -103,8 +108,10 @@ public class JavaxWebSocketClientContainer extends JavaxWebSocketContainer imple if (coreClient == null) { coreClient = coreClientFactory.get(); - this.coreClient.getHttpClient().setName("Javax-WebSocketClient@" + Integer.toHexString(this.coreClient.getHttpClient().hashCode())); - addManaged(coreClient); + if (coreClient.isRunning()) + addBean(coreClient,false); + else + addManaged(coreClient); } return coreClient; diff --git a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java index 34be193823e..793a260feb5 100644 --- a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java +++ b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandler.java @@ -18,6 +18,25 @@ package org.eclipse.jetty.websocket.javax.common; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +import javax.websocket.CloseReason; +import javax.websocket.Decoder; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.PongMessage; +import javax.websocket.Session; + import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.log.Log; @@ -39,24 +58,6 @@ import org.eclipse.jetty.websocket.javax.common.messages.PartialByteBufferMessag import org.eclipse.jetty.websocket.javax.common.messages.PartialStringMessageSink; import org.eclipse.jetty.websocket.javax.common.util.InvokerUtils; -import javax.websocket.CloseReason; -import javax.websocket.Decoder; -import javax.websocket.EndpointConfig; -import javax.websocket.MessageHandler; -import javax.websocket.PongMessage; -import javax.websocket.Session; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - public class JavaxWebSocketFrameHandler implements FrameHandler { private final Logger LOG; @@ -217,9 +218,7 @@ public class JavaxWebSocketFrameHandler implements FrameHandler if (errorHandle == null) { - LOG.warn("Unhandled Error: Endpoint " + endpointInstance.getClass().getName() + " : " + cause); - if (LOG.isDebugEnabled()) - LOG.debug("unhandled", cause); + LOG.warn("Unhandled Error: " + endpointInstance, cause); return; } 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/JavaxWebSocketServerContainer.java index 90626fca3e5..18ac6e302c1 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/JavaxWebSocketServerContainer.java @@ -24,8 +24,6 @@ import java.util.List; import java.util.concurrent.Executor; import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; import javax.servlet.ServletException; import javax.websocket.DeploymentException; import javax.websocket.EndpointConfig; @@ -80,12 +78,13 @@ public class JavaxWebSocketServerContainer if (!(handler instanceof ServletContextHandler)) return null; - return (javax.websocket.WebSocketContainer)handler.getServletContext().getAttribute(ServerContainer.class.getName()); + return (javax.websocket.WebSocketContainer)handler.getServletContext().getAttribute("javax.websocket.server.ServerContainer"); } public static JavaxWebSocketServerContainer ensureContainer(ServletContext servletContext) throws ServletException { - ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); + ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "Javax Websocket"); + JavaxWebSocketServerContainer container = contextHandler.getBean(JavaxWebSocketServerContainer.class); if (container==null) { @@ -116,7 +115,7 @@ public class JavaxWebSocketServerContainer return container; } - private final WebSocketMapping _webSocketMapping; + private final WebSocketMapping webSocketMapping; private final JavaxWebSocketServerFrameHandlerFactory frameHandlerFactory; private final Executor executor; private final FrameHandler.ConfigurationCustomizer customizer = new FrameHandler.ConfigurationCustomizer(); @@ -138,7 +137,7 @@ public class JavaxWebSocketServerContainer client.getHttpClient().setExecutor(executor); return client; }); - this._webSocketMapping = webSocketMapping; + this.webSocketMapping = webSocketMapping; this.executor = executor; this.frameHandlerFactory = new JavaxWebSocketServerFrameHandlerFactory(this); } @@ -148,7 +147,7 @@ public class JavaxWebSocketServerContainer { ContextHandler contextHandler = (ContextHandler) context; JavaxWebSocketServerContainer container = contextHandler.getBean(JavaxWebSocketServerContainer.class); - if (container==null) + if (container==this) { contextHandler.removeBean(container); LifeCycle.stop(container); @@ -159,7 +158,7 @@ public class JavaxWebSocketServerContainer @Override public ByteBufferPool getBufferPool() { - return this._webSocketMapping.getBufferPool(); + return this.webSocketMapping.getBufferPool(); } @Override @@ -171,7 +170,7 @@ public class JavaxWebSocketServerContainer @Override public WebSocketExtensionRegistry getExtensionRegistry() { - return this._webSocketMapping.getExtensionRegistry(); + return this.webSocketMapping.getExtensionRegistry(); } @Override @@ -183,7 +182,7 @@ public class JavaxWebSocketServerContainer @Override public DecoratedObjectFactory getObjectFactory() { - return this._webSocketMapping.getObjectFactory(); + return this.webSocketMapping.getObjectFactory(); } @Override @@ -269,10 +268,11 @@ public class JavaxWebSocketServerContainer { frameHandlerFactory.getMetadata(config.getEndpointClass(), config); - JavaxWebSocketCreator creator = new JavaxWebSocketCreator(this, config, this._webSocketMapping + JavaxWebSocketCreator creator = new JavaxWebSocketCreator(this, config, this.webSocketMapping .getExtensionRegistry()); - this._webSocketMapping.addMapping(new UriTemplatePathSpec(config.getPath()), creator, frameHandlerFactory, customizer); + this.webSocketMapping + .addMapping(new UriTemplatePathSpec(config.getPath()), creator, frameHandlerFactory, customizer); } @Override diff --git a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainerInitializer.java index ea83e56fa66..e58567575a5 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainerInitializer.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainerInitializer.java @@ -20,11 +20,9 @@ package org.eclipse.jetty.websocket.javax.server; import java.util.HashSet; import java.util.Set; -import java.util.concurrent.Executor; + import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; import javax.servlet.ServletException; import javax.servlet.annotation.HandlesTypes; import javax.websocket.DeploymentException; @@ -33,8 +31,6 @@ import javax.websocket.server.ServerApplicationConfig; import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.TypeUtil; @@ -126,7 +122,7 @@ public class JavaxWebSocketServerContainerInitializer implements ServletContaine return; } - JavaxWebSocketServerContainer container = configureContext((ServletContextHandler)(ContextHandler.getContextHandler(context))); + JavaxWebSocketServerContainer container = configureContext(ServletContextHandler.getServletContextHandler(context,"Javax WebSocket SCI")); try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader())) { diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/DecoderReaderManySmallTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/DecoderReaderManySmallTest.java index 71d97ce28b8..c3172ab65c4 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/DecoderReaderManySmallTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/DecoderReaderManySmallTest.java @@ -18,25 +18,9 @@ package org.eclipse.jetty.websocket.javax.tests.client; -import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.websocket.core.FrameHandler; -import org.eclipse.jetty.websocket.core.MessageHandler; -import org.eclipse.jetty.websocket.core.server.Negotiation; -import org.eclipse.jetty.websocket.javax.tests.CoreServer; -import org.eclipse.jetty.websocket.javax.tests.WSEventTracker; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.websocket.ClientEndpoint; -import javax.websocket.ContainerProvider; -import javax.websocket.DecodeException; -import javax.websocket.Decoder; -import javax.websocket.EndpointConfig; -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.WebSocketContainer; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; @@ -47,8 +31,25 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.DecodeException; +import javax.websocket.Decoder; +import javax.websocket.EndpointConfig; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; + +import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.websocket.core.FrameHandler; +import org.eclipse.jetty.websocket.core.MessageHandler; +import org.eclipse.jetty.websocket.core.server.Negotiation; +import org.eclipse.jetty.websocket.javax.tests.CoreServer; +import org.eclipse.jetty.websocket.javax.tests.WSEventTracker; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; public class DecoderReaderManySmallTest { diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java index ff925776672..5b9085c3a83 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/sockets/IdleTimeoutOnOpenSocket.java @@ -18,11 +18,14 @@ package org.eclipse.jetty.websocket.javax.tests.server.sockets; +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 { @@ -37,4 +40,11 @@ public class IdleTimeoutOnOpenSocket { return msg; } + + @OnError + public void onError(Throwable cause) + { + if (!(cause instanceof WebSocketTimeoutException)) + throw new RuntimeException(cause); + } } diff --git a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java index e7b94df339e..d9173bce8aa 100644 --- a/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java +++ b/jetty-websocket/jetty-websocket-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java @@ -18,6 +18,23 @@ package org.eclipse.jetty.websocket.common; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.lang.annotation.Annotation; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.nio.ByteBuffer; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; + import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.websocket.api.InvalidWebSocketException; import org.eclipse.jetty.websocket.api.Session; @@ -46,24 +63,21 @@ import org.eclipse.jetty.websocket.common.message.StringMessageSink; import org.eclipse.jetty.websocket.common.util.ReflectUtils; import org.eclipse.jetty.websocket.core.Frame; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.nio.ByteBuffer; -import java.time.Duration; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; - /** + * Factory to create {@link JettyWebSocketFrameHandler} instances suitable for + * use with jetty-native websocket API. + *

+ * Will create a {@link FrameHandler} suitable for use with classes/objects that: + *

+ * */ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle { 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 d7cf3d9ee3f..47bbd03d4e6 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 @@ -18,7 +18,14 @@ package org.eclipse.jetty.websocket.server; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandlerFactory; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -28,18 +35,15 @@ import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import javax.servlet.ServletContext; - public class JettyServerFrameHandlerFactory extends JettyWebSocketFrameHandlerFactory implements FrameHandlerFactory, LifeCycle.Listener { public static JettyServerFrameHandlerFactory ensureFactory(ServletContext servletContext) + throws ServletException { - ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); + ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "Jetty Websocket"); + JettyServerFrameHandlerFactory factory = contextHandler.getBean(JettyServerFrameHandlerFactory.class); if (factory == null) { diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java index f079e490ce8..fc49b0fa6b2 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java @@ -18,14 +18,19 @@ package org.eclipse.jetty.websocket.servlet; +import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; + import java.io.IOException; import java.net.URISyntaxException; -import java.util.EnumSet; import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.eclipse.jetty.http.pathmap.MappedResource; import org.eclipse.jetty.http.pathmap.PathMappings; import org.eclipse.jetty.http.pathmap.PathSpec; @@ -36,9 +41,6 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.LifeCycle; @@ -50,18 +52,6 @@ import org.eclipse.jetty.websocket.core.server.Handshaker; import org.eclipse.jetty.websocket.core.server.Negotiation; import org.eclipse.jetty.websocket.core.server.WebSocketNegotiator; -import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; - -import javax.servlet.DispatcherType; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - /** * Mapping of pathSpec to a tupple of {@link WebSocketCreator}, {@link FrameHandlerFactory} and * {@link org.eclipse.jetty.websocket.core.FrameHandler.Customizer}. @@ -119,8 +109,11 @@ public class WebSocketMapping implements Dumpable, LifeCycle.Listener { ContextHandler contextHandler = (ContextHandler) context; WebSocketMapping mapping = contextHandler.getBean(WebSocketMapping.class); - if (mapping == null) + if (mapping == this) + { contextHandler.removeBean(mapping); + mappings.reset(); + } } /** 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 46f4a510f15..394688689f3 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 @@ -29,6 +29,7 @@ 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; @@ -153,10 +154,9 @@ public abstract class WebSocketServlet extends HttpServlet protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - // Typically this servlet is used together with the WebSocketUpgradeFilter, + // Often this servlet is used together with the WebSocketUpgradeFilter, // so upgrade requests will normally be upgraded by the filter. But we // can do it here as well if for some reason the filter did not match. - if (mapping.upgrade(req, resp, null)) return; @@ -256,7 +256,7 @@ public abstract class WebSocketServlet extends HttpServlet { // TODO a bit fragile. This code knows that only the JettyFHF is added directly as a been ServletContext servletContext = getServletContext(); - ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); + ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "WebSocketServlet"); FrameHandlerFactory frameHandlerFactory = contextHandler.getBean(FrameHandlerFactory.class); if (frameHandlerFactory==null)