Example usage for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns

List of usage examples for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns

Introduction

In this page you can find the example usage for javax.servlet FilterRegistration.Dynamic 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:org.obiba.mica.config.WebConfiguration.java

/**
 * Initializes Metrics.//from  w  w  w .ja v a  2  s.co  m
 */
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
            new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet = servletContext.addServlet("metricsServlet",
            new MetricsServlet());

    metricsAdminServlet.addMapping("/jvm/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
}

From source file:org.obiba.mica.config.WebConfiguration.java

/**
 * Initializes the caching HTTP Headers Filter.
 *///from   w  w  w.j  a  va2  s . co m
private void initCachingHttpHeadersFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering Caching HTTP Headers Filter");
    FilterRegistration.Dynamic cachingFilter = servletContext.addFilter("cachingHttpHeadersFilter",
            new CachingHttpHeadersFilter());

    cachingFilter.addMappingForUrlPatterns(disps, true, "/images/*");
    cachingFilter.addMappingForUrlPatterns(disps, true, "/fonts/*");
    cachingFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
    cachingFilter.addMappingForUrlPatterns(disps, true, "/styles/*");
    cachingFilter.setAsyncSupported(true);
}

From source file:fr.univlorraine.mondossierweb.Initializer.java

/**
 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
 *//*from   ww w.j a v a2s .  co m*/
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    addContextParametersToSystemProperties(servletContext);

    /* Configure les sessions */
    Set<SessionTrackingMode> sessionTrackingModes = new HashSet<SessionTrackingMode>();
    sessionTrackingModes.add(SessionTrackingMode.COOKIE);
    servletContext.setSessionTrackingModes(sessionTrackingModes);
    servletContext.addListener(new HttpSessionListener() {
        @Override
        public void sessionCreated(HttpSessionEvent httpSessionEvent) {
            // sans nouvelle requte, on garde la session active 4 minutes
            httpSessionEvent.getSession().setMaxInactiveInterval(240);
        }

        @Override
        public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        }
    });
    /* Gestion des sessions dans Atmosphere (Push Vaadin) */
    servletContext.addListener(SessionSupport.class);

    /* Configure Spring */
    AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    if (!Boolean.valueOf(servletContext.getInitParameter(Constants.SERVLET_PARAMETER_PRODUCTION_MODE))) {
        springContext.getEnvironment().setActiveProfiles(DEBUG_PROFILE);
    }
    springContext.register(SpringConfig.class);
    servletContext.addListener(new ContextLoaderListener(springContext));
    servletContext.addListener(new RequestContextListener());

    /* Filtre Spring Security */
    FilterRegistration.Dynamic springSecurityFilterChain = servletContext.addFilter("springSecurityFilterChain",
            DelegatingFilterProxy.class);
    springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");

    /* Filtre passant l'utilisateur courant  Logback */
    FilterRegistration.Dynamic userMdcServletFilter = servletContext.addFilter("userMdcServletFilter",
            UserMdcServletFilter.class);
    userMdcServletFilter.addMappingForUrlPatterns(null, false, "/*");

    /* Filtre Spring Mobile permettant de dtecter le device */
    FilterRegistration.Dynamic springMobileServletFilter = servletContext
            .addFilter("deviceResolverRequestFilter", DeviceResolverRequestFilter.class);
    springMobileServletFilter.addMappingForUrlPatterns(null, false, "/*");

    /* Servlet Spring-Vaadin */
    //ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin", JMeterServlet.class);
    //ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin", SpringVaadinServlet.class);
    ServletRegistration.Dynamic springVaadinServlet = servletContext.addServlet("springVaadin",
            fr.univlorraine.mondossierweb.utils.MdwSpringVaadinServlet.class);
    springVaadinServlet.setLoadOnStartup(1);
    springVaadinServlet.addMapping("/*");
    /* Dfini le bean UI */
    //springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_UI_PROVIDER, "fr.univlorraine.mondossierweb.MdwUIProvider");
    /* Utilise les messages Spring pour les messages d'erreur Vaadin (cf. http://vaadin.xpoft.ru/#system_messages) */
    springVaadinServlet.setInitParameter("systemMessagesBeanName", "DEFAULT");
    /* Dfini la frquence du heartbeat en secondes (cf. https://vaadin.com/book/vaadin7/-/page/application.lifecycle.html#application.lifecycle.ui-expiration) */
    springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, String.valueOf(30));

    /* Configure le Push */
    springVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_PUSH_MODE,
            Boolean.valueOf(servletContext.getInitParameter("enablePush")) ? PushMode.AUTOMATIC.name()
                    : PushMode.DISABLED.name());

    /* Active le support des servlet 3 et des requtes asynchrones (cf. https://vaadin.com/wiki/-/wiki/Main/Working+around+push+issues) */
    springVaadinServlet.setInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT_SERVLET3, String.valueOf(true));
    /* Active le support des requtes asynchrones */
    springVaadinServlet.setAsyncSupported(true);
    /* Ajoute l'interceptor Atmosphere permettant de restaurer le SecurityContext dans le SecurityContextHolder (cf. https://groups.google.com/forum/#!msg/atmosphere-framework/8yyOQALZEP8/ZCf4BHRgh_EJ) */
    springVaadinServlet.setInitParameter(ApplicationConfig.ATMOSPHERE_INTERCEPTORS,
            RecoverSecurityContextAtmosphereInterceptor.class.getName());

    /* Spring-Vaadin Touchkit Servlet  */
    ServletRegistration.Dynamic springTouchkitVaadinServlet = servletContext.addServlet("springTouchkitVaadin",
            MDWTouchkitServlet.class);
    //springTouchkitVaadinServlet.setLoadOnStartup(1);
    springTouchkitVaadinServlet.addMapping("/m/*");
    /* Dfini le bean UI */
    //springTouchkitVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_UI_PROVIDER, "fr.univlorraine.mondossierweb.MdwTouchkitUIProvider");
    /* Utilise les messages Spring pour les messages d'erreur Vaadin (cf. http://vaadin.xpoft.ru/#system_messages) */
    springTouchkitVaadinServlet.setInitParameter("systemMessagesBeanName", "DEFAULT");
    springTouchkitVaadinServlet.setInitParameter(Constants.PARAMETER_WIDGETSET,
            "fr.univlorraine.mondossierweb.AppWidgetset");

    /* Configure le Push */
    springTouchkitVaadinServlet.setInitParameter(Constants.SERVLET_PARAMETER_PUSH_MODE,
            PushMode.DISABLED.name());
    /* Active le support des servlet 3 et des requtes asynchrones (cf. https://vaadin.com/wiki/-/wiki/Main/Working+around+push+issues) */
    springTouchkitVaadinServlet.setInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT_SERVLET3,
            String.valueOf(true));
    /* Active le support des requtes asynchrones */
    springTouchkitVaadinServlet.setAsyncSupported(true);
    /* Ajoute l'interceptor Atmosphere permettant de restaurer le SecurityContext dans le SecurityContextHolder (cf. https://groups.google.com/forum/#!msg/atmosphere-framework/8yyOQALZEP8/ZCf4BHRgh_EJ) */
    springTouchkitVaadinServlet.setInitParameter(ApplicationConfig.ATMOSPHERE_INTERCEPTORS,
            RecoverSecurityContextAtmosphereInterceptor.class.getName());

}

From source file:org.hdiv.spring.boot.autoconfigure.HdivAutoConfiguration.java

@Bean
public ServletContextInitializer validatorFilter() {
    ServletContextInitializer initializer = new ServletContextInitializer() {

        public void onStartup(ServletContext servletContext) throws ServletException {

            // Register HDIV InitListener and ValidatorFilter

            // InitListener
            servletContext.addListener(new InitListener());

            // ValidatorFilter
            FilterRegistration.Dynamic registration = servletContext.addFilter("validatorFilter",
                    new ValidatorFilter());
            EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST);
            // isMatchAfter false to put it before existing filters
            registration.addMappingForUrlPatterns(dispatcherTypes, false, "/*");
        }//from  w w w  .j  av a  2 s .  c o m
    };
    return initializer;
}

From source file:org.obiba.mica.config.WebConfiguration.java

/**
 * Initializes the static resources production Filter.
 *///  w w w.  j a v  a 2  s .  c o  m
private void initStaticResourcesProductionFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {

    log.debug("Registering static resources production Filter");
    FilterRegistration.Dynamic resourcesFilter = servletContext.addFilter("staticResourcesProductionFilter",
            new StaticResourcesProductionFilter());

    resourcesFilter.addMappingForUrlPatterns(disps, true, "/favicon.ico");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/robots.txt");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/index.html");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/images/*");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/fonts/*");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/styles/*");
    resourcesFilter.addMappingForUrlPatterns(disps, true, "/views/*");
    resourcesFilter.setAsyncSupported(true);
}

From source file:org.smigo.config.WebAppInitializer.java

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
    super.beforeSpringSecurityFilterChain(servletContext);
    log.info("Starting servlet context");
    log.info("contextName: " + servletContext.getServletContextName());
    log.info("contextPath:" + servletContext.getContextPath());
    log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion());
    log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion());
    log.info("majorVersion:" + servletContext.getMajorVersion());
    log.info("minorVersion:" + servletContext.getMinorVersion());
    log.info("serverInfo:" + servletContext.getServerInfo());
    //               ", virtualServerName:" + servletContext.getVirtualServerName() +
    log.info("toString:" + servletContext.toString());

    for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) {
        log.info("Attribute:" + e.nextElement());
    }//from w  w  w. ja  v a2s  .co  m
    for (Map.Entry<String, String> env : System.getenv().entrySet()) {
        log.info("System env:" + env.toString());
    }
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        log.info("System prop:" + prop.toString());
    }

    final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION);
    log.info("Starting with profile " + profile);

    WebApplicationContext context = new AnnotationConfigWebApplicationContext() {
        {
            register(WebConfiguration.class);
            setDisplayName("SomeRandomName");
            getEnvironment().setActiveProfiles(profile);
        }
    };

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    servletContext.addListener(new RequestContextListener());
    servletContext.addListener(new ContextLoaderListener(context));

    //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains
    //        servletContext.getSessionCookieConfig().setDomain(getDomain());

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(false);
    servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/");
}

From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) {
    WebApplicationContext rootContext = createRootContext(servletContext);

    configureSpringMvc(servletContext, rootContext);

    // Add Perf4J graphing servlet
    ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("perf4j",
            org.perf4j.logback.servlet.GraphingServlet.class);
    servletRegistration.setInitParameter("graphNames", "graphOtherTimes,graphQueryTimes,graphQueriesPerSecond");
    servletRegistration.addMapping("/perf4j");

    String TAG_SWAP_FILTER_CLASS = "org.kew.servlet.filter.TagSwapFilter";
    try {//from  www.  ja  va2s.  co  m
        Class.forName(TAG_SWAP_FILTER_CLASS, false, this.getClass().getClassLoader());
        String[] urlPatterns = { "/", "/about/*", "/admin", "/filematch/*", "/help" };

        FilterRegistration.Dynamic cssLinkFilter = servletContext.addFilter("CssLinkFilter",
                TAG_SWAP_FILTER_CLASS);
        cssLinkFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/head.chunk");
        cssLinkFilter.setInitParameter("tag_name", "[KEWCSS]");
        cssLinkFilter.addMappingForUrlPatterns(null, true, urlPatterns);

        FilterRegistration.Dynamic headerFilter = servletContext.addFilter("HeaderFilter",
                TAG_SWAP_FILTER_CLASS);
        headerFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/bodytop.chunk");
        headerFilter.setInitParameter("tag_name", "[KEWHEADER]");
        headerFilter.addMappingForUrlPatterns(null, true, urlPatterns);

        FilterRegistration.Dynamic footerFilter = servletContext.addFilter("FooterFilter",
                TAG_SWAP_FILTER_CLASS);
        footerFilter.setInitParameter("include_file_name",
                "/var/lib/science-apps/web-resources/bodybottom.chunk");
        footerFilter.setInitParameter("tag_name", "[KEWFOOTER]");
        footerFilter.addMappingForUrlPatterns(null, true, urlPatterns);
    } catch (ClassNotFoundException e) {
        log.error("Kew servlet filters not in use, class {} not on classpath", TAG_SWAP_FILTER_CLASS);
    }
}

From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java

protected void registerCubaHttpFilter(ServletContext servletContext) {
    CubaHttpFilter cubaHttpFilter = new CubaHttpFilter();
    FilterRegistration.Dynamic cubaHttpFilterReg = servletContext.addFilter("CubaHttpFilter", cubaHttpFilter);
    cubaHttpFilterReg.setAsyncSupported(true);
    cubaHttpFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}

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

/**
 * Register JerseyServlet Config/* ww  w. ja  v a  2s. co m*/
 * 
 * @param servletContext
 */
private void configurationJersey(ServletContext servletContext) {

    FilterRegistration.Dynamic filterDinamic = servletContext.addFilter("jersey",
            new org.glassfish.jersey.servlet.ServletContainer());
    filterDinamic.setInitParameter("javax.ws.rs.Application",
            "org.apache.hadoop.io.crypto.bee.key.server.jetty.config.JerseyApplicationConfig");
    filterDinamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/api/*");
}

From source file:io.soabase.core.SoaBundle.java

private void checkCorsFilter(SoaConfiguration configuration, ServletEnvironment servlets) {
    if (configuration.isAddCorsFilter()) {
        // from http://jitterted.com/tidbits/2014/09/12/cors-for-dropwizard-0-7-x/

        FilterRegistration.Dynamic filter = servlets.addFilter("CORS", CrossOriginFilter.class);
        filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
        filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
        filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
        filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
        filter.setInitParameter("allowedHeaders",
                "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
        filter.setInitParameter("allowCredentials", "true");
    }//from   www.  j  a  va2 s . c om
}