List of usage examples for javax.servlet ServletContext addFilter
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass);
From source file:org.lightadmin.logging.configurer.LightConfigurerWebApplicationInitializer.java
private void registerHiddenHttpMethodFilter(final ServletContext servletContext, LoggingConfigurerSettings configuration) { final String urlMapping = urlMapping(configuration.getApplicationBaseUrl()); servletContext.addFilter("LightConfigurerHiddenHttpMethodFilter", HiddenHttpMethodFilter.class) .addMappingForUrlPatterns(null, false, urlMapping); }
From source file:com.indeed.imhotep.web.config.WebApp.java
private void initCharacterEncodingFilter(final ServletContext servletContext) { final CharacterEncodingFilter utf8 = new CharacterEncodingFilter(); utf8.setEncoding("utf-8"); utf8.setForceEncoding(true);//from w w w. ja v a 2 s . com servletContext.addFilter("SetCharacterEncodingFilter", utf8).addMappingForUrlPatterns(null, false, "/*"); }
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.tcloud.bee.key.server.jetty.config.WebAppInitializer.java
/** * Register Spring Security/*from w w w. ja va 2s.co 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:cn.ifast.oauth2server.config.ServletInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain"); filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher"); servletContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, false, "/*"); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerClassLoaderFilter(ServletContext servletContext) { FilterRegistration.Dynamic filterReg = servletContext.addFilter("WebSingleWarHttpFilter", new SetClassLoaderFilter()); filterReg.setAsyncSupported(true);//w w w .j a v a2 s .co m filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/dispatch/*"); filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/rest/*"); }
From source file:ua.com.rocketlv.spb.Application.java
@Bean public ServletContextInitializer servletContextInitializer() { return (ServletContext servletContext) -> { final CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(false); // TODO Blog servletContext.addFilter("characterEncodingFilter", characterEncodingFilter) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); };/* w w w .j a v a 2 s. c o m*/ }
From source file:com.local.ask.controller.WebAppInitializer.java
@Override public void onStartup(ServletContext container) { CharacterEncodingFilter encodingFilter = new org.springframework.web.filter.CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(false); FilterRegistration.Dynamic encodingFilterDinamic = container.addFilter("charEncodingFilter", encodingFilter);/*from w ww . j a v a2 s. c o m*/ encodingFilterDinamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfig.class); rootContext.register(SecurityConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(HomeController.class); dispatcherContext.register(LoginController.class); dispatcherContext.register(PostController.class); dispatcherContext.register(SignUpController.class); dispatcherContext.register(ContactUsController.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.setTargetFilterLifecycle(true); container.addFilter("shiroFilter", filterProxy).addMappingForUrlPatterns(null, false, "/*"); // encoding filter }
From source file:org.lightadmin.core.config.LightAdminWebApplicationInitializer.java
private void registerGZipFilter(ServletContext servletContext, String... urlMappings) { GzipFilter gzipFilter = new GzipFilter(); servletContext.addFilter("lightAdminGzipFilter", gzipFilter).addMappingForUrlPatterns(null, false, urlMappings);//from w ww. j ava 2 s. c om }