use of org.apache.tomcat.util.descriptor.web.FilterDef in project tomcat by apache.
the class ApplicationContext method getFilterRegistrations.
@Override
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
Map<String, ApplicationFilterRegistration> result = new HashMap<>();
FilterDef[] filterDefs = context.findFilterDefs();
for (FilterDef filterDef : filterDefs) {
result.put(filterDef.getFilterName(), new ApplicationFilterRegistration(filterDef, context));
}
return result;
}
use of org.apache.tomcat.util.descriptor.web.FilterDef in project tomcat by apache.
the class TestContextConfigAnnotation method testFilterMapping.
@Test
public void testFilterMapping() throws Exception {
WebXml webxml = new WebXml();
Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
ContextConfig config = new ContextConfig();
File sFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
config.processAnnotationsFile(sFile, webxml, false, javaClassCache);
File fFile = paramClassResource("org/apache/catalina/startup/ParamFilter");
config.processAnnotationsFile(fFile, webxml, false, javaClassCache);
FilterDef fdef = webxml.getFilters().get("paramFilter");
assertNotNull(fdef);
assertEquals("Servlet says: ", fdef.getParameterMap().get("message"));
}
use of org.apache.tomcat.util.descriptor.web.FilterDef in project tomcat by apache.
the class TestContextConfigAnnotation method testDuplicateFilterMapping.
@Test
public void testDuplicateFilterMapping() throws Exception {
WebXml webxml = new WebXml();
Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/DuplicateMappingParamFilter");
assertTrue(pFile.exists());
try {
config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
fail();
} catch (IllegalArgumentException ex) {
// ignore
}
FilterDef filterDef = webxml.getFilters().get("paramD");
assertNull(filterDef);
}
use of org.apache.tomcat.util.descriptor.web.FilterDef in project tomcat by apache.
the class TestApplicationFilterConfig method testBug54170.
@Test
public void testBug54170() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "HelloWorld", new HelloWorldServlet());
ctx.addServletMappingDecoded("/", "HelloWorld");
// Add a filter with a name that should be escaped if used in a JMX
// object name
FilterDef filterDef = new FilterDef();
filterDef.setFilterClass(AddDefaultCharsetFilter.class.getName());
filterDef.setFilterName("bug54170*");
ctx.addFilterDef(filterDef);
tomcat.start();
final MBeanServer mbeanServer = Registry.getRegistry(null, null).getMBeanServer();
// There should be one Servlet MBean registered
Set<ObjectName> servlets = mbeanServer.queryNames(new ObjectName("Tomcat:j2eeType=Servlet,*"), null);
Assert.assertEquals(1, servlets.size());
// There should be one Filter MBean registered
Set<ObjectName> filters = mbeanServer.queryNames(new ObjectName("Tomcat:j2eeType=Filter,*"), null);
Assert.assertEquals(1, filters.size());
}
use of org.apache.tomcat.util.descriptor.web.FilterDef in project tomcat by apache.
the class TestStandardContext method configureTest46243Context.
private static void configureTest46243Context(Context context, boolean fail) {
// Add a test filter that fails
FilterDef filterDef = new FilterDef();
filterDef.setFilterClass(Bug46243Filter.class.getName());
filterDef.setFilterName("Bug46243");
filterDef.addInitParameter("fail", Boolean.toString(fail));
context.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName("Bug46243");
filterMap.addURLPatternDecoded("*");
context.addFilterMap(filterMap);
// Add a test servlet so there is something to generate a response if
// it works (although it shouldn't)
Tomcat.addServlet(context, "Bug46243", new HelloWorldServlet());
context.addServletMappingDecoded("/", "Bug46243");
}
Aggregations