List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:us.mn.state.health.lims.plugin.PluginLoader.java
public PluginLoader(ServletContextEvent event) { context = event.getServletContext(); }
From source file:com.anhao.market.web.listener.ServletListener.java
@Override public void contextInitialized(ServletContextEvent sce) { logger.info("ServletListener Starting..."); springContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); //start/*from w w w .j a v a2 s . co m*/ ServletContext sc = sce.getServletContext(); //? ConfigService configService = (ConfigService) springContext.getBean("configService"); logger.info("this is config {}", configService.getSystemConfig()); sc.setAttribute("systemName", "??"); sc.setAttribute("systemConfig", configService.getSystemConfig()); logger.info("ServletListener Started now"); }
From source file:com.telefonica.euro_iaas.sdc.bootstrap.PropertiesMBeanRegisterBootstrap.java
/** * Stores every system properties in BD and show them by JMX *//*w w w . j ava 2 s.c o m*/ public void contextInitialized(ServletContextEvent event) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); PropertiesProvider propertiesUtil = new PropertiesProviderFactoryImpl() .createPropertiesProvider((EntityManagerFactory) ctx.getBean("entityManagerFactory")); try { for (String namespace : propertiesUtil.getNamespaces()) { PropertiesProviderMBean mbean = new PropertiesProviderMBean(namespace, propertiesUtil); log.info("Registering mbean " + namespace); MBeanUtils.register(mbean, event.getServletContext().getContextPath() + ":service=SystemConfiguration-" + namespace); } } catch (Exception e) { throw new SdcRuntimeException(e); } }
From source file:org.mifos.reports.MifosViewerServletContextListener.java
/** * Sets the System Property IBirtConstants.SYS_PROP_ROOT_PATH to a temporary directory into which the *.rptdesign * files etc. are extracted into from the classpath, before invoking the parent ViewerServletContextListener's * {@link ViewerServletContextListener#contextInitialized(ServletContextEvent)}. * //from ww w . j a v a 2 s .c om * @throws RuntimeException if BIRT_RESOURCES_PATTERN not found on Classpath */ @Override public void contextInitialized(ServletContextEvent event) { File birtRootDir = copyBIRTResourcesFromClassPathToFilesystemDirectory(event.getServletContext()); System.setProperty(SYS_PROP_BIRT_ROOT_TEMP_DIR, birtRootDir.getAbsolutePath()); LOGGER.info("System Property " + SYS_PROP_BIRT_ROOT_TEMP_DIR + " set to " + birtRootDir); super.contextInitialized(event); }
From source file:org.sakaiproject.kernel.webapp.GuiceLoaderListener.java
@SuppressWarnings("unchecked") public void contextInitialized(ServletContextEvent sce, ClassLoader classloader) { try {//ww w . ja va2s. c o m String[] moduleNames = StringUtils.split(sce.getServletContext().getInitParameter(INIT_MODULES), ','); Module[] modules = null; if (moduleNames == null) { modules = new Module[0]; } else { modules = new Module[moduleNames.length]; for (int i = 0; i < moduleNames.length; i++) { Class<Module> clazz = (Class<Module>) classloader.loadClass(moduleNames[i]); modules[i] = clazz.newInstance(); } } injector = Guice.createInjector(modules); TypeLiteral<List<Initialisable>> initializersType = new TypeLiteral<List<Initialisable>>() { }; initializers = injector.getInstance(Key.get(initializersType)); for (Initialisable init : initializers) { init.init(); } } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException("Failed to start guild context :" + ex.getMessage(), ex); } }
From source file:org.scenarioo.rest.application.ScenariooWebApplication.java
private String configureConfigurationDirectoryFromServerContext(final ServletContextEvent servletContextEvent) { String configurationDirectory = servletContextEvent.getServletContext() .getInitParameter("scenariooConfigurationDirectory"); if (StringUtils.isBlank(configurationDirectory)) { // Fallback to old property name: configurationDirectory = servletContextEvent.getServletContext() .getInitParameter("configurationDirectory"); }/*from ww w .ja va2 s . c o m*/ LOGGER.info(" configured configuration directory: " + configurationDirectory); return configurationDirectory; }
From source file:cn.buk.qms.listener.QuartzContextListener.java
@Override public void contextDestroyed(ServletContextEvent arg0) { WebApplicationContext webApplicationContext = (WebApplicationContext) arg0.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); Object obj = webApplicationContext.getBean("ctripHotelService"); //System.out.println(obj); cn.buk.api.service.CtripHotelServiceImpl ctripHotelService = (cn.buk.api.service.CtripHotelServiceImpl) obj; if (ctripHotelService != null) { ctripHotelService.stopService(); System.out.println("ctripHotelService.stopService();"); try {//from w w w . j a v a 2 s . co m Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } obj = null; System.out.println("Obj: " + obj); obj = webApplicationContext.getBean("hotelService"); System.out.println("Obj: " + obj); //if(obj != null) { //cn.buk.hotel.service.HotelServiceImpl hotelService = ; //System.out.println("hotelService: " + hotelService); System.out.println("hotelService.stopService();"); ((cn.buk.hotel.service.HotelServiceImpl) obj).stopService(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } //} obj = webApplicationContext.getBean("startQuartz"); //System.out.println(obj.getClass().getName()); org.quartz.impl.StdScheduler startQuartz = (org.quartz.impl.StdScheduler) obj; if (startQuartz != null) { //System.out.println("startQuertz.shutdown();"); startQuartz.shutdown(); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.versatus.jwebshield.securitylock.SecurityCheckListener.java
/** * @see ServletContextListener#contextInitialized(ServletContextEvent) *///w w w .j av a2s. c o m @Override public void contextInitialized(ServletContextEvent sce) { String file = sce.getServletContext().getInitParameter("configFile"); if (file != null) { try { XMLConfiguration config = new XMLConfiguration(file); SubnodeConfiguration fields = config.configurationAt("securityLock"); int triesToLock = fields.getInt("triesToLock"); // lockSql = fields.getString("lockSql"); // dbJndiName = fields.getString("dbJndiName"); timeToLock = fields.getInt("timeToLockMin"); // lockCheckSql = fields.getString("lockCheckSql"); DBHelper dbh = new DBHelper(config); securityLockService = new SecurityLockService(dbh, config); securityLockService.setTriesToLock(triesToLock); // logger.info("contextInitialized: lockCheckInterval=" // + lockCheckInterval); logger.info("contextInitialized: timeToLock=" + timeToLock); // logger.info("contextInitialized: lockSql=" + lockSql); // logger.info("contextInitialized: lockCheckSql=" + // lockCheckSql); // logger.info("contextInitialized: dbJndiName=" + dbJndiName); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } // TimerTask lockCheckTimer = new LockCheckTimerTask(); // timer.schedule(lockCheckTimer, 10000, (lockCheckInterval * 60 * // 1000)); }
From source file:org.ambraproject.configuration.WebAppListener.java
/** * Initialize the configuration singleton since this web application is getting deployed.<p> * * By default, WebAppListener uses the default ConfigurationStore initialization. This * usually means using /etc/.../ambra.xml. This can be overridden by setting the * org.ambraproject.configuration system property or webapp context variable to a URL or a name * resolvable as a resource./*from w ww . j a v a 2 s . c o m*/ * * @param event The servlet event associated with initializing this context * @throws Error on non-recoverable config load error */ public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); FactoryConfig config = getFactoryConfig(context); try { URL url; // Locate the config url. if (config.name.startsWith("/WEB-INF")) { url = context.getResource(config.name); if (url == null) throw new MalformedURLException("'" + config.name + "' not found in the web-app context"); } else { try { // First see if it is a valid URL url = new URL(config.name); } catch (MalformedURLException e) { // Otherwise, load as a resource url = WebAppListener.class.getResource(config.name); if (url == null) throw e; } } // Now load the config log.info("Loading '" + url + "' (" + config.name + ") configured via " + config.source); ConfigurationStore.getInstance().loadConfiguration(url); // Setup an application scope attribute that something like freemarker or struts might use context.setAttribute("config", ConfigurationStore.getInstance().getConfiguration()); } catch (MalformedURLException e) { log.fatal(config.name + " defined by " + config.source + " is not a valid URL or resource", e); throw new Error("Failed to load configuration", e); } catch (ConfigurationException e) { log.fatal("Failed to initialize configuration factory.", e); throw new Error("Failed to load configuration", e); } }
From source file:org.scenarioo.rest.application.ScenariooWebApplication.java
private String configureConfigurationFilenameFromServerContext(final ServletContextEvent servletContextEvent) { String configurationFilename = servletContextEvent.getServletContext() .getInitParameter("scenariooConfigurationFilename"); if (StringUtils.isBlank(configurationFilename)) { // Fallback to old property name: configurationFilename = servletContextEvent.getServletContext() .getInitParameter("configurationFilename"); }//from www .ja v a 2 s. co m if (StringUtils.isNotBlank(configurationFilename)) { LOGGER.info(" overriding default configuration filename config.xml with: " + configurationFilename); return configurationFilename; } return null; }