org.apache.catalina.filters.AddDefaultCharsetFilter Java Examples

The following examples show how to use org.apache.catalina.filters.AddDefaultCharsetFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestApplicationFilterConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example #2
Source File: TestApplicationFilterConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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.addServletMapping("/", "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());
}
 
Example #3
Source File: TestApplicationFilterConfig.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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.addServletMapping("/", "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());
}
 
Example #4
Source File: ServletConfigurer.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public void onStartup(final Set<Class<?>> set, final ServletContext servletContext) {
    addFilter(servletContext, "security-filter", HttpHeaderSecurityFilter.class);
    addFilter(servletContext, "encoding-filter", AddDefaultCharsetFilter.class);
    addFilter(servletContext, "csp-filter", CSPFilter.class);
}