Example usage for javax.servlet ServletContext addFilter

List of usage examples for javax.servlet ServletContext addFilter

Introduction

In this page you can find the example usage for javax.servlet ServletContext addFilter.

Prototype

public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass);

Source Link

Document

Adds the filter with the given name and class type to this servlet context.

Usage

From source file:io.lavagna.config.DispatcherServletInitializer.java

private static void addFilter(ServletContext context, String filterName, Class<? extends Filter> filterClass,
        String... urlPatterns) {/*from   w w w .j  a va 2s  . c  o m*/
    javax.servlet.FilterRegistration.Dynamic hstsFilter = context.addFilter(filterName, filterClass);
    hstsFilter.setAsyncSupported(true);
    hstsFilter.addMappingForUrlPatterns(null, false, urlPatterns);
}

From source file:de.pksoftware.springstrap.core.util.ConfigUtils.java

/**
 * Creates the filter chain./* ww w .  j a  v  a 2  s  .  c o m*/
 * @param sContext
 */
public static void createFilterChain(ServletContext sContext) {
    // EnumSet<DispatcherType> dispatcherTypes =
    // EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    FilterRegistration.Dynamic characterEncoding = sContext.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(null, true, "/*");

    DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
    //TODO Why is this needed?
    filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");

    sContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, false, "/*");

    // FilterRegistration.Dynamic security =
    // sContext.addFilter("springSecurityFilterChain", new
    // DelegatingFilterProxy());
    // security.addMappingForUrlPatterns(null, true, "/*");
}

From source file:http2.DispatcherServletInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.addFilter("pcf", "org.eclipse.jetty.servlets.PushCacheFilter").addMappingForUrlPatterns(
            EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*");
    super.onStartup(servletContext);
}

From source file:com.cami.spring.core.SpringSecurityInitializer.java

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("encodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");
}

From source file:de.interseroh.report.webapp.UiWebAppInitializer.java

private void addSecurityFilter(ServletContext servletContext) {
    servletContext.addFilter(SPRING_SECURITY_FILTER_NAME, DelegatingFilterProxy.class).addMappingForUrlPatterns(
            EnumSet.<DispatcherType>of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}

From source file:org.devgateway.toolkit.forms.wicket.WebInitializer.java

@Override
public void onStartup(final ServletContext sc) throws ServletException {
    sc.addFilter("Spring OpenEntityManagerInViewFilter",
            org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class)
            .addMappingForUrlPatterns(null, false, "/*");

    FilterRegistration filter = sc.addFilter("wicket-filter", WicketFilter.class);
    filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
    filter.setInitParameter(PARAM_APP_BEAN, "formsWebApplication");
    // This line is the only surprise when comparing to the equivalent
    // web.xml. Without some initialization seems to be missing.
    filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    filter.addMappingForUrlPatterns(null, false, "/*");

    // // Request Listener
    sc.addListener(new RequestContextListener());
    sc.addListener(new HttpSessionEventPublisher());

}

From source file:hwolf.showcase.Application.java

@Override
public void onStartup(ServletContext context) throws ServletException {

    context.addListener(new FileCleanerCleanup());
    context.addFilter("PrimeFaces FileUpload Filter", new FileUploadFilter()) //
            .addMappingForServletNames(null, false, "FacesServlet");

    context.addFilter("Browser Stats Filter", new UserAgentListener()) //
            .addMappingForUrlPatterns(null, false, "/push/chart.xhtml");
    Dynamic registration = context.addServlet("Push Servlet", new PushServlet());
    registration.setAsyncSupported(true);
    registration.addMapping("/primepush/*");
}

From source file:com.sg.rest.spring.WebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CorsFilter.class);
    corsFilter.addMappingForUrlPatterns(null, true, "/*");
    super.onStartup(servletContext);
}

From source file:com.cfitzarl.cfjwed.Main.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Add spring security filter chain
    servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(null, false, "/*");

    // Add Hibernate session binder
    servletContext.addFilter("jpaTransactionFilter", OpenEntityManagerInViewFilter.class)
            .addMappingForUrlPatterns(null, false, "/*");

    // Define application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(WebApplicationMvcConfigurer.class);
    rootContext.scan("com.cfitzarl.cfjwed");

    // Create a dispatcher servlet that loads the application context
    DispatcherServlet dispatcherServlet = new DispatcherServlet();
    dispatcherServlet.setApplicationContext(rootContext);

    // Add the dispatcher servlet to the servlet context and map it to /
    ServletRegistration.Dynamic servletRegister = servletContext.addServlet("dispatcher", dispatcherServlet);
    servletRegister.setLoadOnStartup(1);
    servletRegister.addMapping("/");

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:com.tcloud.bee.key.server.jetty.config.WebAppInitializer.java

/**
 * Overrided to squelch a meaningless log message when embedded.
 *///  w w w.  j  a  v a 2 s . c om
@Override
protected void registerContextLoaderListener(ServletContext servletContext) {
    servletContext.addFilter("HiddenHttpMethodFilter",
            org.springframework.web.filter.HiddenHttpMethodFilter.class);
}