List of usage examples for javax.servlet ServletRegistration.Dynamic addMapping
public Set<String> addMapping(String... urlPatterns);
From source file:com.mycompany.testeproject.App.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = getContext(); servletContext.addListener(new ContextLoaderListener(context)); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1);//from ww w . j ava 2s. c o m dispatcher.addMapping("/rest/*"); }
From source file:net.przemkovv.sphinx.config.ApplicationInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfig.class, JpaConfig.class); // rootContext.refresh(); rootContext.setDisplayName("Sphinx Web Application"); servletContext.addListener(new ContextLoaderListener(rootContext)); // servletContext.addListener(new HttpSessionEventPublisher()); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(WebMvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Spring MVC Servlet", new DispatcherServlet(dispatcherContext)); dispatcher.addMapping("/app/"); dispatcher.setLoadOnStartup(1);//from w w w .ja v a2s . co m // servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")) // .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); servletContext.addFilter("UrlRewriteFilter", new UrlRewriteFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpPutFormContentFilter", new HttpPutFormContentFilter()) .addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic charsetFilter = servletContext.addFilter("charsetFilter", new CharacterEncodingFilter()); charsetFilter.setInitParameter("encoding", "UTF-8"); charsetFilter.setInitParameter("forceEncoding", "true"); charsetFilter.addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic dustCompilingFilter = servletContext.addFilter("dustCompilingFilter", new DustCompilingFilter()); dustCompilingFilter.setInitParameter("templateNameRegex", "/template/(.*).dust.js$"); dustCompilingFilter.addMappingForUrlPatterns(null, true, "/*"); }
From source file:io.springagora.store.AppInitializer.java
/** * RESTful API.//from www .ja v a 2 s . c o m * * @param container * {@code ServletContext}. Representation of the context that is serving * the JEE application. Servlets, filters and listeners are registered * via this interface. */ private void initializeRESTfulAPI(ServletContext container) { AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(RestConfig.class); DispatcherServlet restDispatcher = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic servletReg = container.addServlet(dispatcherRestName, restDispatcher); servletReg.setLoadOnStartup(2); servletReg.addMapping(URL_PATTERN_REST); }
From source file:org.osgpfoundation.osgp.webdemoapp.application.config.WebDemoInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {//ww w . j a va2s.c o m TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); servletContext.addListener(new ContextLoaderListener(rootContext)); } catch (final NamingException e) { throw new ServletException("naming exception", e); } }
From source file:gt.dakaik.config.AppConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { ConfiguracionLogs.agregarLlave();/* w w w. jav a2 s . co m*/ AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootContext.class); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.setServletContext(servletContext); dispatcherContext.setParent(rootContext); dispatcherContext.register(WebContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); FilterRegistration.Dynamic FiltroLogs = servletContext.addFilter(FILTER_LOGGING, new FiltroLogs()); FiltroLogs.addMappingForUrlPatterns(null, true, FILTER_LOGGING_MAPPING); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:io.springagora.store.AppInitializer.java
/** * Web Application.//from w w w .j ava 2 s . c om * * @param container * {@code ServletContext}. Representation of the context that is serving * the JEE application. Servlets, filters and listeners are registered * via this interface. */ private void initializeWebApplication(ServletContext container) { AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(WebConfig.class); DispatcherServlet webDispatcher = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic servletReg = container.addServlet(dispatcherWebName, webDispatcher); servletReg.setLoadOnStartup(1); servletReg.addMapping(URL_PATTERN_WEB); HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter(); FilterRegistration.Dynamic filterReg = container.addFilter("Hidden HTTP Method Filter", filter); filterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, dispatcherWebName); }
From source file:org.jboss.arquillian.spring.testsuite.beans.web.EmployeeWebRootInitializer.java
/** * {@inheritDoc}//from w w w. j a v a 2 s.c o m */ public void onStartup(ServletContext servletContext) throws ServletException { // creates the web root app context AnnotationConfigWebApplicationContext webRootContext = new AnnotationConfigWebApplicationContext(); webRootContext.register(WebAppConfig.class); // registers context load listener servletContext.addListener(new ContextLoaderListener(webRootContext)); // adds a dispatch servlet, the servlet will be configured from root web app context ServletRegistration.Dynamic servletConfig = servletContext.addServlet("employee", new DispatcherServlet(new AnnotationConfigWebApplicationContext())); servletConfig.setLoadOnStartup(1); servletConfig.addMapping("*.htm"); }
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 w w . ja va 2s .com*/ 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:fr.treeptik.cloudunit.initializer.ApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CloudUnitApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);//from w w w . j ava 2 s . co m dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); dispatcher.setAsyncSupported(true); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/nopublic/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:com.consol.citrus.simulator.WebAppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/citrus-servlet-context.xml"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("citrus", new MessageDispatcherServlet()); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/simulator"); dispatcherServlet.addMapping("/simulator/*"); dispatcherServlet.setInitParameter("contextConfigLocation", ""); ServletRegistration.Dynamic statusServlet = servletContext.addServlet("status", new SimulatorStatusServlet()); statusServlet.setLoadOnStartup(1000); statusServlet.addMapping("/status"); statusServlet.addMapping("/status/*"); ServletRegistration.Dynamic runServlet = servletContext.addServlet("run", new SimulatorRunServlet()); runServlet.setLoadOnStartup(1000);// w w w.j a v a2 s . c om runServlet.addMapping("/run"); runServlet.addMapping("/run/*"); ServletRegistration.Dynamic resourceServlet = servletContext.addServlet("resource", new StaticResourceServlet()); resourceServlet.setLoadOnStartup(1000); resourceServlet.addMapping("/info"); resourceServlet.addMapping("/info/*"); servletContext.addListener(new ContextLoaderListener(appContext)); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(System.getProperty("file.encoding", "UTF-8")); encodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filter = servletContext.addFilter("encoding-filter", encodingFilter); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }