You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/02/15 14:41:14 UTC

svn commit: r378007 - in /incubator/servicemix/trunk/servicemix-http/src: main/java/org/apache/servicemix/http/ServerManager.java test/java/org/apache/servicemix/http/ServerManagerTest.java

Author: gnodet
Date: Wed Feb 15 05:41:14 2006
New Revision: 378007

URL: http://svn.apache.org/viewcvs?rev=378007&view=rev
Log:
Throw an exception for overlapping contexts

Modified:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java?rev=378007&r1=378006&r2=378007&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java Wed Feb 15 05:41:14 2006
@@ -73,6 +73,20 @@
         if (!path.startsWith("/")) {
             path = "/" + path;
         }
+        // Check that context does not exist yet
+        Handler[] handlers = server.getHandlers();
+        if (handlers != null) {
+            for (int i = 0; i < handlers.length; i++) {
+                if (handlers[i] instanceof ContextHandler) {
+                    ContextHandler h = (ContextHandler) handlers[i];
+                    if (h.getContextPath().startsWith(path) ||
+                        path.startsWith(h.getContextPath())) {
+                        throw new Exception("The requested context for path '" + path + "' overlaps with an existing context for path: '" + h.getContextPath() + "'");
+                    }
+                }
+            }
+        }
+        // Create context
         ContextHandler context = new ContextHandler();
         context.setContextPath(path);
         ServletHolder holder = new ServletHolder();
@@ -87,7 +101,6 @@
         context.setHandler(handler);
         context.setAttribute("processor", processor);
         // add context
-        Handler[] handlers = server.getHandlers();
         handlers = (Handler[]) add(handlers, context, Handler.class);
         server.setHandlers(handlers);
         return context;

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java?rev=378007&r1=378006&r2=378007&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java Wed Feb 15 05:41:14 2006
@@ -81,6 +81,34 @@
         request("http://localhost:8193/echo", null);
     }
     
+    public void testOverlappingPath() throws Exception {
+        server.init();
+        server.start();
+        
+        server.createContext("http://localhost:8192/Service1/test1", new TestHttpProcessor());
+        
+        try {
+            server.createContext("http://localhost:8192/Service1/test1", new TestHttpProcessor());
+            fail("Contexts are overlapping, an exception should have been thrown");
+        } catch (Exception e) {
+            // ok
+        }
+        
+        try {
+            server.createContext("http://localhost:8192/Service1/test1/test", new TestHttpProcessor());
+            fail("Contexts are overlapping, an exception should have been thrown");
+        } catch (Exception e) {
+            // ok
+        }
+        
+        try {
+            server.createContext("http://localhost:8192/Service1", new TestHttpProcessor());
+            fail("Contexts are overlapping, an exception should have been thrown");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+    
     public void testSetMaxThreads() throws Exception {
         int maxThreads = 512;
         configuration.setJettyThreadPoolSize(maxThreads);