Skip to content

Commit

Permalink
UNDERTOW-980 Servlet name '*' is not recognised in Servlet name mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Feb 1, 2017
1 parent d06c425 commit 8f5e362
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
Expand Up @@ -18,6 +18,20 @@

package io.undertow.servlet.handlers;

import static io.undertow.servlet.handlers.ServletPathMatch.Type.REDIRECT;
import static io.undertow.servlet.handlers.ServletPathMatch.Type.REWRITE;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.DispatcherType;

import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.cache.LRUCache;
Expand All @@ -34,19 +48,6 @@
import io.undertow.servlet.core.ManagedServlets;
import io.undertow.servlet.handlers.security.ServletSecurityRoleHandler;

import javax.servlet.DispatcherType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static io.undertow.servlet.handlers.ServletPathMatch.Type.REDIRECT;
import static io.undertow.servlet.handlers.ServletPathMatch.Type.REWRITE;

/**
* Facade around {@link ServletPathMatchesData}. This facade is responsible for re-generating the matches if anything changes.
Expand Down Expand Up @@ -291,18 +292,18 @@ private ServletPathMatchesData setupServletChains() {
ManagedFilter filter = filters.getManagedFilter(filterMapping.getFilterName());
if (filterMapping.getMappingType() == FilterMappingInfo.MappingType.SERVLET) {
if (targetServletMatch.handler != null) {
if (filterMapping.getMapping().equals(targetServletMatch.handler.getManagedServlet().getServletInfo().getName())) {
if (filterMapping.getMapping().equals(targetServletMatch.handler.getManagedServlet().getServletInfo().getName()) || filterMapping.getMapping().equals("*")) {
addToListMap(noExtension, filterMapping.getDispatcher(), filter);
}
}
for(Map.Entry<String, Map<DispatcherType, List<ManagedFilter>>> entry : extension.entrySet()) {
ServletHandler pathServlet = targetServletMatch.handler;
boolean defaultServletMatch = targetServletMatch.defaultServlet;
for (Map.Entry<String, Map<DispatcherType, List<ManagedFilter>>> entry : extension.entrySet()) {
ServletHandler pathServlet = targetServletMatch.handler;
boolean defaultServletMatch = targetServletMatch.defaultServlet;
if (defaultServletMatch && extensionServlets.containsKey(entry.getKey())) {
pathServlet = extensionServlets.get(entry.getKey());
}

if (filterMapping.getMapping().equals(pathServlet.getManagedServlet().getServletInfo().getName())) {
if (filterMapping.getMapping().equals(pathServlet.getManagedServlet().getServletInfo().getName()) || filterMapping.getMapping().equals("*")) {
addToListMap(extension.get(entry.getKey()), filterMapping.getDispatcher(), filter);
}
}
Expand Down
Expand Up @@ -118,6 +118,9 @@ public void testBasicFilterMappings() throws IOException, ServletException {
builder.addFilter(new FilterInfo("/test", PathFilter.class));
builder.addFilterUrlMapping("/test", "/test", DispatcherType.REQUEST);

builder.addFilter(new FilterInfo("allByName", PathFilter.class));
builder.addFilterServletNameMapping("allByName", "*", DispatcherType.REQUEST);

builder.setClassIntrospecter(TestClassIntrospector.INSTANCE)
.setClassLoader(FilterPathMappingTestCase.class.getClassLoader())
.setContextPath("/servletContext")
Expand All @@ -132,21 +135,21 @@ public void testBasicFilterMappings() throws IOException, ServletException {

TestHttpClient client = new TestHttpClient();
try {
runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test");
runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa");
runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*");
runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*");
runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName");
runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*");
runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName");
runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot");
runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName");
runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*");
runTest(client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*", "*", "/myservlet/myfilter/*");
runTest(client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*", "*", "/myservlet/myfilter/*");
runTest(client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null", "/*", "*");
runTest(client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*");
runTest(client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*", "/helloworld/index.html", "defaultName");
runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test", "allByName");
runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa", "allByName");
runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*", "allByName");
runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*", "allByName");
runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName", "allByName");
runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*", "allByName");
runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName", "allByName");
runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot", "allByName");
runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName", "allByName");
runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*", "allByName");
runTest(client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*", "*", "/myservlet/myfilter/*", "allByName");
runTest(client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*", "*", "/myservlet/myfilter/*", "allByName");
runTest(client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null", "/*", "*", "allByName");
runTest(client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*", "allByName");
runTest(client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*", "/helloworld/index.html", "defaultName", "allByName");

} finally {
client.getConnectionManager().shutdown();
Expand Down

0 comments on commit 8f5e362

Please sign in to comment.