List of usage examples for org.springframework.web.servlet DispatcherServlet DispatcherServlet
public DispatcherServlet(WebApplicationContext webApplicationContext)
From source file:cz.muni.fi.editor.webapp.config.init.EditorApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { String bootLogo = " __ __ _ _ _ _ _ _ \n" + " | \\/ | | | | | | | | (_) | \n" + " | \\ / | ___| |_ __ _ __| | __ _| |_ __ _ ___ __| |_| |_ ___ _ __ \n" + " | |\\/| |/ _ \\ __/ _` |/ _` |/ _` | __/ _` | / _ \\/ _` | | __/ _ \\| '__|\n" + " | | | | __/ || (_| | (_| | (_| | || (_| | | __/ (_| | | || (_) | | \n" + " |_| |_|\\___|\\__\\__,_|\\__,_|\\__,_|\\__\\__,_| \\___|\\__,_|_|\\__\\___/|_| \n" + " \n" + " "; System.out.println(ANSI_YELLOW + bootLogo + ANSI_RESET); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().setActiveProfiles("production"); rootContext.register(WebAppConfiguration.class, SecurityConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class, WebSocketSecurityConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);/*from ww w . j ava2 s. c o m*/ dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true)) .addMappingForUrlPatterns(null, false, "/*"); servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); }
From source file:org.bonitasoft.web.designer.SpringWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { for (String line : BANNER) { logger.info(line);//from w ww . j a v a 2 s. c o m } logger.info(Strings.repeat("=", 100)); logger.info(String.format("UI-DESIGNER : %s edition v.%s", prop.getProperty("designer.edition"), prop.getProperty("designer.version"))); logger.info(Strings.repeat("=", 100)); // Create the root context Spring AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(new Class<?>[] { ApplicationConfig.class }); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(rootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir"))); dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); }
From source file:io.springagora.store.AppInitializer.java
/** * Web Application./* ww w.j a v a 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.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()); }/* w ww . j a v a2 s .c o 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:net.ljcomputing.sr.config.StatusReporterWebConfiguration.java
/** * @see org.springframework.boot.context.web.SpringBootServletInitializer#onStartup(javax.servlet.ServletContext) *//*from w ww. j av a 2 s . c o m*/ public void onStartup(ServletContext container) throws ServletException { logger.info("onStartup ..."); AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(StatusReporterWebConfiguration.class); ctx.setServletContext(container); DispatcherServlet ds = new DispatcherServlet(ctx); ServletRegistration.Dynamic servlet = container.addServlet("dispatcherServlet", ds); servlet.setInitParameter("throwExceptionIfNoHandlerFound", "true"); servlet.setLoadOnStartup(1); servlet.addMapping("/"); logger.warn("servlet name: {}", servlet.getName()); logger.warn("servlet throwExceptionIfNoHandlerFound: {}", servlet.getInitParameter("throwExceptionIfNoHandlerFound")); }
From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java
private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) { AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MvcConfig.class); mvcContext.setParent(rootContext);// w ww .ja v a2 s . c om ServletRegistration.Dynamic appServlet = servletContext.addServlet("reconciliation-service", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(1); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { log.error("Mapping conflict: " + s); } throw new IllegalStateException("'webservice' cannot be mapped to '/'"); } }
From source file:org.lightadmin.core.config.LightAdminWebApplicationInitializer.java
private void registerLightAdminDispatcher(final ServletContext servletContext) { final AnnotationConfigWebApplicationContext webApplicationContext = lightAdminApplicationContext( servletContext);/*from w w w . j a v a 2 s. co m*/ final DispatcherServlet lightAdminDispatcher = new DispatcherServlet(webApplicationContext); lightAdminDispatcher.setDetectAllViewResolvers(false); ServletRegistration.Dynamic lightAdminDispatcherRegistration = servletContext .addServlet(LIGHT_ADMIN_DISPATCHER_NAME, lightAdminDispatcher); lightAdminDispatcherRegistration.setLoadOnStartup(3); lightAdminDispatcherRegistration.addMapping(dispatcherUrlMapping(lightAdminBaseUrl(servletContext))); }
From source file:com.dm.estore.config.WebAppInitializer.java
private void registerServlets(ServletContext servletContext) { // Enable Spring Data REST in the DispatcherServlet AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); webCtx.register(RestAPIModule.class); // REST API dispatcher DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); ServletRegistration.Dynamic restDispatcher = servletContext.addServlet("restAPI", dispatcherServlet); restDispatcher.setLoadOnStartup(1);/*www. j a v a 2s. c o m*/ restDispatcher.setAsyncSupported(true); restDispatcher.addMapping(REST_SERVLET_MAPPING); }
From source file:net.swigg.talo.TaloCacheBootstrap.java
private Handler createAdminHandler(WebApplicationContext context) { ServletContextHandler contextHandler = new ServletContextHandler(); contextHandler.setErrorHandler(null); contextHandler.setContextPath("/"); ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(context)); contextHandler.addServlet(servletHolder, "/*"); contextHandler.addEventListener(new ContextLoaderListener(context)); return contextHandler; }
From source file:io.springagora.store.AppInitializer.java
/** * RESTful API.//from w w w .j a va 2 s .co 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); }