List of usage examples for javax.servlet ServletContext addListener
public void addListener(Class<? extends EventListener> listenerClass);
From source file:com.dominion.salud.pedicom.configuration.PEDICOMInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.scan("com.dominion.salud.pedicom.configuration"); ctx.setServletContext(servletContext); PEDICOMConstantes._NOMBRE_CONFIG = servletContext.getInitParameter("NOMBRE_CONFIG"); System.setProperty("pedicom.conf.home", findConfigurationAndLogger(ctx)); ctx.refresh();//from w w w.j a v a2 s .c om // Spring Dispatcher ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); dispatcher.setInitParameter("contextClass", ctx.getClass().getName()); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); dispatcher.addMapping("/controller/*"); servletContext.addListener(new ContextLoaderListener(ctx)); // Configuracion general PEDICOMConstantes._HOME = StringUtils.endsWith(servletContext.getRealPath("/"), File.separator) ? servletContext.getRealPath("/") : servletContext.getRealPath("/") + File.separator; PEDICOMConstantes._CONF_HOME = ctx.getEnvironment().getProperty("pedicom.conf.home"); PEDICOMConstantes._TEMP = PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "temp" + File.separator; PEDICOMConstantes._VERSION = ResourceBundle.getBundle("version").getString("version"); PEDICOMConstantes._LOGS = PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "classes" + File.separator + "logs"; PEDICOMConstantes._CONTEXT_NAME = servletContext.getServletContextName(); PEDICOMConstantes._CONTEXT_PATH = servletContext.getContextPath(); PEDICOMConstantes._CONTEXT_SERVER = servletContext.getServerInfo(); PEDICOMConstantes._ENABLE_TECHNICAL_INFORMATION = StringUtils.isNotBlank( ResourceBundle.getBundle("application").getString("pedicom.enable.technical.information")) ? Boolean.parseBoolean(ResourceBundle.getBundle("application") .getString("pedicom.enable.technical.information")) : false; PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = StringUtils .isNotBlank(ResourceBundle.getBundle("application").getString("pedicom_scheduler_send_mail_cron")) ? PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = ResourceBundle.getBundle("application") .getString("pedicom_scheduler_send_mail_cron") : PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON; PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON = StringUtils.isNotBlank( ResourceBundle.getBundle("application").getString("pedicom_scheduler_update_existencias_cron")) ? PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = ResourceBundle.getBundle("application") .getString("pedicom_scheduler_update_existencias_cron") : PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON; // 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(PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "classes" + File.separator + "logs" + File.separator + "mpr-desktop.log"); } PEDICOMConstantes._LOGS = new File( ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile()) .getParent(); Environment env = ctx.getEnvironment(); XmlUnmarshaler xml = new XmlUnmarshaler(); Datos datos = (Datos) xml.unmarshal(); logger.info(" Datasources"); for (Datasources dat : datos.getDatasources()) { if (dat.getNombreDatasource().equals("Central")) { PEDICOMConstantes.EXISTENCIAS_EXISTE = true; } logger.info(" codCentro: " + dat.getCodCentro()); logger.info(" nombreDatasource: " + dat.getNombreDatasource()); logger.info(" driverClassName: " + dat.getDriverClassName()); logger.info(" jndi: " + dat.getJndi()); logger.info(" url: " + dat.getUrl()); logger.info(" username: " + dat.getUsername()); logger.info(" usernameEmail: " + dat.getUsernameEmail()); logger.info(" passwordEmail: " + dat.getPasswordEmail()); logger.info(" from: " + dat.getFrom()); logger.info(" host: " + dat.getHost()); logger.info(" port: " + dat.getPort()); logger.info(" TLS: " + dat.getTLS()); logger.info(" SSL: " + dat.getSSL()); } // ctx.refresh(); // PropertyConfigurator.configureAndWatch("log4j"); logger.info(" Configuracion general del sistema"); logger.info(" pedicom.home: " + PEDICOMConstantes._HOME); logger.info(" pedicom.conf.home: " + PEDICOMConstantes._CONF_HOME); logger.info(" pedicom.temp: " + PEDICOMConstantes._TEMP); logger.info(" pedicom.version: " + PEDICOMConstantes._VERSION); logger.info(" pedicom.logs: " + PEDICOMConstantes._LOGS); logger.info(" pedicom.context.name: " + PEDICOMConstantes._CONTEXT_NAME); logger.info(" pedicom.context.path: " + PEDICOMConstantes._CONTEXT_PATH); logger.info(" pedicom.context.server: " + PEDICOMConstantes._CONTEXT_SERVER); logger.info(" Parametrizacion del sistema"); logger.info(" pedicom.enable.technical.information: " + PEDICOMConstantes._ENABLE_TECHNICAL_INFORMATION); logger.info( " pedicom_scheduler_send_mail_cron: " + PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON); logger.info(" pedicom_scheduler_update_existencias_cron: " + PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON); logger.info(" Modulo configurado correctamente"); logger.info("MODULO INICIADO CORRECTAMENTE"); }
From source file:com.alliander.osgp.webdevicesimulator.application.config.WebDeviceSimulatorInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/*from w ww.j av a2 s. c om*/ // Force the timezone of application to UTC (required for // Hibernate/JDBC) TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final String logLocation = (String) initialContext .lookup("java:comp/env/osp/webDeviceSimulator/log-config"); LogbackConfigurer.initLogging(logLocation); InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); 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); } catch (final FileNotFoundException e) { throw new ServletException("Logging file not found", e); } catch (final JoranException e) { throw new ServletException("Logback exception", e); } }
From source file:com.rakesh.rp3599.config.WebAppInitializer.java
public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(AppContext.class); /** Dispatcher Servlet **/ ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);//from ww w . ja v a 2 s.com dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); /** Dispatcher Types Enum **/ EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); /** UTF-8 Filter **/ FilterRegistration.Dynamic characterEncoding = container.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); /** Context Listener **/ container.addListener(new ContextLoaderListener(rootContext)); }
From source file:org.openmrs.web.WebComponentRegistrar.java
@Override public void setServletContext(ServletContext servletContext) { try {/*from w w w .j a v a 2s . co m*/ ServletRegistration openmrsServletReg = servletContext.getServletRegistration("openmrs"); addMappings(openmrsServletReg, "*.htm", "*.form", "*.list", "*.json", "*.field", "*.portlet", "*.page", "*.action"); addMappings(servletContext.getServletRegistration("jsp"), "*.withjstl"); ServletRegistration servletReg = servletContext.addServlet("logoutServlet", new LogoutServlet()); servletReg.addMapping("/logout"); Dynamic filter = servletContext.addFilter("forcePasswordChangeFilter", new ForcePasswordChangeFilter()); filter.setInitParameter("changePasswordForm", "/admin/users/changePassword.form"); filter.setInitParameter("excludeURL", "changePasswordForm,logout,.js,.css,.gif,.jpg,.jpeg,.png"); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); filter = servletContext.addFilter("adminPageFilter", new AdminPageFilter()); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/admin"); servletContext.addListener(new SessionListener()); /* * EfficientShutdownServletContextAttributeListener is used instead of * EfficientShutdownServletContextListener since the latter implements ServletContextListener, * which is not supported by ServletContext.addListener. */ servletContext.addListener(new EfficientShutdownServletContextAttributeListener()); } catch (Exception ex) { //TODO not yet looked into what caused this to fail. } }
From source file:com.cfitzarl.cfjwed.Main.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Add spring security filter chain servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class) .addMappingForUrlPatterns(null, false, "/*"); // Add Hibernate session binder servletContext.addFilter("jpaTransactionFilter", OpenEntityManagerInViewFilter.class) .addMappingForUrlPatterns(null, false, "/*"); // Define application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebApplicationMvcConfigurer.class); rootContext.scan("com.cfitzarl.cfjwed"); // Create a dispatcher servlet that loads the application context DispatcherServlet dispatcherServlet = new DispatcherServlet(); dispatcherServlet.setApplicationContext(rootContext); // Add the dispatcher servlet to the servlet context and map it to / ServletRegistration.Dynamic servletRegister = servletContext.addServlet("dispatcher", dispatcherServlet); servletRegister.setLoadOnStartup(1); servletRegister.addMapping("/"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
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 w w w .ja va2 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.jblogcms.core.config.MainConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(MainContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);//from w w w . j av a 2 s. c o m dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); 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); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:com.github.sshw.config.RootApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/*w ww.jav a 2 s . c o m*/ dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); 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); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, 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);/*ww w . ja v a2 s . com*/ 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, "/*"); }
From source file:org.alfresco.bm.web.WebApp.java
@Override public void onStartup(ServletContext container) { // Grab the server capabilities, otherwise just use the java version String javaVersion = System.getProperty("java.version"); String systemCapabilities = System.getProperty(PROP_SYSTEM_CAPABILITIES, javaVersion); String appDir = new File(".").getAbsolutePath(); String appContext = container.getContextPath(); String appName = container.getContextPath().replace(SEPARATOR, ""); // Create an application context (don't start, yet) XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(new String[] { "classpath:config/spring/app-context.xml" }); // Pass our properties to the new context Properties ctxProperties = new Properties(); {/*from w ww . j a v a 2 s .c o m*/ ctxProperties.put(PROP_SYSTEM_CAPABILITIES, systemCapabilities); ctxProperties.put(PROP_APP_CONTEXT_PATH, appContext); ctxProperties.put(PROP_APP_DIR, appDir); } ConfigurableEnvironment ctxEnv = ctx.getEnvironment(); ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource(appName, ctxProperties)); // Override all properties with system properties ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("system", System.getProperties())); // Bind to shutdown ctx.registerShutdownHook(); ContextLoaderListener ctxLoaderListener = new ContextLoaderListener(ctx); container.addListener(ctxLoaderListener); ServletRegistration.Dynamic jerseyServlet = container.addServlet("jersey-serlvet", SpringServlet.class); jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "org.alfresco.bm.rest"); jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); jerseyServlet.addMapping("/api/*"); }