List of usage examples for javax.servlet ServletContext addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass);
From source file:com.oreilly.springdata.rest.RestWebApplicationInitializer.java
public void onStartup(ServletContext container) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Register and map the dispatcher servlet DispatcherServlet servlet = new RepositoryRestExporterServlet(); ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", servlet); dispatcher.setLoadOnStartup(1);// ww w . j av a 2 s .c om dispatcher.addMapping("/"); }
From source file:gt.dakaik.config.AppConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { ConfiguracionLogs.agregarLlave();//from w w w .j a v a 2 s . c om 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:org.homiefund.init.WebAppBoostrapper.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfiguration.class, SecurityConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.addListener(new RequestContextListener()); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);//from w ww . j a va 2 s. c om 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.lightadmin.core.config.LightAdminWebApplicationInitializer.java
private void registerLightAdminDispatcher(final ServletContext servletContext) { final AnnotationConfigWebApplicationContext webApplicationContext = lightAdminApplicationContext( servletContext);/*from w w w. j a va 2s. 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.googlecode.jeeunit.example.spring.web.LibraryWebApplicationInitializer.java
@Override public void onStartup(ServletContext sc) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().addActiveProfile("web"); rootContext.register(WebSpringConfig.class); sc.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.setParent(rootContext); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(2);/* www . j av a 2 s .c o m*/ dispatcher.addMapping("*.html"); dispatcher.addMapping("*.form"); dispatcher.addMapping("*.ajax"); }
From source file:com.sishuok.chapter2.initializer.NoXmlWebAppInitializer.java
@Override public void onStartup(final ServletContext sc) throws ServletException { //1?//from ww w . j a v a 2 s.com AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfiguration.class); sc.addListener(new ContextLoaderListener(rootContext)); //2?springmvc AnnotationConfigWebApplicationContext springMvcContext = new AnnotationConfigWebApplicationContext(); springMvcContext.register(SpringMvcConfiguration.class); //3?DispatcherServlet DispatcherServlet dispatcherServlet = new DispatcherServlet(springMvcContext); ServletRegistration.Dynamic dynamic = sc.addServlet("dispatcherServlet", dispatcherServlet); dynamic.setLoadOnStartup(1); dynamic.addMapping("/"); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerRestApiServlet(ServletContext servletContext) { CubaRestApiServlet cubaRestApiServlet = new SingleAppRestApiServlet(dependencyJars); try {//from w w w .j a va 2 s . c o m cubaRestApiServlet.init(new CubaServletConfig("rest_api", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing dispatcher servlet", e); } ServletRegistration.Dynamic cubaRestApiServletReg = servletContext.addServlet("rest_api", cubaRestApiServlet); cubaRestApiServletReg.setLoadOnStartup(2); cubaRestApiServletReg.addMapping("/rest/*"); DelegatingFilterProxy restSpringSecurityFilterChain = new DelegatingFilterProxy(); restSpringSecurityFilterChain .setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.rest_api"); restSpringSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); FilterRegistration.Dynamic restSpringSecurityFilterChainReg = servletContext .addFilter("restSpringSecurityFilterChain", restSpringSecurityFilterChain); restSpringSecurityFilterChainReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/rest/*"); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerDispatchServlet(ServletContext servletContext) { CubaDispatcherServlet cubaDispatcherServlet = new SingleAppDispatcherServlet(dependencyJars); try {//from ww w.ja v a 2 s . co m cubaDispatcherServlet.init(new CubaServletConfig("dispatcher", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing dispatcher servlet", e); } ServletRegistration.Dynamic cubaDispatcherServletReg = servletContext.addServlet("dispatcher", cubaDispatcherServlet); cubaDispatcherServletReg.setLoadOnStartup(1); cubaDispatcherServletReg.addMapping("/dispatch/*"); }
From source file:com.mycompany.spring2explore.config.WebAppInitializer.java
@Override public void onStartup(ServletContext cs) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringRootConfig.class); // Manage the lifecycle of the root application context cs.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(MvcConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = cs.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1);/*from w w w .j a v a 2 s . c o m*/ dispatcher.addMapping("/"); }
From source file:com.dominion.salud.mpr.configuration.MPRInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.scan("com.dominion.salud.mpr.configuration"); ctx.setServletContext(servletContext); System.setProperty("mpr.conf.home", findConfigurationAndLogger(ctx)); ctx.refresh();/* w w w .jav a 2s .c o m*/ ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); dispatcher.addMapping("/controller/*"); dispatcher.addMapping("/services/*"); servletContext.addListener(new ContextLoaderListener(ctx)); // Configuracion GENERAL DEL MODULO MPRConstantes._MPR_HOME = StringUtils.endsWith(servletContext.getRealPath("/"), File.separator) ? servletContext.getRealPath("/") : servletContext.getRealPath("/") + File.separator; MPRConstantes._MPR_CONF_HOME = ctx.getEnvironment().getProperty("mpr.conf.home"); MPRConstantes._MPR_VERSION = ResourceBundle.getBundle("version").getString("version"); MPRConstantes._MPR_RESOURCES = MPRConstantes._MPR_HOME + "resources" + File.separator; MPRConstantes._MPR_TEMP = MPRConstantes._MPR_HOME + "WEB-INF" + File.separator + "temp" + File.separator; MPRConstantes._MPR_CONTEXT_NAME = servletContext.getServletContextName(); MPRConstantes._MPR_CONTEXT_PATH = servletContext.getContextPath(); MPRConstantes._MPR_CONTEXT_SERVER = servletContext.getServerInfo(); // Configuracion de LOGS DEL MODULO if (StringUtils.isBlank( ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile())) { ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")) .setFile(MPRConstantes._MPR_HOME + "WEB-INF" + File.separator + "classes" + File.separator + "logs" + File.separator + "mpr-desktop.log"); } MPRConstantes._MPR_LOGS = new File( ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile()) .getParent(); // Parametrizacion GENERAL DEL SISTEMA MPRConstantes._ENABLE_TECHNICAL_INFORMATION = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.enable.technical.information")) ? Boolean.parseBoolean(ctx.getEnvironment().getProperty("mpr.enable.technical.information")) : false; // Parametrizacion de CONEXION A EMPI MPRConstantes._EMPI_ENABLE = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.enable")) ? Boolean.parseBoolean(ctx.getEnvironment().getProperty("mpr.empi.enable")) : false; MPRConstantes._EMPI_USUARIO = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.usuario")) ? ctx.getEnvironment().getProperty("mpr.empi.usuario") : ""; MPRConstantes._EMPI_SISTEMA = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.sistema")) ? ctx.getEnvironment().getProperty("mpr.empi.sistema") : ""; MPRConstantes._EMPI_URL = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.url")) ? ctx.getEnvironment().getProperty("mpr.empi.url") : ""; // Parametrizacion de TAREAS PROGRAMADAS MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.process.messages")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.process.messages") : MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES; MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.process.messages")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.process.messages") : MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES; MPRConstantes._TASK_BUZON_IN_HIS_CLEAN = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean") : MPRConstantes._TASK_BUZON_IN_HIS_CLEAN; MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean") : MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN; MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean.old")) ? Integer.parseInt(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean.old")) : MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD; MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean.old")) ? Integer.parseInt(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean.old")) : MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD; MPRConstantes._TASK_BUZON_IN_CLEAN = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.clean")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.clean") : MPRConstantes._TASK_BUZON_IN_CLEAN; MPRConstantes._TASK_BUZON_OUT_CLEAN = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.clean")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.clean") : MPRConstantes._TASK_BUZON_OUT_CLEAN; MPRConstantes._TASK_BUZON_ERRORES_CLEAN = StringUtils .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.errores.clean")) ? ctx.getEnvironment().getProperty("mpr.task.buzon.errores.clean") : MPRConstantes._TASK_BUZON_ERRORES_CLEAN; logger.info("Iniciando el modulo de [" + MPRConstantes._MPR_CONTEXT_NAME + "]"); logger.debug(" Configuracion GENERAL DEL MODULO"); logger.debug(" mpr.home: " + MPRConstantes._MPR_HOME); logger.debug(" mpr.conf.home: " + MPRConstantes._MPR_CONF_HOME); logger.debug(" mpr.version: " + MPRConstantes._MPR_VERSION); logger.debug(" mpr.resources: " + MPRConstantes._MPR_RESOURCES); logger.debug(" mpr.temp: " + MPRConstantes._MPR_TEMP); logger.debug(" mpr.logs: " + MPRConstantes._MPR_LOGS); logger.debug(" mpr.logs.file: " + ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile()); logger.debug(" mpr.context.name: " + MPRConstantes._MPR_CONTEXT_NAME); logger.debug(" mpr.context.path: " + MPRConstantes._MPR_CONTEXT_PATH); logger.debug(" mpr.context.server: " + MPRConstantes._MPR_CONTEXT_SERVER); logger.debug(" java.version: " + ctx.getEnvironment().getProperty("java.version")); logger.debug(""); logger.debug(" Parametrizacion GENERAL DEL SISTEMA"); logger.debug(" mpr.enable.technical.information: " + MPRConstantes._ENABLE_TECHNICAL_INFORMATION); logger.debug(" Parametrizacion de CONEXION A EMPI"); logger.debug(" mpr.empi.enable: " + MPRConstantes._EMPI_ENABLE); logger.debug(" mpr.empi.usuario: " + MPRConstantes._EMPI_USUARIO); logger.debug(" mpr.empi.sistema: " + MPRConstantes._EMPI_SISTEMA); logger.debug(" mpr.empi.url: " + MPRConstantes._EMPI_URL); logger.debug(" Parametrizacion de TAREAS PROGRAMADAS"); logger.debug( " mpr.task.buzon.in.process.messages: " + MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES); logger.debug( " mpr.task.buzon.out.process.messages: " + MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES); logger.debug(" mpr.task.buzon.in.his.clean: " + MPRConstantes._TASK_BUZON_IN_HIS_CLEAN); logger.debug(" mpr.task.buzon.out.his.clean: " + MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN); logger.debug(" mpr.task.buzon.in.his.clean.old: " + MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD); logger.debug(" mpr.task.buzon.out.his.clean.old: " + MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD); logger.debug(" mpr.task.buzon.in.clean: " + MPRConstantes._TASK_BUZON_IN_CLEAN); logger.debug(" mpr.task.buzon.out.clean: " + MPRConstantes._TASK_BUZON_OUT_CLEAN); logger.debug(" mpr.task.buzon.errores.clean: " + MPRConstantes._TASK_BUZON_ERRORES_CLEAN); logger.debug(" Variables de ENTORNO de utilidad"); logger.debug(" catalina.home: " + ctx.getEnvironment().getProperty("catalina.home")); logger.debug(" jboss.home.dir: " + ctx.getEnvironment().getProperty("jboss.home.dir")); logger.info("Modulo [" + MPRConstantes._MPR_CONTEXT_NAME + "] iniciado correctamente"); }