FELIX-4778 : Implement ordering of ServletContextHelper

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1656463 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java
index c1e93e7..a2f4138 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java
@@ -77,29 +77,33 @@
     @Override
     public int compareTo(final PerContextHandlerRegistry other)
     {
-        if (other.ranking == this.ranking)
-        {
-            if (other.serviceId == this.serviceId)
+        final int result = other.prefixPath.compareTo(this.prefixPath);
+        if ( result == 0 ) {
+            if (other.ranking == this.ranking)
             {
-                return 0;
-            }
-            // service id might be negative, we have to change the behavior in that case
-            if ( this.serviceId < 0 )
-            {
-                if ( other.serviceId > 0 )
+                if (other.serviceId == this.serviceId)
+                {
+                    return 0;
+                }
+                // service id might be negative, we have to change the behavior in that case
+                if ( this.serviceId < 0 )
+                {
+                    if ( other.serviceId > 0 )
+                    {
+                        return -1;
+                    }
+                    return other.serviceId < this.serviceId ? -1 : 1;
+                }
+                if ( other.serviceId < 0 )
                 {
                     return -1;
                 }
-                return other.serviceId < this.serviceId ? -1 : 1;
+                return other.serviceId > this.serviceId ? -1 : 1;
             }
-            if ( other.serviceId < 0 )
-            {
-                return -1;
-            }
-            return other.serviceId > this.serviceId ? -1 : 1;
-        }
 
-        return (other.ranking > this.ranking) ? 1 : -1;
+            return (other.ranking > this.ranking) ? 1 : -1;
+        }
+        return result;
     }
 
     /**