Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2014-07-16 01:52:04 -0400
committerJan Bartel2014-07-16 01:53:07 -0400
commit50f11bea091b17ec4c7cffc6d8c53ce649266582 (patch)
treec3ab578dce5038638d9943fda004b83220242ca1 /jetty-servlet
parentdd5cdab54cdd6787ab25775291ff5c56716b1415 (diff)
downloadorg.eclipse.jetty.project-50f11bea091b17ec4c7cffc6d8c53ce649266582.tar.gz
org.eclipse.jetty.project-50f11bea091b17ec4c7cffc6d8c53ce649266582.tar.xz
org.eclipse.jetty.project-50f11bea091b17ec4c7cffc6d8c53ce649266582.zip
439663 Allow mappings to be declared before servlet/filter
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java32
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHandlerTest.java7
2 files changed, 28 insertions, 11 deletions
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
index 2ed3b50285..38edb727ec 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
@@ -116,8 +116,6 @@ public class ServletHandler extends ScopedHandler
private ServletHolder[] _servlets=new ServletHolder[0];
private ServletMapping[] _servletMappings;
- private Map<String,ServletMapping> _servletPathMappings = new HashMap<String,ServletMapping>();
-
private final Map<String,FilterHolder> _filterNameMap= new HashMap<>();
private List<FilterMapping> _filterPathMappings;
private MultiMap<FilterMapping> _filterNameMappings;
@@ -340,7 +338,6 @@ public class ServletHandler extends ScopedHandler
_filterPathMappings=null;
_filterNameMappings=null;
_servletPathMap=null;
- _servletPathMappings=null;
}
/* ------------------------------------------------------------ */
@@ -415,10 +412,26 @@ public class ServletHandler extends ScopedHandler
*/
public ServletMapping getServletMapping(String pathSpec)
{
- if (pathSpec == null || _servletPathMappings == null)
+ if (pathSpec == null || _servletMappings == null)
return null;
- return _servletPathMappings.get(pathSpec);
+ ServletMapping mapping = null;
+ for (int i=0; i<_servletMappings.length && mapping == null; i++)
+ {
+ ServletMapping m = _servletMappings[i];
+ if (m.getPathSpecs() != null)
+ {
+ for (String p:m.getPathSpecs())
+ {
+ if (pathSpec.equals(p))
+ {
+ mapping = m;
+ break;
+ }
+ }
+ }
+ }
+ return mapping;
}
/* ------------------------------------------------------------ */
@@ -1443,9 +1456,7 @@ public class ServletHandler extends ScopedHandler
//for each path, look at the mappings where it is referenced
//if a mapping is for a servlet that is not enabled, skip it
Set<ServletMapping> mappings = sms.get(pathSpec);
-
-
-
+
ServletMapping finalMapping = null;
for (ServletMapping mapping : mappings)
{
@@ -1483,7 +1494,6 @@ public class ServletHandler extends ScopedHandler
}
_servletPathMap=pm;
- _servletPathMappings=servletPathMappings;
}
// flush filter chain cache
@@ -1542,7 +1552,7 @@ public class ServletHandler extends ScopedHandler
{
updateBeans(_filterMappings,filterMappings);
_filterMappings = filterMappings;
- updateMappings();
+ if (isStarted()) updateMappings();
invalidateChainsCache();
}
@@ -1567,7 +1577,7 @@ public class ServletHandler extends ScopedHandler
{
updateBeans(_servletMappings,servletMappings);
_servletMappings = servletMappings;
- updateMappings();
+ if (isStarted()) updateMappings();
invalidateChainsCache();
}
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHandlerTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHandlerTest.java
index f8d1aaa1c8..cb035d7ac2 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHandlerTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHandlerTest.java
@@ -335,6 +335,7 @@ public class ServletHandlerTest
//add a non-programmatic one to begin with
handler.addFilterWithMapping(fh1, "/*", EnumSet.allOf(DispatcherType.class));
+ handler.updateMappings();
FilterMapping[] mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertTrue(fh1 == mappings[0].getFilterHolder());
@@ -343,6 +344,7 @@ public class ServletHandlerTest
fh4.setServletHandler(handler);
handler.addFilter(fh4);
fh4.getRegistration().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertEquals(2, mappings.length);
@@ -353,6 +355,7 @@ public class ServletHandlerTest
fh3.setServletHandler(handler);
handler.addFilter(fh3);
fh3.getRegistration().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertEquals(3, mappings.length);
@@ -364,6 +367,7 @@ public class ServletHandlerTest
fh5.setServletHandler(handler);
handler.addFilter(fh5);
fh5.getRegistration().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertEquals(4, mappings.length);
@@ -376,6 +380,7 @@ public class ServletHandlerTest
FilterHolder f = new FilterHolder(Source.EMBEDDED);
f.setName("non-programmatic");
handler.addFilterWithMapping(f, "/*", EnumSet.allOf(DispatcherType.class));
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertEquals(5, mappings.length);
@@ -391,6 +396,7 @@ public class ServletHandlerTest
pf.setName("programmaticA");
handler.addFilter(pf);
pf.getRegistration().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);
assertEquals(6, mappings.length);
@@ -407,6 +413,7 @@ public class ServletHandlerTest
pf2.setName("programmaticB");
handler.addFilter(pf2);
pf2.getRegistration().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
+ handler.updateMappings();
mappings = handler.getFilterMappings();
assertNotNull(mappings);

Back to the top