Example usage for javax.servlet FilterRegistration addMappingForUrlPatterns

List of usage examples for javax.servlet FilterRegistration addMappingForUrlPatterns

Introduction

In this page you can find the example usage for javax.servlet FilterRegistration addMappingForUrlPatterns.

Prototype

public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
        String... urlPatterns);

Source Link

Document

Adds a filter mapping with the given url patterns and dispatcher types for the Filter represented by this FilterRegistration.

Usage

From source file:com.dm.platform.listener.base.MyServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("MyServletContextListener");
    ServletContext sc = sce.getServletContext();

    ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class);
    sr.setInitParameter("contextConfigLocation", "/WEB-INF/dispatcher-servlet.xml");
    sr.addMapping("/spring/*");

    FilterRegistration fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");
    //          fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(), DelegatingFilterProxy.class);
    //        fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");

    sc.addListener(new ContextLoaderListener());
}

From source file:com.dm.platform.listener.PlatformServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("contextInitialized");

    ServletContext sc = sce.getServletContext();
    sc.setInitParameter("contextConfigLocation", "/WEB-INF/applicationContext.xml");
    //    sc.addListener(ContextLoaderListener.class);
    FilterRegistration fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(),
            DelegatingFilterProxy.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/spring/*");

    ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class);
    sr.setInitParameter("contextConfigLocation",
            "/WEB-INF/dispatcher-servlet.xml /WEB-INF/platform-security.xml");
    sr.addMapping("/spring/*");

    fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");

}

From source file:com.gosmarter.it.eis.config.ExcelERPWebApplicationInitializer.java

private void registerSpringSecurityFilterChain(ServletContext servletContext) {
    DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration fr = servletContext.addFilter("securityFilter", delegatingFilterProxy);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");
}

From source file:com.coffeebeans.services.config.initializer.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppConfig.class);
    servletContext.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet(MVC_DISPATCHER_NAME,
            new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);//from  w  ww .  jav  a2 s .co  m
    dispatcher.addMapping("/1/*");
    dispatcher.addMapping("/oauth/token");

    FilterRegistration charEncodingFilterReg = servletContext.addFilter("CharacterEncodingFilter",
            CharacterEncodingFilter.class);
    charEncodingFilterReg.setInitParameter("encoding", "UTF-8");
    charEncodingFilterReg.setInitParameter("forceEncoding", "true");
    charEncodingFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), 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());

}