JSR-356: adding example of mixed pathspec
This commit is contained in:
parent
df77322ff1
commit
754dfa979e
|
@ -18,9 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.jsr356.server.pathmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.eclipse.jetty.websocket.jsr356.server.pathmap.PathMappings.MappedResource;
|
||||
|
||||
|
@ -109,7 +110,7 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>
|
|||
}
|
||||
}
|
||||
|
||||
private List<MappedResource<E>> mappings = new CopyOnWriteArrayList<MappedResource<E>>();
|
||||
private List<MappedResource<E>> mappings = new ArrayList<MappedResource<E>>();
|
||||
private MappedResource<E> defaultResource = null;
|
||||
|
||||
public MappedResource<E> getMatch(String path)
|
||||
|
@ -141,5 +142,6 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>
|
|||
}
|
||||
// TODO: warning on replacement of existing mapping?
|
||||
mappings.add(entry);
|
||||
Collections.sort(mappings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,43 @@ public class PathMappingsTest
|
|||
Assert.assertEquals(msg,expectedValue,actualMatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the match order rules with a mixed Servlet and WebSocket path specs
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>Exact match</li>
|
||||
* <li>Longest prefix match</li>
|
||||
* <li>Longest suffix match</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Test
|
||||
public void testMixedMatchOrder()
|
||||
{
|
||||
PathMappings<String> p = new PathMappings<>();
|
||||
|
||||
p.put(new ServletPathSpec("/"),"default");
|
||||
p.put(new ServletPathSpec("/animal/bird/*"),"birds");
|
||||
p.put(new ServletPathSpec("/animal/fish/*"),"fishes");
|
||||
p.put(new ServletPathSpec("/animal/*"),"animals");
|
||||
p.put(new WebSocketPathSpec("/animal/{type}/{name}/chat"),"animalChat");
|
||||
p.put(new WebSocketPathSpec("/animal/{type}/{name}/cam"),"animalCam");
|
||||
p.put(new WebSocketPathSpec("/entrance/cam"),"entranceCam");
|
||||
|
||||
for (MappedResource<String> res : p)
|
||||
{
|
||||
System.out.printf(" %s%n",res);
|
||||
}
|
||||
|
||||
assertMatch(p,"/animal/bird/eagle","birds");
|
||||
assertMatch(p,"/animal/fish/bass/sea","fishes");
|
||||
assertMatch(p,"/animal/peccary/javalina/evolution","animals");
|
||||
assertMatch(p,"/","default");
|
||||
assertMatch(p,"/animal/bird/eagle/chat","animalChat");
|
||||
assertMatch(p,"/animal/bird/penguin/chat","animalChat");
|
||||
assertMatch(p,"/animal/fish/trout/cam","animalCam");
|
||||
assertMatch(p,"/entrance/cam","entranceCam");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the match order rules imposed by the Servlet API.
|
||||
* <p>
|
||||
|
|
Loading…
Reference in New Issue