mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-28 19:09:10 +00:00
Revert "482042 - New API, Allow customization of ServletHandler path mapping"
This reverts commit 77d4b54082f6789168ea7ef1523e8e1b924bb560.
This commit is contained in:
parent
6e0ad429d9
commit
4f9d785b46
@ -44,7 +44,6 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||||||
private static final Logger LOG = Log.getLogger(PathMappings.class);
|
private static final Logger LOG = Log.getLogger(PathMappings.class);
|
||||||
private List<MappedResource<E>> mappings = new ArrayList<MappedResource<E>>();
|
private List<MappedResource<E>> mappings = new ArrayList<MappedResource<E>>();
|
||||||
private MappedResource<E> defaultResource = null;
|
private MappedResource<E> defaultResource = null;
|
||||||
private MappedResource<E> rootResource = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String dump()
|
public String dump()
|
||||||
@ -106,11 +105,6 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||||||
|
|
||||||
public MappedResource<E> getMatch(String path)
|
public MappedResource<E> getMatch(String path)
|
||||||
{
|
{
|
||||||
if (path.equals("/") && rootResource != null)
|
|
||||||
{
|
|
||||||
return rootResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
int len = mappings.size();
|
int len = mappings.size();
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
@ -129,22 +123,14 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||||||
return mappings.iterator();
|
return mappings.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("incomplete-switch")
|
|
||||||
public void put(PathSpec pathSpec, E resource)
|
public void put(PathSpec pathSpec, E resource)
|
||||||
{
|
{
|
||||||
MappedResource<E> entry = new MappedResource<>(pathSpec,resource);
|
MappedResource<E> entry = new MappedResource<>(pathSpec,resource);
|
||||||
switch (pathSpec.group)
|
if (pathSpec.group == PathSpecGroup.DEFAULT)
|
||||||
{
|
{
|
||||||
case DEFAULT:
|
defaultResource = entry;
|
||||||
defaultResource = entry;
|
|
||||||
break;
|
|
||||||
case ROOT:
|
|
||||||
rootResource = entry;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
// TODO: warning on replacement of existing mapping?
|
||||||
// TODO: add warning when replacing an existing pathspec?
|
|
||||||
|
|
||||||
mappings.add(entry);
|
mappings.add(entry);
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("Added {} to {}",entry,this);
|
LOG.debug("Added {} to {}",entry,this);
|
||||||
|
@ -119,7 +119,7 @@ public abstract class PathSpec implements Comparable<PathSpec>
|
|||||||
*
|
*
|
||||||
* @return the as-provided path spec
|
* @return the as-provided path spec
|
||||||
*/
|
*/
|
||||||
public String getDeclaration()
|
public String getPathSpec()
|
||||||
{
|
{
|
||||||
return pathSpec;
|
return pathSpec;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ public class ServletPathSpec extends PathSpec
|
|||||||
case EXACT:
|
case EXACT:
|
||||||
return pathSpec.equals(path);
|
return pathSpec.equals(path);
|
||||||
case PREFIX_GLOB:
|
case PREFIX_GLOB:
|
||||||
return isWildcardMatch(path);
|
return (!"/".equals(path) && isWildcardMatch(path));
|
||||||
case SUFFIX_GLOB:
|
case SUFFIX_GLOB:
|
||||||
return path.regionMatches((path.length() - specLength) + 1,pathSpec,1,specLength - 1);
|
return path.regionMatches((path.length() - specLength) + 1,pathSpec,1,specLength - 1);
|
||||||
case ROOT:
|
case ROOT:
|
||||||
|
@ -77,22 +77,61 @@ public class PathMappingsTest
|
|||||||
assertMatch(p,"/animal/fish/trout/cam","animalCam");
|
assertMatch(p,"/animal/fish/trout/cam","animalCam");
|
||||||
assertMatch(p,"/entrance/cam","entranceCam");
|
assertMatch(p,"/entrance/cam","entranceCam");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the match order rules imposed by the Servlet API (default vs any)
|
* Test the match order rules imposed by the Servlet API.
|
||||||
|
* <p>
|
||||||
|
* <ul>
|
||||||
|
* <li>Exact match</li>
|
||||||
|
* <li>Longest prefix match</li>
|
||||||
|
* <li>Longest suffix match</li>
|
||||||
|
* <li>default</li>
|
||||||
|
* </ul>
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testServletMatchDefault()
|
public void testServletMatchOrder()
|
||||||
{
|
{
|
||||||
PathMappings<String> p = new PathMappings<>();
|
PathMappings<String> p = new PathMappings<>();
|
||||||
|
|
||||||
p.put(new ServletPathSpec("/"),"default");
|
p.put(new ServletPathSpec("/abs/path"),"abspath"); // 1
|
||||||
p.put(new ServletPathSpec("/*"),"any");
|
p.put(new ServletPathSpec("/abs/path/longer"),"longpath"); // 2
|
||||||
|
p.put(new ServletPathSpec("/animal/bird/*"),"birds"); // 3
|
||||||
|
p.put(new ServletPathSpec("/animal/fish/*"),"fishes"); // 4
|
||||||
|
p.put(new ServletPathSpec("/animal/*"),"animals"); // 5
|
||||||
|
p.put(new ServletPathSpec("*.tar.gz"),"tarball"); // 6
|
||||||
|
p.put(new ServletPathSpec("*.gz"),"gzipped"); // 7
|
||||||
|
p.put(new ServletPathSpec("/"),"default"); // 8
|
||||||
|
// 9 was the old Jetty ":" spec delimited case (no longer valid)
|
||||||
|
p.put(new ServletPathSpec(""),"root"); // 10
|
||||||
|
p.put(new ServletPathSpec("/\u20ACuro/*"),"money"); // 11
|
||||||
|
|
||||||
assertMatch(p,"/abs/path","any");
|
// dumpMappings(p);
|
||||||
assertMatch(p,"/abs/path/xxx","any");
|
|
||||||
assertMatch(p,"/animal/bird/eagle/bald","any");
|
// From old PathMapTest
|
||||||
assertMatch(p,"/","any");
|
assertMatch(p,"/abs/path","abspath");
|
||||||
|
assertMatch(p,"/abs/path/xxx","default");
|
||||||
|
assertMatch(p,"/abs/pith","default");
|
||||||
|
assertMatch(p,"/abs/path/longer","longpath");
|
||||||
|
assertMatch(p,"/abs/path/","default");
|
||||||
|
assertMatch(p,"/abs/path/foo","default");
|
||||||
|
assertMatch(p,"/animal/bird/eagle/bald","birds");
|
||||||
|
assertMatch(p,"/animal/fish/shark/hammerhead","fishes");
|
||||||
|
assertMatch(p,"/animal/insect/ladybug","animals");
|
||||||
|
assertMatch(p,"/animal","animals");
|
||||||
|
assertMatch(p,"/animal/","animals");
|
||||||
|
assertMatch(p,"/animal/other","animals");
|
||||||
|
assertMatch(p,"/animal/*","animals");
|
||||||
|
assertMatch(p,"/downloads/distribution.tar.gz","tarball");
|
||||||
|
assertMatch(p,"/downloads/script.gz","gzipped");
|
||||||
|
assertMatch(p,"/animal/arhive.gz","animals");
|
||||||
|
assertMatch(p,"/Other/path","default");
|
||||||
|
assertMatch(p,"/\u20ACuro/path","money");
|
||||||
|
assertMatch(p,"/","root");
|
||||||
|
|
||||||
|
// Extra tests
|
||||||
|
assertMatch(p,"/downloads/readme.txt","default");
|
||||||
|
assertMatch(p,"/downloads/logs.tgz","default");
|
||||||
|
assertMatch(p,"/main.css","default");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,13 +28,13 @@ public class RegexPathSpecTest
|
|||||||
{
|
{
|
||||||
public static void assertMatches(PathSpec spec, String path)
|
public static void assertMatches(PathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(true));
|
assertThat(msg,spec.matches(path),is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertNotMatches(PathSpec spec, String path)
|
public static void assertNotMatches(PathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(false));
|
assertThat(msg,spec.matches(path),is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class RegexPathSpecTest
|
|||||||
public void testExactSpec()
|
public void testExactSpec()
|
||||||
{
|
{
|
||||||
RegexPathSpec spec = new RegexPathSpec("^/a$");
|
RegexPathSpec spec = new RegexPathSpec("^/a$");
|
||||||
assertEquals("Spec.pathSpec","^/a$",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","^/a$",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.group);
|
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.group);
|
||||||
@ -57,7 +57,7 @@ public class RegexPathSpecTest
|
|||||||
public void testMiddleSpec()
|
public void testMiddleSpec()
|
||||||
{
|
{
|
||||||
RegexPathSpec spec = new RegexPathSpec("^/rest/([^/]*)/list$");
|
RegexPathSpec spec = new RegexPathSpec("^/rest/([^/]*)/list$");
|
||||||
assertEquals("Spec.pathSpec","^/rest/([^/]*)/list$",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","^/rest/([^/]*)/list$",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/rest/([^/]*)/list$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/rest/([^/]*)/list$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.group);
|
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.group);
|
||||||
@ -78,7 +78,7 @@ public class RegexPathSpecTest
|
|||||||
public void testMiddleSpecNoGrouping()
|
public void testMiddleSpecNoGrouping()
|
||||||
{
|
{
|
||||||
RegexPathSpec spec = new RegexPathSpec("^/rest/[^/]+/list$");
|
RegexPathSpec spec = new RegexPathSpec("^/rest/[^/]+/list$");
|
||||||
assertEquals("Spec.pathSpec","^/rest/[^/]+/list$",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","^/rest/[^/]+/list$",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/rest/[^/]+/list$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/rest/[^/]+/list$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.group);
|
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.group);
|
||||||
@ -99,7 +99,7 @@ public class RegexPathSpecTest
|
|||||||
public void testPrefixSpec()
|
public void testPrefixSpec()
|
||||||
{
|
{
|
||||||
RegexPathSpec spec = new RegexPathSpec("^/a/(.*)$");
|
RegexPathSpec spec = new RegexPathSpec("^/a/(.*)$");
|
||||||
assertEquals("Spec.pathSpec","^/a/(.*)$",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","^/a/(.*)$",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/(.*)$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/(.*)$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.group);
|
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.group);
|
||||||
@ -117,7 +117,7 @@ public class RegexPathSpecTest
|
|||||||
public void testSuffixSpec()
|
public void testSuffixSpec()
|
||||||
{
|
{
|
||||||
RegexPathSpec spec = new RegexPathSpec("^(.*).do$");
|
RegexPathSpec spec = new RegexPathSpec("^(.*).do$");
|
||||||
assertEquals("Spec.pathSpec","^(.*).do$",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","^(.*).do$",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^(.*).do$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^(.*).do$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",0,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",0,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.SUFFIX_GLOB,spec.group);
|
assertEquals("Spec.group",PathSpecGroup.SUFFIX_GLOB,spec.group);
|
||||||
|
@ -43,13 +43,13 @@ public class ServletPathSpecTest
|
|||||||
|
|
||||||
private void assertMatches(ServletPathSpec spec, String path)
|
private void assertMatches(ServletPathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(true));
|
assertThat(msg,spec.matches(path),is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNotMatches(ServletPathSpec spec, String path)
|
private void assertNotMatches(ServletPathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(false));
|
assertThat(msg,spec.matches(path),is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public class ServletPathSpecTest
|
|||||||
public void testDefaultPathSpec()
|
public void testDefaultPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec("/");
|
ServletPathSpec spec = new ServletPathSpec("/");
|
||||||
assertEquals("Spec.pathSpec","/",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class ServletPathSpecTest
|
|||||||
public void testExactPathSpec()
|
public void testExactPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec("/abs/path");
|
ServletPathSpec spec = new ServletPathSpec("/abs/path");
|
||||||
assertEquals("Spec.pathSpec","/abs/path",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/abs/path",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
||||||
|
|
||||||
assertMatches(spec,"/abs/path");
|
assertMatches(spec,"/abs/path");
|
||||||
@ -125,7 +125,7 @@ public class ServletPathSpecTest
|
|||||||
public void testNullPathSpec()
|
public void testNullPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec(null);
|
ServletPathSpec spec = new ServletPathSpec(null);
|
||||||
assertEquals("Spec.pathSpec","",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ public class ServletPathSpecTest
|
|||||||
public void testRootPathSpec()
|
public void testRootPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec("");
|
ServletPathSpec spec = new ServletPathSpec("");
|
||||||
assertEquals("Spec.pathSpec","",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",-1,spec.getPathDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public class ServletPathSpecTest
|
|||||||
public void testPrefixPathSpec()
|
public void testPrefixPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec("/downloads/*");
|
ServletPathSpec spec = new ServletPathSpec("/downloads/*");
|
||||||
assertEquals("Spec.pathSpec","/downloads/*",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/downloads/*",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
||||||
|
|
||||||
assertMatches(spec,"/downloads/logo.jpg");
|
assertMatches(spec,"/downloads/logo.jpg");
|
||||||
@ -173,7 +173,7 @@ public class ServletPathSpecTest
|
|||||||
public void testSuffixPathSpec()
|
public void testSuffixPathSpec()
|
||||||
{
|
{
|
||||||
ServletPathSpec spec = new ServletPathSpec("*.gz");
|
ServletPathSpec spec = new ServletPathSpec("*.gz");
|
||||||
assertEquals("Spec.pathSpec","*.gz",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","*.gz",spec.getPathSpec());
|
||||||
assertEquals("Spec.pathDepth",0,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",0,spec.getPathDepth());
|
||||||
|
|
||||||
assertMatches(spec,"/downloads/distribution.tar.gz");
|
assertMatches(spec,"/downloads/distribution.tar.gz");
|
||||||
|
@ -34,7 +34,7 @@ public class UriTemplatePathSpecTest
|
|||||||
{
|
{
|
||||||
private void assertDetectedVars(UriTemplatePathSpec spec, String... expectedVars)
|
private void assertDetectedVars(UriTemplatePathSpec spec, String... expectedVars)
|
||||||
{
|
{
|
||||||
String prefix = String.format("Spec(\"%s\")",spec.getDeclaration());
|
String prefix = String.format("Spec(\"%s\")",spec.getPathSpec());
|
||||||
assertEquals(prefix + ".variableCount",expectedVars.length,spec.getVariableCount());
|
assertEquals(prefix + ".variableCount",expectedVars.length,spec.getVariableCount());
|
||||||
assertEquals(prefix + ".variable.length",expectedVars.length,spec.getVariables().length);
|
assertEquals(prefix + ".variable.length",expectedVars.length,spec.getVariables().length);
|
||||||
for (int i = 0; i < expectedVars.length; i++)
|
for (int i = 0; i < expectedVars.length; i++)
|
||||||
@ -45,13 +45,13 @@ public class UriTemplatePathSpecTest
|
|||||||
|
|
||||||
private void assertMatches(PathSpec spec, String path)
|
private void assertMatches(PathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(true));
|
assertThat(msg,spec.matches(path),is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNotMatches(PathSpec spec, String path)
|
private void assertNotMatches(PathSpec spec, String path)
|
||||||
{
|
{
|
||||||
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getDeclaration(),path);
|
String msg = String.format("!Spec(\"%s\").matches(\"%s\")",spec.getPathSpec(),path);
|
||||||
assertThat(msg,spec.matches(path),is(false));
|
assertThat(msg,spec.matches(path),is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testDefaultPathSpec()
|
public void testDefaultPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/");
|
||||||
assertEquals("Spec.pathSpec","/",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
||||||
@ -72,7 +72,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testExactOnePathSpec()
|
public void testExactOnePathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a");
|
||||||
assertEquals("Spec.pathSpec","/a",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
||||||
@ -90,7 +90,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testExactPathSpec_TestWebapp()
|
public void testExactPathSpec_TestWebapp()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/deep.thought/");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/deep.thought/");
|
||||||
assertEquals("Spec.pathSpec","/deep.thought/",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/deep.thought/",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/deep\\.thought/$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/deep\\.thought/$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
||||||
@ -106,7 +106,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testExactTwoPathSpec()
|
public void testExactTwoPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/b");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/b");
|
||||||
assertEquals("Spec.pathSpec","/a/b",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a/b",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/b$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/b$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.EXACT,spec.getGroup());
|
||||||
@ -125,7 +125,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testMiddleVarPathSpec()
|
public void testMiddleVarPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var}/c");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var}/c");
|
||||||
assertEquals("Spec.pathSpec","/a/{var}/c",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a/{var}/c",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/([^/]+)/c$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/([^/]+)/c$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
||||||
@ -149,7 +149,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testOneVarPathSpec()
|
public void testOneVarPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{foo}");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{foo}");
|
||||||
assertEquals("Spec.pathSpec","/a/{foo}",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a/{foo}",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/([^/]+)$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/([^/]+)$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",2,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
||||||
@ -170,7 +170,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testOneVarSuffixPathSpec()
|
public void testOneVarSuffixPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var}/b/c");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var}/b/c");
|
||||||
assertEquals("Spec.pathSpec","/{var}/b/c",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/{var}/b/c",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/([^/]+)/b/c$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/([^/]+)/b/c$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.SUFFIX_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.SUFFIX_GLOB,spec.getGroup());
|
||||||
@ -194,7 +194,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testTwoVarComplexInnerPathSpec()
|
public void testTwoVarComplexInnerPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var1}/c/{var2}/e");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var1}/c/{var2}/e");
|
||||||
assertEquals("Spec.pathSpec","/a/{var1}/c/{var2}/e",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a/{var1}/c/{var2}/e",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/([^/]+)/c/([^/]+)/e$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/([^/]+)/c/([^/]+)/e$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",5,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",5,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
||||||
@ -217,7 +217,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testTwoVarComplexOuterPathSpec()
|
public void testTwoVarComplexOuterPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var1}/b/{var2}/{var3}");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var1}/b/{var2}/{var3}");
|
||||||
assertEquals("Spec.pathSpec","/{var1}/b/{var2}/{var3}",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/{var1}/b/{var2}/{var3}",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/([^/]+)/b/([^/]+)/([^/]+)$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/([^/]+)/b/([^/]+)/([^/]+)$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",4,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",4,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.MIDDLE_GLOB,spec.getGroup());
|
||||||
@ -241,7 +241,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testTwoVarPrefixPathSpec()
|
public void testTwoVarPrefixPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var1}/{var2}");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/a/{var1}/{var2}");
|
||||||
assertEquals("Spec.pathSpec","/a/{var1}/{var2}",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/a/{var1}/{var2}",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/a/([^/]+)/([^/]+)$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/a/([^/]+)/([^/]+)$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",3,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
||||||
@ -264,7 +264,7 @@ public class UriTemplatePathSpecTest
|
|||||||
public void testVarOnlyPathSpec()
|
public void testVarOnlyPathSpec()
|
||||||
{
|
{
|
||||||
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var1}");
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/{var1}");
|
||||||
assertEquals("Spec.pathSpec","/{var1}",spec.getDeclaration());
|
assertEquals("Spec.pathSpec","/{var1}",spec.getPathSpec());
|
||||||
assertEquals("Spec.pattern","^/([^/]+)$",spec.getPattern().pattern());
|
assertEquals("Spec.pattern","^/([^/]+)$",spec.getPattern().pattern());
|
||||||
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
assertEquals("Spec.pathDepth",1,spec.getPathDepth());
|
||||||
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
assertEquals("Spec.group",PathSpecGroup.PREFIX_GLOB,spec.getGroup());
|
||||||
|
@ -47,7 +47,6 @@ import org.eclipse.jetty.http.HttpHeader;
|
|||||||
import org.eclipse.jetty.http.HttpMethod;
|
import org.eclipse.jetty.http.HttpMethod;
|
||||||
import org.eclipse.jetty.http.MimeTypes;
|
import org.eclipse.jetty.http.MimeTypes;
|
||||||
import org.eclipse.jetty.http.PathMap.MappedEntry;
|
import org.eclipse.jetty.http.PathMap.MappedEntry;
|
||||||
import org.eclipse.jetty.http.pathmap.MappedResource;
|
|
||||||
import org.eclipse.jetty.io.WriterOutputStream;
|
import org.eclipse.jetty.io.WriterOutputStream;
|
||||||
import org.eclipse.jetty.server.HttpOutput;
|
import org.eclipse.jetty.server.HttpOutput;
|
||||||
import org.eclipse.jetty.server.InclusiveByteRange;
|
import org.eclipse.jetty.server.InclusiveByteRange;
|
||||||
@ -692,9 +691,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||||||
|
|
||||||
if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null)
|
if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null)
|
||||||
{
|
{
|
||||||
MappedResource<ServletHolder> entry=_servletHandler.getHolderEntry(welcome_in_context);
|
MappedEntry<?> entry=_servletHandler.getHolderEntry(welcome_in_context);
|
||||||
if (entry!=null && entry.getResource()!=_defaultHolder &&
|
if (entry!=null && entry.getValue()!=_defaultHolder &&
|
||||||
(_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcome_in_context))))
|
(_welcomeServlets || (_welcomeExactServlets && entry.getKey().equals(welcome_in_context))))
|
||||||
welcome_servlet=welcome_in_context;
|
welcome_servlet=welcome_in_context;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.PathMap.MappedEntry;
|
|
||||||
import org.eclipse.jetty.http.pathmap.MappedResource;
|
|
||||||
import org.eclipse.jetty.server.Dispatcher;
|
import org.eclipse.jetty.server.Dispatcher;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.HttpChannel;
|
import org.eclipse.jetty.server.HttpChannel;
|
||||||
@ -74,7 +72,7 @@ public class Invoker extends HttpServlet
|
|||||||
|
|
||||||
private ContextHandler _contextHandler;
|
private ContextHandler _contextHandler;
|
||||||
private ServletHandler _servletHandler;
|
private ServletHandler _servletHandler;
|
||||||
private MappedResource<ServletHolder> _invokerEntry;
|
private Map.Entry<String, ServletHolder> _invokerEntry;
|
||||||
private Map<String, String> _parameters;
|
private Map<String, String> _parameters;
|
||||||
private boolean _nonContextServlets;
|
private boolean _nonContextServlets;
|
||||||
private boolean _verbose;
|
private boolean _verbose;
|
||||||
@ -173,12 +171,12 @@ public class Invoker extends HttpServlet
|
|||||||
|
|
||||||
// Check for existing mapping (avoid threaded race).
|
// Check for existing mapping (avoid threaded race).
|
||||||
String path=URIUtil.addPaths(servlet_path,servlet);
|
String path=URIUtil.addPaths(servlet_path,servlet);
|
||||||
MappedResource<ServletHolder> entry = _servletHandler.getHolderEntry(path);
|
Map.Entry<String, ServletHolder> entry = _servletHandler.getHolderEntry(path);
|
||||||
|
|
||||||
if (entry!=null && !entry.equals(_invokerEntry))
|
if (entry!=null && !entry.equals(_invokerEntry))
|
||||||
{
|
{
|
||||||
// Use the holder
|
// Use the holder
|
||||||
holder=(ServletHolder)entry.getResource();
|
holder=(ServletHolder)entry.getValue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -52,10 +52,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import org.eclipse.jetty.http.HttpHeader;
|
import org.eclipse.jetty.http.HttpHeader;
|
||||||
import org.eclipse.jetty.http.HttpHeaderValue;
|
import org.eclipse.jetty.http.HttpHeaderValue;
|
||||||
import org.eclipse.jetty.http.pathmap.MappedResource;
|
import org.eclipse.jetty.http.PathMap;
|
||||||
import org.eclipse.jetty.http.pathmap.PathMappings;
|
|
||||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
|
||||||
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
|
|
||||||
import org.eclipse.jetty.io.EofException;
|
import org.eclipse.jetty.io.EofException;
|
||||||
import org.eclipse.jetty.io.RuntimeIOException;
|
import org.eclipse.jetty.io.RuntimeIOException;
|
||||||
import org.eclipse.jetty.security.IdentityService;
|
import org.eclipse.jetty.security.IdentityService;
|
||||||
@ -124,8 +121,7 @@ public class ServletHandler extends ScopedHandler
|
|||||||
private MultiMap<FilterMapping> _filterNameMappings;
|
private MultiMap<FilterMapping> _filterNameMappings;
|
||||||
|
|
||||||
private final Map<String,ServletHolder> _servletNameMap=new HashMap<>();
|
private final Map<String,ServletHolder> _servletNameMap=new HashMap<>();
|
||||||
// private PathMap<ServletHolder> _servletPathMap;
|
private PathMap<ServletHolder> _servletPathMap;
|
||||||
private PathMappings<ServletHolder> _servletPathMap;
|
|
||||||
|
|
||||||
private ListenerHolder[] _listeners=new ListenerHolder[0];
|
private ListenerHolder[] _listeners=new ListenerHolder[0];
|
||||||
|
|
||||||
@ -387,7 +383,7 @@ public class ServletHandler extends ScopedHandler
|
|||||||
* @param pathInContext Path within _context.
|
* @param pathInContext Path within _context.
|
||||||
* @return PathMap Entries pathspec to ServletHolder
|
* @return PathMap Entries pathspec to ServletHolder
|
||||||
*/
|
*/
|
||||||
public MappedResource<ServletHolder> getHolderEntry(String pathInContext)
|
public PathMap.MappedEntry<ServletHolder> getHolderEntry(String pathInContext)
|
||||||
{
|
{
|
||||||
if (_servletPathMap==null)
|
if (_servletPathMap==null)
|
||||||
return null;
|
return null;
|
||||||
@ -474,14 +470,14 @@ public class ServletHandler extends ScopedHandler
|
|||||||
if (target.startsWith("/"))
|
if (target.startsWith("/"))
|
||||||
{
|
{
|
||||||
// Look for the servlet by path
|
// Look for the servlet by path
|
||||||
MappedResource<ServletHolder> entry=getHolderEntry(target);
|
PathMap.MappedEntry<ServletHolder> entry=getHolderEntry(target);
|
||||||
if (entry!=null)
|
if (entry!=null)
|
||||||
{
|
{
|
||||||
PathSpec pathSpec = entry.getPathSpec();
|
servlet_holder=entry.getValue();
|
||||||
servlet_holder=entry.getResource();
|
|
||||||
|
|
||||||
String servlet_path=pathSpec.getPathMatch(target);
|
String servlet_path_spec= entry.getKey();
|
||||||
String path_info=pathSpec.getPathInfo(target);
|
String servlet_path=entry.getMapped()!=null?entry.getMapped():PathMap.pathMatch(servlet_path_spec,target);
|
||||||
|
String path_info=PathMap.pathInfo(servlet_path_spec,target);
|
||||||
|
|
||||||
if (DispatcherType.INCLUDE.equals(type))
|
if (DispatcherType.INCLUDE.equals(type))
|
||||||
{
|
{
|
||||||
@ -1436,7 +1432,7 @@ public class ServletHandler extends ScopedHandler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PathMappings<ServletHolder> pm = new PathMappings<>();
|
PathMap<ServletHolder> pm = new PathMap<>();
|
||||||
Map<String,ServletMapping> servletPathMappings = new HashMap<String,ServletMapping>();
|
Map<String,ServletMapping> servletPathMappings = new HashMap<String,ServletMapping>();
|
||||||
|
|
||||||
//create a map of paths to set of ServletMappings that define that mapping
|
//create a map of paths to set of ServletMappings that define that mapping
|
||||||
@ -1499,7 +1495,7 @@ public class ServletHandler extends ScopedHandler
|
|||||||
if (LOG.isDebugEnabled()) LOG.debug("Chose path={} mapped to servlet={} from default={}", pathSpec, finalMapping.getServletName(), finalMapping.isDefault());
|
if (LOG.isDebugEnabled()) LOG.debug("Chose path={} mapped to servlet={} from default={}", pathSpec, finalMapping.getServletName(), finalMapping.isDefault());
|
||||||
|
|
||||||
servletPathMappings.put(pathSpec, finalMapping);
|
servletPathMappings.put(pathSpec, finalMapping);
|
||||||
pm.put(new ServletPathSpec(pathSpec),_servletNameMap.get(finalMapping.getServletName()));
|
pm.put(pathSpec,_servletNameMap.get(finalMapping.getServletName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
_servletPathMap=pm;
|
_servletPathMap=pm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user