List of usage examples for javax.servlet ServletContext addFilter
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass);
From source file:io.gumga.security.WebConfigForTest.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages"); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);//from w ww . j a v a 2 s . c o m characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); rootContext.setServletContext(servletContext); rootContext.register(WebConfigForTest.class); rootContext.refresh(); }
From source file:net.rgielen.actionframeworks.struts2.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ApplicationConfig.class); servletContext.addListener(new ContextLoaderListener(context)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);/*from w ww. jav a2 s . c o m*/ characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); final FilterRegistration.Dynamic struts = servletContext.addFilter("struts", new StrutsPrepareAndExecuteFilter()); struts.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); }
From source file:com.tamnd.app.init.WebMvcInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Create the 'root' Spring application context WebApplicationContext context = context(); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(context)); DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", dispatcherServlet); dispatcher.setLoadOnStartup(1);//from w w w . j a v a 2 s. c o m dispatcher.addMapping(MAPPING_URL); servletContext .addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"/*Do not change this name*/)) .addMappingForUrlPatterns(null, false, "/*"); // servletContext.addFilter("hibernateFilter", new OpenSessionInViewFilter()) // .addMappingForUrlPatterns(null, false, "/*"); }
From source file:net.rgielen.actionframeworks.springmvc.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ApplicationConfig.class); servletContext.addListener(new ContextLoaderListener(context)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);//from w w w . j a v a 2 s . c o m characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); registration.setLoadOnStartup(1); registration.addMapping("/"); }
From source file:com.econcept.init.MainWebAppplicationInitializer.java
@Override public void onStartup(ServletContext pContainer) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext lRootContext = new AnnotationConfigWebApplicationContext(); lRootContext.scan("com.econcept.init"); // Manage the lifecycle of the root application context pContainer.addListener(new ContextLoaderListener(lRootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic lDispatcher = pContainer.addServlet("CFXServlet", CXFServlet.class); lDispatcher.addMapping("/rest/*"); // Apply Spring OAuthSecurity to both forward and request dispatcher FilterRegistration.Dynamic lFilter = pContainer.addFilter("unicodeFilter", new UnicodeFilter()); lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*"); // Apply Spring OAuthSecurity to both forward and request dispatcher lFilter = pContainer.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")); lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*"); pContainer.addListener(AppHttpSessionListener.class); }
From source file:com.nebhale.cyclinglibrary.web.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(UtilConfiguration.class, RepositoryConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); webContext.register(WebConfiguration.class); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(webContext)); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/"); FilterRegistration.Dynamic gzipFilter = servletContext.addFilter("gzip", new GzipFilter()); gzipFilter.addMappingForServletNames(null, false, "dispatcher"); FilterRegistration.Dynamic eTagFilter = servletContext.addFilter("etag", new ShallowEtagHeaderFilter()); eTagFilter.addMappingForServletNames(null, false, "dispatcher"); }
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);/*from w ww . java 2 s .com*/ 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.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 ww w .j av a2 s . c o 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.uoiu.platform.web.DefaultWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); // appContext.register(AppConfig.class); appContext.getEnvironment().setActiveProfiles("webapp"); servletContext.addListener(new ContextLoaderListener(appContext)); AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext)); dispatcher.setLoadOnStartup(1);/*ww w . ja va 2 s . c om*/ dispatcher.addMapping("/"); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", characterEncodingFilter()); encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); }
From source file:com.miserablemind.butter.bootstrap.AppInitializer.java
/** * Implements {@link WebApplicationInitializer} onStartup to initialize the system. * It registers and configures {@link RootContext}, {@link WebSecurityContext}, and app specific contexts. * It also initializes the {@link Log4jConfigListener}. * * @param container ServletContext//w ww . j a va2s . co m */ @Override public void onStartup(ServletContext container) { //Make the logger read settings from main properties file container.setInitParameter("log4jConfigLocation", "classpath:system.properties"); container.addListener(new Log4jConfigListener()); //Root Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootContext.class); container.addListener(new ContextLoaderListener(rootContext)); //Spring Security context AnnotationConfigWebApplicationContext securityContext = new AnnotationConfigWebApplicationContext(); securityContext.register(WebSecurityContext.class); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("springSecurityFilterChain"); container.addFilter("springSecurityFilterChain", filterProxy).addMappingForUrlPatterns(null, false, "*"); //Dispatcher Servlet context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(ButterAppMVCContext.class); //Register and map the dispatcher servlet DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic dispatcher = container.addServlet("mvc-dispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }