List of usage examples for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns);
From source file:com.jiwhiz.web.config.WebConfigurer.java
/** * Initializes the cachig HTTP Headers Filter. */// w w w.jav a2 s .co m private void initCachingHttpHeadersFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) { log.debug("Registering Caching HTTP Headers Filter"); FilterRegistration.Dynamic cachingHttpHeadersFilter = servletContext.addFilter("cachingHttpHeadersFilter", new CachingHttpHeadersFilter()); cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/images/*"); cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/fonts/*"); cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/scripts/*"); cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/styles/*"); cachingHttpHeadersFilter.setAsyncSupported(true); }
From source file:io.paradoxical.cassieq.ServiceConfigurator.java
private void enableCors(ServiceConfiguration config, Environment environment) { FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, environment.getApplicationContext().getContextPath() + "*"); filter.setInitParameter("allowedOrigins", String.join(",", config.getWeb().getAllowedOrigins())); // allowed origins comma separated filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); filter.setInitParameter("allowedMethods", "GET,PUT,POST,DELETE,OPTIONS"); }
From source file:com.dm.estore.config.WebAppInitializer.java
private void registerFilters(ServletContext servletContext) { FilterRegistration.Dynamic securityFilter = servletContext.addFilter(SECURITY_FILTER_NAME, new DelegatingFilterProxy()); securityFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, REST_SERVLET_MAPPING); securityFilter.setAsyncSupported(true); FilterRegistration.Dynamic applicationFilter = servletContext.addFilter(APP_FILTER_NAME, new ApplicationFilter()); applicationFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, APP_FILTER_MAPPING);//from w w w .j a v a 2 s . c om applicationFilter.setAsyncSupported(true); }
From source file:com.tcloud.bee.key.server.jetty.config.WebAppInitializer.java
private void configureEncodingFilter(ServletContext servletContext) { CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(false); FilterRegistration.Dynamic encodingFilterDinamic = servletContext.addFilter("charEncodingFilter", encodingFilter);//from w w w .j a va2 s .c o m encodingFilterDinamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }
From source file:com.tcloud.bee.key.server.jetty.config.WebAppInitializer.java
/** * Register Spring Security/*from w w w . java2 s. c o m*/ * * @param servletContext */ private void configureSpringSecurityFilter(ServletContext servletContext) { DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("springSecurityFilterChain"); FilterRegistration.Dynamic securityFilterDynamic = servletContext.addFilter("securityFilter", delegatingFilterProxy); securityFilterDynamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }
From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Create the root appcontext AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfig.class); rootContext.register(PersistenceConfig.class); // Manage the lifecycle of the root appcontext servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); this.zkLoaderServlet(servletContext); // now the config for the Dispatcher servlet AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(WebMvcConfig.class); // Filters// www.j a va2 s . c om // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/package-summary.html // Enables support for DELETE and PUT request methods with web browser // clients // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/HiddenHttpMethodFilter.html FilterRegistration.Dynamic fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter()); fr.addMappingForUrlPatterns(null, true, "/*"); fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); fr.addMappingForUrlPatterns(null, true, "/*"); // The main Spring MVC servlet. ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(2); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } HttpSessionListener zkCleanUp = new HttpSessionListener(); servletContext.addListener(zkCleanUp); this.logbackServlet(servletContext); this.zkUpdateServlet(servletContext); }
From source file:com.jiwhiz.web.config.WebConfigurer.java
/** * Initializes the static resources production Filter. *//* w w w. j a v a 2 s . c om*/ private void initStaticResourcesProductionFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) { log.debug("Registering static resources production Filter"); FilterRegistration.Dynamic staticResourcesProductionFilter = servletContext .addFilter("staticResourcesProductionFilter", new StaticResourcesProductionFilter()); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/index.html"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/images/*"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/fonts/*"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/scripts/*"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/styles/*"); staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/views/*"); staticResourcesProductionFilter.setAsyncSupported(true); }
From source file:com.techtrip.dynbl.context.config.WebAppinitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component} // Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject} AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); //context.setConfigLocation(APP_CONFIG_LOCATION); context.setConfigLocation(APP_CONFIG_LOCATION); /* // w w w.j av a 2s .co m * Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered * and configured with the specified context */ /* FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue())); securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied */ // Add a Character Encoding Filter that specifies an encoding for mapped requests FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString()); characterEncodingFilter.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(context)); servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString()); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); /* TMT From JEE 6 API Docs: * Registers the given servlet instance with this ServletContext under the given servletName. * The registered servlet may be further configured via the returned ServletRegistration object. */ ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet); appServlet.setLoadOnStartup(1); appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException(String.format( "The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET)); } // TMT servletContext.addListener(new Log4jConfigListener()); System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion()); }
From source file:org.fon.documentmanagementsystem.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.setServletContext(servletContext); ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1);/* ww w. j ava2s . c o m*/ servlet.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024 * 25, 1024 * 1024 * 25, 0)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); }
From source file:com.kabiliravi.kaman.web.KamanApplicationInitializer.java
private void registerSpringSecurityFilterChain(ServletContext servletContext) { FilterRegistration.Dynamic springSecurityFilterChain = servletContext .addFilter(BeanIds.SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy()); springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*"); }