FELIX-4888 : ServletHandler's are not sorted by longest matching path. DTO handling (WiP)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1680296 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
index 87a1e9c..f0044b5 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
@@ -747,7 +748,15 @@
{
final FailedDTOHolder failedDTOHolder = new FailedDTOHolder();
- final Collection<ServletContextDTO> contextDTOs = new TreeSet<ServletContextDTO>();
+ final Collection<ServletContextDTO> contextDTOs = new TreeSet<ServletContextDTO>(new Comparator<ServletContextDTO>() {
+
+ @Override
+ public int compare(ServletContextDTO o1, ServletContextDTO o2) {
+ // Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
+ int reverseOrder = ( o1.serviceId >= 0 && o2.serviceId >= 0 ) ? 1 : -1;
+ return reverseOrder * Long.compare(o1.serviceId, o2.serviceId);
+ }
+ });
synchronized ( this.contextMap )
{