From a205fb3aae65f9cd6721def40bc5956b04bfa9e4 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 20 Jan 2017 09:54:33 +0100 Subject: [PATCH 1/2] Fixes #1276 - Remove org.eclipse.jetty.websocket.server.WebSocketServerFactory from SPI. --- jetty-websocket/websocket-server/pom.xml | 31 ++++++------------- ....websocket.servlet.WebSocketServletFactory | 1 - jetty-websocket/websocket-servlet/pom.xml | 1 - 3 files changed, 10 insertions(+), 23 deletions(-) delete mode 100644 jetty-websocket/websocket-server/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.servlet.WebSocketServletFactory diff --git a/jetty-websocket/websocket-server/pom.xml b/jetty-websocket/websocket-server/pom.xml index 8c1ab4f30c6..732049eca80 100644 --- a/jetty-websocket/websocket-server/pom.xml +++ b/jetty-websocket/websocket-server/pom.xml @@ -16,28 +16,17 @@ - - org.apache.felix - maven-bundle-plugin - true - - - osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)" - osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory - - - - org.apache.maven.plugins - maven-jar-plugin - - - test-jar - - test-jar - - - + org.apache.maven.plugins + maven-jar-plugin + + + test-jar + + test-jar + + + 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-servlet/pom.xml b/jetty-websocket/websocket-servlet/pom.xml index f1abb48ae65..385bd707c45 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)" From 51f68dc57e06fb439ae690212bd93a4d6d451a16 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 20 Jan 2017 11:34:29 +0100 Subject: [PATCH 2/2] Issue #1229 - ClassLoader constraint issue when using NativeWebSocketConfiguration with WEB-INF/lib/jetty-http.jar present. Introduced String-based APIs to specify mappings, to avoid the classloader issue. --- .../jetty/http/pathmap/RegexPathSpec.java | 4 +- .../jetty/http/pathmap/ServletPathSpec.java | 5 +- .../jsr356/server/ServerContainer.java | 3 +- .../WebSocketServerContainerInitializer.java | 5 +- .../websocket/jsr356/server/DummyCreator.java | 20 +++-- .../server/MappedWebSocketCreator.java | 40 +++++++-- .../server/NativeWebSocketConfiguration.java | 85 ++++++++++++++++++- .../server/WebSocketUpgradeFilter.java | 18 +++- .../WebSocketUpgradeHandlerWrapper.java | 18 +++- .../server/InfoContextAttributeListener.java | 3 +- .../websocket/server/InfoContextListener.java | 3 +- .../jetty/websocket/server/InfoServlet.java | 3 +- .../websocket/server/WebSocketCloseTest.java | 19 +++-- .../server/WebSocketUpgradeFilterTest.java | 17 ++-- .../resources/wsuf-config-via-listener.xml | 38 +++++---- .../wsuf-config-via-servlet-init.xml | 42 ++++----- 16 files changed, 236 insertions(+), 87 deletions(-) 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 33389093e72..8daeaa7599b 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 @@ -24,11 +24,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 7e9638128ed..0052d646afc 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 @@ -25,7 +25,6 @@ import javax.websocket.Endpoint; 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.events.EventDriverFactory; @@ -80,7 +79,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket. public void addEndpoint(ServerEndpointMetadata metadata) throws DeploymentException { JsrCreator creator = new JsrCreator(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 942ae78aaad..dcfc92bfe01 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 @@ -79,7 +79,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) { @@ -115,6 +115,8 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit // Create Filter if(isEnabledViaContext(context.getServletContext(), ADD_DYNAMIC_FILTER_KEY, true)) { + if (LOG.isDebugEnabled()) + LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName()); WebSocketUpgradeFilter.configureContext(context); NativeWebSocketServletContainerInitializer.getDefaultFrom(context.getServletContext()); } @@ -136,6 +138,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 index 50aaa0a9c64..e8e65a62e9a 100644 --- 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 @@ -18,16 +18,20 @@ package org.eclipse.jetty.websocket.jsr356.server; -import org.eclipse.jetty.http.pathmap.MappedResource; import org.eclipse.jetty.websocket.server.MappedWebSocketCreator; import org.eclipse.jetty.websocket.server.pathmap.PathMappings; -import org.eclipse.jetty.websocket.server.pathmap.PathSpec; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; public class DummyCreator implements MappedWebSocketCreator { @Override - public void addMapping(PathSpec spec, WebSocketCreator creator) + public void addMapping(String spec, WebSocketCreator creator) + { + /* do nothing */ + } + + @Override + public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec, WebSocketCreator creator) { /* do nothing */ } @@ -43,10 +47,16 @@ public class DummyCreator implements MappedWebSocketCreator { return null; } - + @Override - public MappedResource getMapping(String target) + public WebSocketCreator getMapping(String spec) { return null; } + + @Override + public boolean removeMapping(String spec) + { + return false; + } } 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 4a80e31a821..37d4f633319 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,9 +18,7 @@ package org.eclipse.jetty.websocket.server; -import org.eclipse.jetty.http.pathmap.MappedResource; import org.eclipse.jetty.websocket.server.pathmap.PathMappings; -import org.eclipse.jetty.websocket.server.pathmap.PathSpec; import org.eclipse.jetty.websocket.servlet.WebSocketCreator; /** @@ -28,6 +26,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. * @@ -37,7 +54,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. @@ -58,11 +75,18 @@ public interface MappedWebSocketCreator PathMappings getMappings(); /** - * 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 541beb7cab3..6ea8d25a5a0 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,12 +19,14 @@ package org.eclipse.jetty.websocket.server; import java.io.IOException; +import java.util.Iterator; import org.eclipse.jetty.http.pathmap.MappedResource; 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; @@ -39,7 +41,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<>(); @@ -123,7 +125,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) @@ -168,4 +170,83 @@ public class NativeWebSocketConfiguration extends ContainerLifeCycle implements } }); } + + @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); + } + + @Override + public org.eclipse.jetty.websocket.server.pathmap.PathMappings getMappings() + { + throw new IllegalStateException("Access to PathMappings cannot be supported. See alternative API in javadoc for " + + MappedWebSocketCreator.class.getName()); + } } 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 5e628ca933c..6a5c4bfc2a0 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 @@ -142,7 +142,19 @@ public class WebSocketUpgradeFilter extends AbstractLifeCycle implements Filter, { 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() { @@ -274,9 +286,9 @@ public class WebSocketUpgradeFilter extends AbstractLifeCycle implements Filter, } @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 0e0a83d9f7d..290b2326c39 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 @@ -65,7 +65,19 @@ public class WebSocketUpgradeHandlerWrapper extends HandlerWrapper implements Ma { 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 org.eclipse.jetty.websocket.server.pathmap.PathMappings getMappings() { @@ -74,9 +86,9 @@ public class WebSocketUpgradeHandlerWrapper extends HandlerWrapper implements Ma } @Override - public MappedResource getMapping(String target) + public WebSocketCreator getMapping(String target) { - return this.configuration.getMatch(target); + return configuration.getMapping(target); } @Override 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 d347c789392..b3037617731 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(); 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 c3183083014..50033c009ce 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 @@ -18,9 +18,6 @@ package org.eclipse.jetty.websocket.server; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -51,6 +48,10 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + /** * Tests various close scenarios */ @@ -222,13 +223,13 @@ public class WebSocketCloseTest try (BlockheadClient 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); @@ -238,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)); } } @@ -255,14 +256,14 @@ public class WebSocketCloseTest try (BlockheadClient client = new BlockheadClient(server.getServerUri())) { client.setProtocols("fastfail"); - client.setTimeout(1,TimeUnit.SECONDS); + client.setTimeout(5,TimeUnit.SECONDS); try (StacklessLogging scope = new StacklessLogging(AbstractEventDriver.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); @@ -271,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 8c5d08e3f1f..4976cb56122 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.ServletContextHandler; @@ -48,6 +43,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 { @@ -59,7 +58,7 @@ public class WebSocketUpgradeFilterTest @Parameterized.Parameters(name = "{0}") public static List data() { - /** + /* * Case A: * 1. embedded-jetty WSUF.configureContext() / app-ws configured at ... * a. during server construction / before server.start (might not be possible with current impl, native SCI not run (yet)) @@ -109,7 +108,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); server.start(); return server; @@ -138,7 +137,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); server.start(); @@ -165,7 +164,7 @@ public class WebSocketUpgradeFilterTest NativeWebSocketConfiguration configuration = new NativeWebSocketConfiguration(); configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024); - configuration.addMapping(new ServletPathSpec("/info/*"), infoCreator); + configuration.addMapping("/info/*", infoCreator); context.getServletContext().setAttribute(NativeWebSocketConfiguration.class.getName(), configuration); server.start(); 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 + /* +