List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:org.pentaho.platform.web.http.context.SolutionContextListener.java
public void contextInitialized(final ServletContextEvent event) { ServletContext context = event.getServletContext(); String encoding = context.getInitParameter("encoding"); //$NON-NLS-1$ if (encoding != null) { LocaleHelper.setSystemEncoding(encoding); }/* www . j a v a 2s .c o m*/ String textDirection = context.getInitParameter("text-direction"); //$NON-NLS-1$ if (textDirection != null) { LocaleHelper.setTextDirection(textDirection); } String localeLanguage = context.getInitParameter("locale-language"); //$NON-NLS-1$ String localeCountry = context.getInitParameter("locale-country"); //$NON-NLS-1$ boolean localeSet = false; if ((localeLanguage != null) && !"".equals(localeLanguage) && (localeCountry != null) && !"".equals(localeCountry)) { //$NON-NLS-1$ //$NON-NLS-2$ Locale[] locales = Locale.getAvailableLocales(); if (locales != null) { for (Locale element : locales) { if (element.getLanguage().equals(localeLanguage) && element.getCountry().equals(localeCountry)) { LocaleHelper.setLocale(element); localeSet = true; break; } } } } if (!localeSet) { // do this thread in the default locale LocaleHelper.setLocale(Locale.getDefault()); } LocaleHelper.setDefaultLocale(LocaleHelper.getLocale()); // log everything that goes on here Logger.info(SolutionContextListener.class.getName(), Messages.getInstance().getString("SolutionContextListener.INFO_INITIALIZING")); //$NON-NLS-1$ Logger.info(SolutionContextListener.class.getName(), Messages.getInstance().getString("SolutionContextListener.INFO_SERVLET_CONTEXT") + context); //$NON-NLS-1$ SolutionContextListener.contextPath = context.getRealPath(""); //$NON-NLS-1$ Logger.info(SolutionContextListener.class.getName(), Messages.getInstance().getString("SolutionContextListener.INFO_CONTEXT_PATH") //$NON-NLS-1$ + SolutionContextListener.contextPath); SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context); if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) { String errorMsg = Messages.getInstance() .getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH"); //$NON-NLS-1$ Logger.error(getClass().getName(), errorMsg); /* * Since we couldn't find solution repository path there is no point in going forward and the user should know * that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message. */ throw new RuntimeException(errorMsg); } Logger.info(getClass().getName(), Messages.getInstance().getString("SolutionContextListener.INFO_ROOT_PATH") + SolutionContextListener.solutionPath); //$NON-NLS-1$ String fullyQualifiedServerUrl = context.getInitParameter("fully-qualified-server-url"); //$NON-NLS-1$ if (fullyQualifiedServerUrl == null) { // assume this is a demo installation // TODO: Create a servlet that's loaded on startup to set this value fullyQualifiedServerUrl = "http://localhost:8080/pentaho/"; //$NON-NLS-1$ } IApplicationContext applicationContext = new WebApplicationContext(SolutionContextListener.solutionPath, fullyQualifiedServerUrl, context.getRealPath(""), context); //$NON-NLS-1$ /* * Copy out all the initParameter values from the servlet context and put them in the application context. */ Properties props = new Properties(); Enumeration<?> initParmNames = context.getInitParameterNames(); String initParmName; while (initParmNames.hasMoreElements()) { initParmName = (String) initParmNames.nextElement(); props.setProperty(initParmName, context.getInitParameter(initParmName)); } ((WebApplicationContext) applicationContext).setProperties(props); setSystemCfgFile(context); setObjectFactory(context); boolean initOk = PentahoSystem.init(applicationContext); this.showInitializationMessage(initOk, fullyQualifiedServerUrl); }
From source file:org.pepstock.jem.gwt.server.listeners.StartUp.java
@Override public void contextInitialized(ServletContextEvent event) { // starts SHIRO super.contextInitialized(event); // gets servlet context ServletContext context = event.getServletContext(); // gets servlet context and saves it SharedObjects.getInstance().setContext(context); // reads Hazecast init parameter String hazelcastFile = context.getInitParameter(ConfigKeys.HAZELCAST_CONFIG); // set the check version flag retreive by web.xml Boolean checkVersion = Boolean.valueOf(context.getInitParameter(ConfigKeys.JEM_CHECK_VERSION)); SharedObjects.getInstance().setCheckVersion(checkVersion); setJemVersion(context);//w w w.jav a 2s . c om if (hazelcastFile != null) { try { // starts hazelcast startHazelcastClient(context, hazelcastFile); } catch (ConfigurationException e) { throw new JemRuntimeException(e); } } else { throw new MessageRuntimeException(UserInterfaceMessage.JEMG021E); } }
From source file:org.fenixedu.ulisboa.specifications.servlet.FenixeduUlisboaSpecificationsInitializer.java
private void setupCustomExceptionHandler(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); PortalExceptionHandler exceptionHandler = CoreConfiguration.getConfiguration() .developmentMode() == Boolean.TRUE ? new PortalDevModeExceptionHandler(servletContext) : new PortalExceptionHandler(servletContext); ExceptionHandlerFilter.setExceptionHandler(new FenixEduUlisboaExceptionHandler(exceptionHandler)); }
From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); try {/* ww w . j a va 2s. c o m*/ new Loader(this, ctx, ss).load(); new SmokeTester(this, ctx, ss).test(); } catch (Exception e) { ss.fatal(this, "Failed to load the PermissionSets", e); } }
From source file:com.joe.utilities.core.startup.listener.AlineoContextListener.java
/** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) *//*w ww . j a v a 2 s . c om*/ public void contextInitialized(ServletContextEvent event) { logger.info(".contextInitialized: Entering"); StartupValidator validator = new StartupValidator(); ReturnStatus status = validator.validate(); Boolean success = Boolean.TRUE; if (!status.isSuccess()) { success = Boolean.FALSE; event.getServletContext().setAttribute("Messages", status); event.getServletContext().setAttribute("Exception", validator.getStartupException()); } event.getServletContext().setAttribute("Working", success); logger.info(".contextInitialized: Exiting"); }
From source file:nl.opengeogroep.filesetsync.server.FileHashCache.java
@Override public void contextInitialized(ServletContextEvent sce) { log.info("*** initializing ***"); int maxElementsInMemory = 10000; try {// w w w .j ava 2 s. c om String s = sce.getServletContext().getInitParameter("hashcache.maxElementsInMemory"); if (s != null) { maxElementsInMemory = Integer.parseInt(s); } } catch (Exception e) { } // Create caches for all filesets for (String name : ServerSyncConfig.getInstance().getFilesetNames()) { ServerFileset fs = ServerSyncConfig.getInstance().getFileset(name); File f = new File(fs.getPath()); if (f.isFile()) { continue; } File cacheDir = new File(getCacheDir(name)); log.info("Creating Ehcache for fileset " + fs.getName() + " in directory " + cacheDir); Configuration cacheManagerConfig = new Configuration().name(name) .diskStore(new DiskStoreConfiguration().path(cacheDir.getAbsolutePath())); CacheConfiguration cacheConfig = new CacheConfiguration(name, maxElementsInMemory) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU).eternal(false) .timeToIdleSeconds(60 * 60 * 24) .persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP)); cacheManagerConfig.addCache(cacheConfig); CacheManager cacheManager; try { cacheManager = new CacheManager(cacheManagerConfig); } catch (CacheException e) { log.error(String.format("Error creating cache for \"%s\" at directory \"%s\", hash cache disabled!", fs.getName(), cacheDir), e); continue; } cacheManagers.put(name, cacheManager); Cache cache = cacheManager.getCache(name); caches.put(name, cache); File persistedCache = new File(getPersistedCacheFile(name)); if (persistedCache.exists() && persistedCache.canRead()) { log.info(String.format("Reading persisted cache for \"%s\" from \"%s\"...", name, persistedCache)); try (BufferedReader br = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(persistedCache))))) { long startTime = System.currentTimeMillis(); String line; while ((line = br.readLine()) != null) { String[] s = line.split(":", 2); cache.put(new Element(s[0], s[1])); } log.info(String.format("Cache size is %d, read in %s", cache.getSize(), DurationFormatUtils .formatDurationWords(System.currentTimeMillis() - startTime, true, false))); } catch (IOException e) { log.error("Exception reading persisted cache", e); } } } }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.WebappDaoSetup.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); try {//w w w .j a v a 2 s .com long startTime = System.currentTimeMillis(); setUpJenaDataSource(ctx, ss); log.info((System.currentTimeMillis() - startTime) / 1000 + " seconds to set up models and DAO factories"); } catch (Throwable t) { log.error("Throwable in " + this.getClass().getName(), t); ss.fatal(this, "Throwable in " + this.getClass().getName(), t); } }
From source file:org.jasig.ssp.config.logging.ExternalConfigLoader.java
private void initConfigDirectory(final ServletContextEvent sce) { final StringBuffer configLocation = new StringBuffer(); final String environmentDefinedConf = System.getenv("SSP_CONFIGDIR"); if (StringUtils.isBlank(environmentDefinedConf)) { final String contextDefinedConf = sce.getServletContext().getInitParameter("SSP_CONFIGDIR"); if (StringUtils.isBlank(contextDefinedConf)) { LOGGER.error("Unable to set config directory."); } else {/*from w w w.j a v a 2 s .c o m*/ configLocation.append(contextDefinedConf); } } else { configLocation.append(environmentDefinedConf); } configDir = configLocation.toString(); LOGGER.info("Config directory set to {}", configDir); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.SolrSmokeTest.java
@Override public void contextInitialized(ServletContextEvent sce) { final StartupStatus ss = StartupStatus.getBean(sce.getServletContext()); String solrUrlString = ConfigurationProperties.getBean(sce).getProperty("vitro.local.solr.url", ""); if (solrUrlString.isEmpty()) { ss.fatal(this, "Can't connect to Solr search engine. " + "runtime.properties must contain a value for " + "vitro.local.solr.url"); return;/*from w ww . j av a 2 s.co m*/ } URL solrUrl = null; try { solrUrl = new URL(solrUrlString); } catch (MalformedURLException e) { ss.fatal(this, "Can't connect to Solr search engine. " + "The value for vitro.local.solr.url " + "in runtime.properties is not a valid URL: '" + solrUrlString + "'", e); } ss.info(this, "Starting thread for Solr test."); new SolrSmokeTestThread(this, solrUrl, ss).start(); }
From source file:com.apdplat.platform.spring.APDPlatContextLoaderListener.java
/** * Initialize the root web application context. *///from w w w .jav a 2 s.co m public void contextInitialized(ServletContextEvent event) { SystemListener.contextInitialized(event); this.contextLoader = createContextLoader(); if (this.contextLoader == null) { this.contextLoader = this; } this.contextLoader.initWebApplicationContext(event.getServletContext()); }