From d56bdf10278de5bf2c36745ccac842190eeb72c6 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Fri, 28 Aug 2015 11:19:14 -0500 Subject: Bug 476136 - [http whiteboard] using legacy servlet registration does not allow exact matching to take precidence --- .../equinox/http/servlet/tests/ServletTest.java | 33 ++++++++++++++++++++++ .../servlet/internal/HttpServiceRuntimeImpl.java | 12 ++++---- 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'bundles') diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java index ce0ce6c1d..8727d4106 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java +++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java @@ -1726,6 +1726,39 @@ public class ServletTest extends TestCase { Assert.assertEquals("p=1&p=2|1|[1, 2]", result); } + public void test_ServletExactMatchPrecidence() throws Exception { + Servlet sA = new HttpServlet() { + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.getWriter().write('a'); + } + + }; + + Servlet sB = new HttpServlet() { + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.getWriter().write('b'); + } + + }; + + HttpService httpService = getHttpService(); + + HttpContext httpContext = httpService.createDefaultHttpContext(); + + httpService.registerServlet("*.txt", sA, null, httpContext); + httpService.registerServlet("/files/help.txt", sB, null, httpContext); + + Assert.assertEquals("b", requestAdvisor.request("files/help.txt")); + } + private static String getSubmittedFileName(Part part) { for (String cd : part.getHeader("content-disposition").split(";")) { if (cd.trim().startsWith("filename")) { diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java index d363b698b..9e28f58f9 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java @@ -692,13 +692,13 @@ public class HttpServiceRuntimeImpl // check the pattern against the original input ContextController.checkPattern(alias); - String pattern = alias; - // need to make sure exact matching aliases are converted to wildcard pattern matches - if (!pattern.endsWith(Const.SLASH_STAR) && !pattern.startsWith(Const.STAR_DOT) && !pattern.contains(Const.SLASH_STAR_DOT)) { - if (pattern.endsWith(Const.SLASH)) { - pattern = pattern + '*'; + Object pattern = alias; + // need to make sure exact matching aliases are converted to exact matching + wildcard pattern matching + if (!alias.endsWith(Const.SLASH_STAR) && !alias.startsWith(Const.STAR_DOT) && !alias.contains(Const.SLASH_STAR_DOT)) { + if (alias.endsWith(Const.SLASH)) { + pattern = new String[] {alias, alias + '*'}; } else { - pattern = pattern + Const.SLASH_STAR; + pattern = new String[] {alias, alias + Const.SLASH_STAR}; } } -- cgit v1.2.3