diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/RegexPathSpec.java b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/RegexPathSpec.java index b5db23bf6c2..630791c538b 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/RegexPathSpec.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/RegexPathSpec.java @@ -33,10 +33,12 @@ public class RegexPathSpec extends PathSpec public RegexPathSpec(String regex) { super.pathSpec = regex; - boolean inGrouping = false; + if (regex.startsWith("regex|")) + super.pathSpec = regex.substring("regex|".length()); this.pathDepth = 0; this.specLength = pathSpec.length(); // build up a simple signature we can use to identify the grouping + boolean inGrouping = false; StringBuilder signature = new StringBuilder(); for (char c : pathSpec.toCharArray()) { diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/ServletPathSpec.java b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/ServletPathSpec.java index 5d6549a22df..07a4b499aff 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/ServletPathSpec.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/ServletPathSpec.java @@ -40,11 +40,12 @@ public class ServletPathSpec extends PathSpec public ServletPathSpec(String servletPathSpec) { - super(); + if (servletPathSpec.startsWith("servlet|")) + servletPathSpec = servletPathSpec.substring("servlet|".length()); assertValidServletPathSpec(servletPathSpec); // The Root Path Spec - if ((servletPathSpec == null) || (servletPathSpec.length() == 0)) + if (servletPathSpec.length() == 0) { super.pathSpec = ""; super.pathDepth = -1; // force this to be at the end of the sort order diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java index 60a09b8823a..a6a130a7964 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java @@ -30,7 +30,6 @@ import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; -import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.common.WebSocketSession; @@ -101,7 +100,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket. private void addEndpoint(ServerEndpointMetadata metadata) throws DeploymentException { JsrCreator creator = new JsrCreator(this,metadata,this.configuration.getFactory().getExtensionFactory()); - this.configuration.addMapping(new UriTemplatePathSpec(metadata.getPath()),creator); + this.configuration.addMapping("uri-template|" + metadata.getPath(), creator); } @Override diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java index b6faeffcb4f..2e3e8563851 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java @@ -109,7 +109,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit } // Next, try attribute on context - Object enable = context.getAttribute(ENABLE_KEY); + Object enable = context.getAttribute(keyName); if(enable != null) { @@ -148,6 +148,8 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI"; if(context.getAttribute(instanceKey) == null) { + if (LOG.isDebugEnabled()) + LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName()); WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context); context.setAttribute(instanceKey, wsuf); } @@ -170,6 +172,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit { if(!isEnabledViaContext(context, ENABLE_KEY, true)) { + LOG.info("JSR-356 is disabled by configuration"); return; } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DummyCreator.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DummyCreator.java deleted file mode 100644 index 17c23f5aad0..00000000000 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DummyCreator.java +++ /dev/null @@ -1,45 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2017 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.jsr356.server; - -import org.eclipse.jetty.http.pathmap.MappedResource; -import org.eclipse.jetty.http.pathmap.PathSpec; -import org.eclipse.jetty.websocket.server.MappedWebSocketCreator; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; - -public class DummyCreator implements MappedWebSocketCreator -{ - @Override - public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator) - { - /* do nothing */ - } - - @Override - public void addMapping(PathSpec spec, WebSocketCreator creator) - { - /* do nothing */ - } - - @Override - public MappedResource getMapping(String target) - { - return null; - } -} diff --git a/jetty-websocket/websocket-server/pom.xml b/jetty-websocket/websocket-server/pom.xml index 16e1eacd55d..153e56edd6f 100644 --- a/jetty-websocket/websocket-server/pom.xml +++ b/jetty-websocket/websocket-server/pom.xml @@ -26,7 +26,7 @@ osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)" - osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory,org.eclipse.jetty.webapp.Configuration + osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.webapp.Configuration diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/MappedWebSocketCreator.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/MappedWebSocketCreator.java index 0c7812073fe..6b264233e37 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/MappedWebSocketCreator.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/MappedWebSocketCreator.java @@ -18,8 +18,6 @@ package org.eclipse.jetty.websocket.server; -import org.eclipse.jetty.http.pathmap.MappedResource; -import org.eclipse.jetty.websocket.server.pathmap.PathSpec; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; /** @@ -27,6 +25,25 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator; */ public interface MappedWebSocketCreator { + /** + * Add a mapping, of a pathspec to a WebSocketCreator. + *

+ * Recognized Path Spec syntaxes + *

+ *
+ *
/path/to or / or *.ext or servlet|{spec}
+ *
Servlet Syntax
+ *
^{spec} or regex|{spec}
+ *
Regex Syntax
+ *
uri-template|{spec}
+ *
URI Template (see JSR356 and RFC6570 level 1)
+ *
+ * + * @param spec the path spec to use. + * @param creator the websocket creator for this specific mapping + */ + void addMapping(String spec, WebSocketCreator creator); + /** * Add a mapping. * @@ -36,7 +53,7 @@ public interface MappedWebSocketCreator * (support classes moved to generic jetty-http project) */ @Deprecated - void addMapping(PathSpec spec, WebSocketCreator creator); + void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator); /** * Add a mapping. @@ -48,11 +65,19 @@ public interface MappedWebSocketCreator void addMapping(org.eclipse.jetty.http.pathmap.PathSpec spec, WebSocketCreator creator); /** - * Get specific MappedResource for associated target. + /** + * Returns the creator for the given path spec. * - * @param target the target to get mapping for - * @return the MappedResource for the target, or null if no match. - * @since 9.2.20 + * @param spec @param spec the spec to test for (using the same spec syntax as seen in {@link #addMapping(String, WebSocketCreator)}) + * @return the websocket creator if path spec exists, or null */ - MappedResource getMapping(String target); + WebSocketCreator getMapping(String spec); + + /** + * Removes the mapping based on the given path spec. + * + * @param spec the path spec to remove (using the same spec syntax as seen in {@link #addMapping(String, WebSocketCreator)}) + * @return true if underlying mapping were altered, false otherwise + */ + boolean removeMapping(String spec); } diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketConfiguration.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketConfiguration.java index 31bb36f37fa..fe0b9710fc3 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketConfiguration.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketConfiguration.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.server; import java.io.IOException; +import java.util.Iterator; import javax.servlet.ServletContext; @@ -27,6 +28,7 @@ import org.eclipse.jetty.http.pathmap.PathMappings; import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.http.pathmap.RegexPathSpec; import org.eclipse.jetty.http.pathmap.ServletPathSpec; +import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.websocket.api.WebSocketException; @@ -41,7 +43,7 @@ import org.eclipse.jetty.websocket.servlet.WebSocketCreator; * Only applicable if using {@link WebSocketUpgradeFilter} *

