Author: markt
Date: Tue Jun 25 10:19:54 2013
New Revision: 1496400
URL: http://svn.apache.org/r1496400
Log:
WebSocket 1.0. Section 4.1.1
Deployment to duplicate paths is not permitted
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsServerContainer.java
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1496400&r1=1496399&r2=1496400&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
(original)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
Tue Jun 25 10:19:54 2013
@@ -15,6 +15,7 @@
sci.newInstance.fail=Failed to create an Endpoint instance of type [{0}]
serverContainer.configuratorFail=Failed to create configurator of type [{0}]
for POJO of type [{1}]
+serverContainer.duplicatePaths=Multiple Endpoints may not be deployed to using
the same path [{0}]
serverContainer.endpointDeploy=Endpoint class [{0}] deploying to path [{1}] in
ServletContext [{2}]
serverContainer.missingAnnotation=Cannot deploy POJO class [{0}] as it is not
annotated with @ServerEndpoint
serverContainer.missingEndpoint=An Endpoint instance has been request for path
[{0}] but no matching Endpoint class was found
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java?rev=1496400&r1=1496399&r2=1496400&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServerContainer.java
Tue Jun 25 10:19:54 2013
@@ -148,10 +148,19 @@ public class WsServerContainer extends W
TemplatePathMatchComparator.getInstance());
configTemplateMatchMap.put(key, templateMatches);
}
- templateMatches.add(new TemplatePathMatch(sec, uriTemplate));
+ if (!templateMatches.add(new TemplatePathMatch(sec, uriTemplate)))
{
+ // Duplicate uriTemplate;
+ throw new DeploymentException(
+ sm.getString("serverContainer.duplicatePaths", path));
+ }
} else {
// Exact match
- configExactMatchMap.put(path, sec);
+ ServerEndpointConfig old = configExactMatchMap.put(path, sec);
+ if (old != null) {
+ // Duplicate path mappings
+ throw new DeploymentException(
+ sm.getString("serverContainer.duplicatePaths", path));
+ }
}
}
Modified:
tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsServerContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsServerContainer.java?rev=1496400&r1=1496399&r2=1496400&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsServerContainer.java
(original)
+++
tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsServerContainer.java
Tue Jun 25 10:19:54 2013
@@ -112,4 +112,67 @@ public class TestWsServerContainer exten
Assert.assertEquals(configB, sc.findMapping("/b/d").getConfig());
}
+
+
+ @Test(expected = javax.websocket.DeploymentException.class)
+ public void testDuplicatePaths_01() throws Exception {
+ WsServerContainer sc = WsServerContainer.getServerContainer();
+ sc.setServletContext(new TesterServletContext());
+
+ ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/c").build();
+ ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/c").build();
+
+ sc.addEndpoint(configA);
+ sc.addEndpoint(configB);
+ }
+
+
+ @Test(expected = javax.websocket.DeploymentException.class)
+ public void testDuplicatePaths_02() throws Exception {
+ WsServerContainer sc = WsServerContainer.getServerContainer();
+ sc.setServletContext(new TesterServletContext());
+
+ ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/{var}").build();
+ ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/{var}").build();
+
+ sc.addEndpoint(configA);
+ sc.addEndpoint(configB);
+ }
+
+
+ @Test(expected = javax.websocket.DeploymentException.class)
+ public void testDuplicatePaths_03() throws Exception {
+ WsServerContainer sc = WsServerContainer.getServerContainer();
+ sc.setServletContext(new TesterServletContext());
+
+ ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/{var1}").build();
+ ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/{var2}").build();
+
+ sc.addEndpoint(configA);
+ sc.addEndpoint(configB);
+ }
+
+
+ @Test
+ public void testDuplicatePaths_04() throws Exception {
+ WsServerContainer sc = WsServerContainer.getServerContainer();
+ sc.setServletContext(new TesterServletContext());
+
+ ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/{var1}/{var2}").build();
+ ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
+ Object.class, "/a/b/{var2}").build();
+
+ sc.addEndpoint(configA);
+ sc.addEndpoint(configB);
+
+ Assert.assertEquals(configA, sc.findMapping("/a/x/y").getConfig());
+ Assert.assertEquals(configB, sc.findMapping("/a/b/y").getConfig());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]