List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.impetus.ankush.common.controller.listener.StartupListener.java
/** * {@inheritDoc}// w ww . j av a2 s . co m */ @Override @SuppressWarnings("unchecked") public void contextInitialized(final ServletContextEvent event) { log.info("Initializing context..."); ServletContext context = event.getServletContext(); applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context); try { // setting application context. AppStoreWrapper.setApplicationContext(applicationContext); // setting servlet context. AppStoreWrapper.setServletContext(context); // setting ankush config reader and config properties reader. setAnkushConfigurator(); // set ankush confiration classes. // AppStoreWrapper.setAnkushConfigurableClassNames(); AppStoreWrapper.setComponentConfiguration(); AppStoreWrapper.setCompConfigClasses(); // Read VERSION.txt file in agent.tar.gz and set current agent // version in server context setAgentVersion(); // For Reading ankush-hadoop-config.xml // HadoopUtils.setHadoopConfigClasses(); // setting mail manager setupMailManager(); // setting App access URL setupAppAccessURL(); // setting asyc executor. setAsyncExecutor(); addDefaultAdminUser(); setServerHost(); // initialising the application dependencies. initializeAppDependency(); // process inconsistent operations in the operation table,which have // op-status as "InProgress",set to "Failed" processInconsistentOperation(); // Start Agent Upgrade procedure new AgentUpgrader().asyncUpgradeAgent(); } catch (Exception e) { log.error(e.getMessage(), e); } }
From source file:net.wastl.webmail.config.ExtConfigListener.java
public void contextInitialized(ServletContextEvent sce) { Helper.logThreads("Top of ExtCongigListener.contextInitialized()"); final ServletContext sc = sce.getServletContext(); contextPath = sc.getInitParameter("default.contextpath"); try {//from w w w . j ava 2 s. c o m final Object o = new InitialContext().lookup("java:comp/env/app.contextpath"); contextPath = (String) o; log.debug("app.contextpath set by webapp env property"); } catch (final NameNotFoundException nnfe) { } catch (final NamingException nnfe) { log.fatal("Runtime failure when looking up env property", nnfe); throw new RuntimeException("Runtime failure when looking up env property", nnfe); } if (contextPath == null) { log.fatal("Required setting 'app.contextpath' is not set as either " + "a app webapp JNDI env param, nor by default context " + "init parameter 'default.contextpath'"); throw new IllegalStateException("Required setting 'app.contextpath' is not set as either " + "a app webapp JNDI env param, nor by default context " + "init parameter 'default.contextpath'"); } if (contextPath.equals("/ROOT")) { log.fatal("Refusing to use context path of '/ROOT' to avoid " + "ambiguity with default context path"); throw new IllegalStateException( "Refusing to use context path of '/ROOT' to avoid " + "ambiguity with default context path"); } deploymentName = generateDeploymentName(); log.info("Initializing configs for runtime deployment name '" + deploymentName + "'"); String dirProp = System.getProperty("webapps.rtconfig.dir"); if (dirProp == null) { dirProp = System.getProperty("user.home"); System.setProperty("webapps.rtconfig.dir", dirProp); } final File rtConfigDir = new File(dirProp, deploymentName); final File metaFile = new File(rtConfigDir, "meta.properties"); lockFile = new File(rtConfigDir, "lock.txt"); if (lockFile.exists()) { log.fatal("Presence of lock file '" + lockFile.getAbsolutePath() + "' indicates the instance is already running"); lockFile = null; throw new IllegalStateException("Presence of lock file " + "indicates the instance is already running"); } // From this point on, we know that: // IF LOCK FILE EXISTS, we have created it and all is well // IF LOCK FILE DOES NOT EXIST, we need to create it ASAP if (rtConfigDir.isDirectory()) { mkLockFile(); } // We create lock file as early as possible. // If we can't make it here, it will be created in installXmlStorage. if (!rtConfigDir.isDirectory() || !metaFile.isFile()) { try { installXmlStorage(rtConfigDir, metaFile); log.warn("New XML storage system successfully loaded. " + "Metadata file '" + metaFile.getAbsolutePath() + "'"); } catch (final IOException e) { log.fatal("Failed to set up a new XML storage system", e); throw new IllegalStateException("Failed to set up a new XML storage system", e); } } if (!lockFile.exists()) { // Being extra safe log.fatal("Assertion failed. Internal locking error in " + getClass().getName() + '.'); lockFile = null; throw new IllegalStateException( "Assertion failed. Internal locking error in " + getClass().getName() + '.'); } final ExpandableProperties metaProperties = new ExpandableProperties(); try { metaProperties.load(new FileInputStream(metaFile)); } catch (final IOException ioe) { log.fatal("Failed to read meta props file '" + metaFile.getAbsolutePath() + "'", ioe); throw new IllegalStateException("Failed to read meta props file '" + metaFile.getAbsolutePath() + "'", ioe); } final Properties expandProps = new Properties(); expandProps.setProperty("rtconfig.dir", rtConfigDir.getAbsolutePath()); expandProps.setProperty("app.contextpath", contextPath); expandProps.setProperty("deployment.name", deploymentName); try { metaProperties.expand(expandProps); // Expand ${} properties } catch (final Throwable t) { log.fatal("Failed to expand properties in meta file '" + metaFile.getAbsolutePath() + "'", t); throw new IllegalStateException( "Failed to expand properties in meta file '" + metaFile.getAbsolutePath() + "'", t); } String requiredKeysString; requiredKeysString = sc.getInitParameter("required.metaprop.keys"); if (requiredKeysString != null) { final Set<String> requiredKeys = new HashSet<String>( Arrays.asList(requiredKeysString.split("\\s*,\\s*", -1))); requiredKeys.removeAll(metaProperties.keySet()); if (requiredKeys.size() > 0) { log.fatal("Meta properties file '" + metaFile.getAbsolutePath() + "' missing required property(s): " + requiredKeys); throw new IllegalStateException("Meta properties file '" + metaFile.getAbsolutePath() + "' missing required property(s): " + requiredKeys); } } sc.setAttribute("app.contextpath", contextPath); sc.setAttribute("deployment.name", deploymentName); sc.setAttribute("rtconfig.dir", rtConfigDir); sc.setAttribute("meta.properties", metaProperties); log.debug("'app.contextpath', 'rtconfig.dir', 'meta.properties' " + "successfully published to app context for " + deploymentName); }
From source file:edu.ucsf.vitro.opensocial.OpenSocialSmokeTests.java
/** * When the system starts up, run the tests. *///w w w. j av a 2 s . c om @Override public void contextInitialized(ServletContextEvent sce) { ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); configProps = ConfigurationProperties.getBean(ctx); /* * If OpenSocial is not configured in runtime.properties, skip the * tests. */ if (!configurationPresent()) { ss.info(this, "The OpenSocial connection is not configured."); return; } /* * Run all of the non-threaded tests. If any fail, skip the threaded * tests. */ checkDatabaseTables(); checkShindigConfigFile(); checkTokenKeyFile(); checkTokenServiceInfo(); if (!warnings.isEmpty()) { for (Warning w : warnings) { w.warn(ss); } return; } /* * Run the threaded tests. */ ss.info(this, "Starting threads for OpenSocial smoke tests"); new ShindigTestThread(this, ss, shindigBaseUrl).start(); new TokenServiceTestThread(this, ss, tokenServiceHost, tokenServicePort).start(); }
From source file:org.openspaces.pu.container.jee.context.BootstrapWebApplicationContextListener.java
public void contextDestroyed(ServletContextEvent servletContextEvent) { if (jeeContainerContextListener != null) { jeeContainerContextListener.contextDestroyed(servletContextEvent); }/*from w w w. j a va 2s. c o m*/ ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) servletContextEvent .getServletContext().getAttribute(JeeProcessingUnitContainerProvider.APPLICATION_CONTEXT_CONTEXT); if (applicationContext != null && applicationContext.isActive()) { applicationContext.close(); } }
From source file:org.kuali.kra.infrastructure.KraServiceLocatorListener.java
public void contextInitialized(ServletContextEvent sce) { LOG.debug("Starting KraServiceLocatorListener"); ApplicationContext appContext = null; String bootstrapSpringBeans = "classpath:kc-bootstrap-springbeans.xml"; if (!StringUtils.isBlank(System.getProperty(Constants.BOOTSTRAP_SPRING_FILE))) { bootstrapSpringBeans = System.getProperty(Constants.BOOTSTRAP_SPRING_FILE); LOG.info("Found bootstrap Spring Beans file defined in system properties: " + bootstrapSpringBeans); } else if (!StringUtils .isBlank(sce.getServletContext().getInitParameter(Constants.BOOTSTRAP_SPRING_FILE))) { bootstrapSpringBeans = sce.getServletContext().getInitParameter(Constants.BOOTSTRAP_SPRING_FILE); LOG.info("Found bootstrap Spring Beans file defined in servlet context: " + bootstrapSpringBeans); }// w ww. ja va 2s .c o m try { appContext = new ClassPathXmlApplicationContext(bootstrapSpringBeans); } catch (RuntimeException e) { LOG.fatal("error during startup", e); throw e; } catch (Error e) { LOG.fatal("error during startup", e); throw e; } KraServiceLocator.setAppContext(appContext); }
From source file:org.apache.roller.weblogger.ui.core.RollerContext.java
/** * Responds to app-init event and triggers startup procedures. *//*ww w. j a v a 2 s. co m*/ public void contextInitialized(ServletContextEvent sce) { // First, initialize everything that requires no database // Keep a reverence to ServletContext object this.servletContext = sce.getServletContext(); // Call Spring's context ContextLoaderListener to initialize all the // context files specified in web.xml. This is necessary because // listeners don't initialize in the order specified in 2.3 containers super.contextInitialized(sce); // get the *real* path to <context>/resources String ctxPath = servletContext.getRealPath("/"); if (!ctxPath.endsWith(File.separator)) ctxPath += File.separator + "resources"; else ctxPath += "resources"; // try setting the uploads path to <context>/resources // NOTE: this should go away at some point // we leave it here for now to allow users to keep writing // uploads into their webapp context, but this is a bad idea // // also, the WebloggerConfig.setUploadsDir() method is smart // enough to disregard this call unless the uploads.path // is set to ${webapp.context} WebloggerConfig.setUploadsDir(ctxPath); // try setting the themes path to <context>/themes // NOTE: this should go away at some point // we leave it here for now to allow users to keep using // themes in their webapp context, but this is a bad idea // // also, the WebloggerConfig.setThemesDir() method is smart // enough to disregard this call unless the themes.dir // is set to ${webapp.context} WebloggerConfig.setThemesDir(servletContext.getRealPath("/") + File.separator + "themes"); // Now prepare the core services of the app so we can bootstrap try { WebloggerStartup.prepare(); } catch (StartupException ex) { log.fatal("Roller Weblogger startup failed during app preparation", ex); return; } // if preparation failed or is incomplete then we are done, // otherwise try to bootstrap the business tier if (!WebloggerStartup.isPrepared()) { StringBuffer buf = new StringBuffer(); buf.append("\n--------------------------------------------------------------"); buf.append("\nRoller Weblogger startup INCOMPLETE, user interaction required"); buf.append("\n--------------------------------------------------------------"); log.info(buf.toString()); } else { try { // trigger bootstrapping process WebloggerFactory.bootstrap(); // trigger initialization process WebloggerFactory.getWeblogger().initialize(); } catch (BootstrapException ex) { log.fatal("Roller Weblogger bootstrap failed", ex); } catch (WebloggerException ex) { log.fatal("Roller Weblogger initialization failed", ex); } // Initialize Planet if necessary if (WebloggerFactory.isBootstrapped()) { if (WebloggerConfig.getBooleanProperty("planet.aggregator.enabled")) { // Now prepare the core services of planet so we can bootstrap it try { PlanetStartup.prepare(); } catch (Throwable ex) { log.fatal("Roller Planet startup failed during app preparation", ex); return; } try { // trigger planet bootstrapping process // we need to use our own planet provider for integration String guiceModule = WebloggerConfig.getProperty("planet.aggregator.guice.module"); PlanetProvider provider = new GuicePlanetProvider(guiceModule); PlanetFactory.bootstrap(provider); // and now initialize planet PlanetFactory.getPlanet().initialize(); } catch (Throwable t) { log.fatal("Roller Planet initialization failed", t); } } } } // do a small amount of work to initialize the web tier try { // Initialize Acegi based on Roller configuration initializeSecurityFeatures(servletContext); // Setup Velocity template engine setupVelocity(); } catch (WebloggerException ex) { log.fatal("Error initializing Roller Weblogger web tier", ex); } }
From source file:com.autentia.tnt.listener.StartupListener.java
public void contextInitialized(ServletContextEvent sce) { try {/*from w w w. j a v a 2 s . com*/ // Dump traces now as if nothing had happended before log.info("--------------------------------------------------------------------------------"); log.info("contextInitialized - starting up application"); log.info("contextInitialized - saving Spring's context for use by all application"); // Save Spring context SpringUtils.configure(WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext())); // Get configuration directory String cfgDir = ConfigurationUtil.getDefault().getConfigDir(); log.info("contextInitialized - configuration directory set to '" + cfgDir + "'"); // Normalized cfgDir if (cfgDir.endsWith("/") || cfgDir.endsWith("\\")) { cfgDir = cfgDir.substring(0, cfgDir.length() - 1); } // Check configuration directory if (!new File(cfgDir).isDirectory()) { throw new FileNotFoundException(cfgDir); } // Configure LOG4J String log4jProperties = cfgDir + FILE_LOG4J; if (!new File(log4jProperties).exists()) { throw new FileNotFoundException(log4jProperties); } PropertyConfigurator.configure(log4jProperties); log.info("contextInitialized - configuring LOG4J system with file " + log4jProperties); // Try to create essential directories File uploadPath = new File(ConfigurationUtil.getDefault().getUploadPath()); log.info("contextInitialized - checking upload directory " + uploadPath.getAbsolutePath()); uploadPath.mkdirs(); if (!uploadPath.isDirectory()) { throw new FileNotFoundException(uploadPath.getAbsolutePath()); } // Load reports if (ConfigurationUtil.getDefault().getLoadingReportOnLoad() > 0) { log.info("contextInitialized - loading reports in report manager"); ReportManager.getReportManager(); } else { log.info("contextInitialized - loading reports on startup disabled"); } // Check database log.info("contextInitialized - checking database version"); ApplicationLock.refresh(); } catch (FileNotFoundException e) { log.fatal("contextInitialized - configuration dir or file not found (" + e.getMessage() + "): application will not be started", e); throw new IllegalStateException("Config dir or file not found", e); } /* Moved to Spring catch( ConfigurationException e ) { log.fatal("contextInitialized - error reading application configuration: application will not be started",e); throw new IllegalStateException("Error reading applocation configuration",e); } */ }