*/ -public class NativeWebSocketConfiguration extends ContainerLifeCycle implements Dumpable +public class NativeWebSocketConfiguration extends ContainerLifeCycle implements MappedWebSocketCreator, Dumpable { private final WebSocketServerFactory factory; private final PathMappings mappings = new PathMappings<>(); @@ -135,7 +137,7 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements * * @param spec the pathspec to respond on * @param creator the websocket creator to activate on the provided mapping - * @deprecated use {@link #addMapping(PathSpec, Class)} instead. + * @deprecated use {@link #addMapping(PathSpec, WebSocketCreator)} instead. */ @Deprecated public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator) @@ -164,23 +166,92 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements */ public void addMapping(PathSpec pathSpec, final Class endpointClass) { - mappings.put(pathSpec, new WebSocketCreator() + mappings.put(pathSpec, (req, resp) -> { - @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) + try { - try - { - return endpointClass.newInstance(); - } - catch (InstantiationException | IllegalAccessException e) - { - throw new WebSocketException("Unable to create instance of " + endpointClass.getName(), e); - } + return endpointClass.newInstance(); + } + catch (InstantiationException | IllegalAccessException e) + { + throw new WebSocketException("Unable to create instance of " + endpointClass.getName(), e); } }); } + + @Override + public void addMapping(String rawspec, WebSocketCreator creator) + { + PathSpec spec = toPathSpec(rawspec); + addMapping(spec, creator); + } + + private PathSpec toPathSpec(String rawspec) + { + // Determine what kind of path spec we are working with + if (rawspec.charAt(0) == '/' || rawspec.startsWith("*.") || rawspec.startsWith("servlet|")) + { + return new ServletPathSpec(rawspec); + } + else if (rawspec.charAt(0) == '^' || rawspec.startsWith("regex|")) + { + return new RegexPathSpec(rawspec); + } + else if (rawspec.startsWith("uri-template|")) + { + return new UriTemplatePathSpec(rawspec.substring("uri-template|".length())); + } + + // TODO: add ability to load arbitrary jetty-http PathSpec implementation + // TODO: perhaps via "fully.qualified.class.name|spec" style syntax + + throw new IllegalArgumentException("Unrecognized path spec syntax [" + rawspec + "]"); + } + + @Override + public WebSocketCreator getMapping(String rawspec) + { + PathSpec pathSpec = toPathSpec(rawspec); + for (MappedResource mapping : mappings) + { + if (mapping.getPathSpec().equals(pathSpec)) + return mapping.getResource(); + } + return null; + } + + @Override + public boolean removeMapping(String rawspec) + { + PathSpec pathSpec = toPathSpec(rawspec); + boolean removed = false; + for (Iterator> iterator = mappings.iterator(); iterator.hasNext(); ) + { + MappedResource mapping = iterator.next(); + if (mapping.getPathSpec().equals(pathSpec)) + { + iterator.remove(); + removed = true; + } + } + return removed; + } + + /** + * Manually add a WebSocket mapping. + * + * @param rawspec the pathspec to map to (see {@link MappedWebSocketCreator#addMapping(String, WebSocketCreator)} for syntax details) + * @param endpointClass the endpoint class to use for new upgrade requests on the provided + * pathspec (can be an {@link org.eclipse.jetty.websocket.api.annotations.WebSocket} annotated + * POJO, or implementing {@link org.eclipse.jetty.websocket.api.WebSocketListener}) + */ + public void addMapping(String rawspec, final Class endpointClass) + { + PathSpec pathSpec = toPathSpec(rawspec); + addMapping(pathSpec, endpointClass); + } + private class PersistedWebSocketCreator implements WebSocketCreator { private final WebSocketCreator delegate; diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java index 94114927add..55bd7521a26 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java @@ -145,6 +145,18 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D configuration.addMapping(spec, creator); } + @Override + public void addMapping(String spec, WebSocketCreator creator) + { + configuration.addMapping(spec, creator); + } + + @Override + public boolean removeMapping(String spec) + { + return configuration.removeMapping(spec); + } + @Override public void destroy() { @@ -279,9 +291,9 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D } @Override - public MappedResource getMapping(String target) + public WebSocketCreator getMapping(String target) { - return getConfiguration().getMatch(target); + return getConfiguration().getMapping(target); } @Override diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeHandlerWrapper.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeHandlerWrapper.java index 06040f75e56..d204ed525ad 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeHandlerWrapper.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeHandlerWrapper.java @@ -66,11 +66,23 @@ public class WebSocketUpgradeHandlerWrapper extends HandlerWrapper implements Ma { configuration.addMapping(spec, creator); } - + @Override - public MappedResource getMapping(String target) + public void addMapping(String spec, WebSocketCreator creator) { - return this.configuration.getMatch(target); + configuration.addMapping(spec, creator); + } + + @Override + public boolean removeMapping(String spec) + { + return configuration.removeMapping(spec); + } + + @Override + public WebSocketCreator getMapping(String target) + { + return configuration.getMapping(target); } @Override diff --git a/jetty-websocket/websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.servlet.WebSocketServletFactory b/jetty-websocket/websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.servlet.WebSocketServletFactory deleted file mode 100644 index a5341c906a0..00000000000 --- a/jetty-websocket/websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.servlet.WebSocketServletFactory +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.jetty.websocket.server.WebSocketServerFactory \ No newline at end of file diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAltAttributeListener.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAltAttributeListener.java index 08683c9f7c6..e87416308f9 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAltAttributeListener.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAltAttributeListener.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -35,7 +34,7 @@ public class InfoContextAltAttributeListener implements WebSocketCreator, Servle { NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), this); + configuration.addMapping("/info/*", this); sce.getServletContext().setAttribute(ATTR, configuration); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAttributeListener.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAttributeListener.java index e3ae273cd42..292937b48db 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAttributeListener.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextAttributeListener.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -33,7 +32,7 @@ public class InfoContextAttributeListener implements WebSocketCreator, ServletCo { NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) sce.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), this); + configuration.addMapping("/info/*", this); } @Override diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextListener.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextListener.java index f082e68373e..cbe8c5133a2 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextListener.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoContextListener.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.server; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -33,7 +32,7 @@ public class InfoContextListener implements WebSocketCreator, ServletContextList { NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(sce.getServletContext()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), this); + configuration.addMapping("/info/*", this); sce.getServletContext().setAttribute(NativeWebSocketConfiguration.class.getName(), configuration); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoServlet.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoServlet.java index 60c499a3b2c..6dc0f3e96ac 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoServlet.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/InfoServlet.java @@ -23,7 +23,6 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; -import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; @@ -42,6 +41,6 @@ public class InfoServlet extends HttpServlet implements WebSocketCreator ServletContext context = config.getServletContext(); NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(NativeWebSocketConfiguration.class.getName()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), this); + configuration.addMapping("/info/*", this); } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java index 4fd35fa3ac6..d1995aecb69 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketCloseTest.java @@ -223,13 +223,13 @@ public class WebSocketCloseTest try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) { client.setProtocols("fastclose"); - client.setTimeout(1,TimeUnit.SECONDS); + client.setTimeout(5,TimeUnit.SECONDS); client.connect(); client.sendStandardRequest(); client.expectUpgradeResponse(); // Verify that client got close frame - EventQueue frames = client.readFrames(1,1,TimeUnit.SECONDS); + EventQueue frames = client.readFrames(1,5,TimeUnit.SECONDS); WebSocketFrame frame = frames.poll(); assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE)); CloseInfo close = new CloseInfo(frame); @@ -239,7 +239,7 @@ public class WebSocketCloseTest client.write(close.asFrame()); // respond with close // ensure server socket got close event - assertThat("Fast Close Latch",closeSocket.closeLatch.await(1,TimeUnit.SECONDS),is(true)); + assertThat("Fast Close Latch",closeSocket.closeLatch.await(5,TimeUnit.SECONDS),is(true)); assertThat("Fast Close.statusCode",closeSocket.closeStatusCode,is(StatusCode.NORMAL)); } } @@ -256,14 +256,14 @@ public class WebSocketCloseTest try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) { client.setProtocols("fastfail"); - client.setTimeout(1,TimeUnit.SECONDS); + client.setTimeout(5,TimeUnit.SECONDS); try (StacklessLogging scope = new StacklessLogging(FastFailSocket.class, WebSocketSession.class)) { client.connect(); client.sendStandardRequest(); client.expectUpgradeResponse(); - EventQueue frames = client.readFrames(1,1,TimeUnit.SECONDS); + EventQueue frames = client.readFrames(1,5,TimeUnit.SECONDS); WebSocketFrame frame = frames.poll(); assertThat("frames[0].opcode",frame.getOpCode(),is(OpCode.CLOSE)); CloseInfo close = new CloseInfo(frame); @@ -272,7 +272,7 @@ public class WebSocketCloseTest client.write(close.asFrame()); // respond with close // ensure server socket got close event - assertThat("Fast Fail Latch",closeSocket.closeLatch.await(1,TimeUnit.SECONDS),is(true)); + assertThat("Fast Fail Latch",closeSocket.closeLatch.await(5,TimeUnit.SECONDS),is(true)); assertThat("Fast Fail.statusCode",closeSocket.closeStatusCode,is(StatusCode.SERVER_ERROR)); assertThat("Fast Fail.errors",closeSocket.errors.size(),is(1)); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java index 94c74ddd388..9e47fa2a883 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilterTest.java @@ -18,10 +18,6 @@ package org.eclipse.jetty.websocket.server; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - import java.io.File; import java.net.URI; import java.util.ArrayList; @@ -31,7 +27,6 @@ import java.util.concurrent.TimeUnit; import javax.servlet.DispatcherType; -import org.eclipse.jetty.http.pathmap.ServletPathSpec; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.FilterHolder; @@ -47,6 +42,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + @RunWith(Parameterized.class) public class WebSocketUpgradeFilterTest { @@ -79,7 +78,7 @@ public class WebSocketUpgradeFilterTest // direct configuration via WSUF wsuf.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - wsuf.addMapping(new ServletPathSpec("/info/*"), infoCreator); + wsuf.addMapping("/info/*", infoCreator); server1.start(); return server1; @@ -104,7 +103,7 @@ public class WebSocketUpgradeFilterTest NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName()); assertThat("NativeWebSocketConfiguration", configuration, notNullValue()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator); + configuration.addMapping("/info/*", infoCreator); server12.start(); @@ -127,7 +126,7 @@ public class WebSocketUpgradeFilterTest NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator); + configuration.addMapping("/info/*", infoCreator); context.setAttribute(NativeWebSocketConfiguration.class.getName(), configuration); server13.start(); @@ -153,7 +152,7 @@ public class WebSocketUpgradeFilterTest NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(context.getServletContext()); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator); + configuration.addMapping("/info/*", infoCreator); context.addBean(configuration, true); FilterHolder wsufHolder = new FilterHolder(new WebSocketUpgradeFilter(configuration)); diff --git a/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-listener.xml b/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-listener.xml index 8e75569ae23..986a4c20534 100644 --- a/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-listener.xml +++ b/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-listener.xml @@ -1,22 +1,26 @@ - + - - org.eclipse.jetty.websocket.server.InfoContextAttributeListener - + + + org.eclipse.jetty.websocket.jsr356 + false + - - wsuf - org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter - + + org.eclipse.jetty.websocket.server.InfoContextAttributeListener + - - wsuf - /* - + + wsuf + org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter + + + + wsuf + /* + diff --git a/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-servlet-init.xml b/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-servlet-init.xml index a2a082f53cd..a82122a36e0 100644 --- a/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-servlet-init.xml +++ b/jetty-websocket/websocket-server/src/test/resources/wsuf-config-via-servlet-init.xml @@ -1,24 +1,28 @@ - + - - info-servlet - org.eclipse.jetty.websocket.server.InfoServlet - 1 - + + + org.eclipse.jetty.websocket.jsr356 + false + - - wsuf - org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter - + + info-servlet + org.eclipse.jetty.websocket.server.InfoServlet + 1 + - - wsuf - /* - + + wsuf + org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter + + + + wsuf + /* + diff --git a/jetty-websocket/websocket-servlet/pom.xml b/jetty-websocket/websocket-servlet/pom.xml index 0172eebf4a8..bd1edd7605c 100644 --- a/jetty-websocket/websocket-servlet/pom.xml +++ b/jetty-websocket/websocket-servlet/pom.xml @@ -24,7 +24,6 @@ Websocket Servlet Interface org.eclipse.jetty.websocket.server.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}",org.eclipse.jetty.websocket.server.pathmap.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}" - osgi.serviceloader; filter:="(osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory)";cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"