List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java
/** * Initializes the application context by web flow xml configs. * @param servletContextEvent the servlet context event. *//*from www . ja va2 s. c om*/ public void contextInitialized(ServletContextEvent servletContextEvent) { final ServletContext servletContext = servletContextEvent.getServletContext(); final WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); final String[] configLocations = getConfigLocations(context, initParameter); final Set<URL> xmlConfigs = new HashSet<URL>(); for (String configLocation : configLocations) { try { final Resource[] locationResources = context.getResources(configLocation); for (Resource locationResource : locationResources) { xmlConfigs.add(locationResource.getURL()); } } catch (IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not find state chart configuration", e); } } } Assert.notEmpty(xmlConfigs, "Cannot find state chart configuration."); ApplicationContextLocator.setWebFlowConfiguration(xmlConfigs); ApplicationContextLocator.setApplicationContext(context); final FlowConfigurationLoader flowConfigurationLoader = (FlowConfigurationLoader) context .getBean("flowConfigurationLoader"); flowConfigurationLoader.init(xmlConfigs); }
From source file:org.cipango.sipatra.DefaultContextLoader.java
public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); String appPath = servletContext.getRealPath("/WEB-INF/sipatra"); String scriptPath = PropertyUtils.getStringProperty(Properties.SIPATRA_PATH_PROPERTY, null, servletContext); if (scriptPath == null) { scriptPath = appPath + "/application.rb"; } else {/*from w w w.j a v a 2 s. c o m*/ File file = new File(scriptPath); if (!file.exists()) { _log.error(file.getAbsolutePath() + " does not exist!"); scriptPath = null; } if (file.isFile()) { if (!file.getName().endsWith(".rb")) _log.warn(file.getAbsolutePath() + " is not a ruby file!"); if (file.getParentFile() != null) appPath = file.getParentFile().getAbsolutePath(); else _log.error(file.getAbsolutePath() + " got no parent directory!"); } else if (file.isDirectory()) { appPath = new File(scriptPath).getAbsolutePath(); } } Config conf = new Config(); conf.maxActive = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_ACTIVE_PROPERTY, -1, servletContext); conf.maxIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_IDLE_PROPERTY, -1, servletContext); conf.maxWait = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_WAIT_PROPERTY, -1, servletContext); conf.minIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MIN_IDLE_PROPERTY, -1, servletContext); conf.minEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_MIN_EVICTABLE_PROPERTY, 1000L * 60L * 30L, servletContext); conf.lifo = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_LIFO, false, servletContext); conf.numTestsPerEvictionRun = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_TEST_EVICTION_RUN, 3, servletContext); conf.softMinEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_SOFT_MIN_EVICTABLE, -1L, servletContext); conf.testOnBorrow = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_BORROW, false, servletContext); conf.testOnReturn = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_RETURN, false, servletContext); conf.testWhileIdle = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_IDLE, false, servletContext); conf.timeBetweenEvictionRunsMillis = PropertyUtils.getLongProperty(Properties.SIPATRA_POOL_TIME_EVICTION, -1L, servletContext); GenericObjectPool pool = new GenericObjectPool(new JRubyRuntimeFactory(appPath, scriptPath), conf); startPool(pool, PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_INIT_POOL_SIZE, 1, servletContext)); servletContext.setAttribute(Attributes.POOL, pool); }
From source file:it.scoppelletti.programmerpower.wui.WebApplicationRegistry.java
/** * Termine di un’applicazione Web. * //from w w w .java 2s.c o m * <P>Questa implementazione del metodo {@code contextDestroyed} imposta * l’istante di termine dell’applicazione Web nel registro delle * applicazioni.</P> * * @param event Evento. */ public void contextDestroyed(ServletContextEvent event) { unregisterApplication(event.getServletContext().getContextPath()); }
From source file:org.psikeds.common.config.ContextLoaderListener.java
/** * Servlet is shutting down. Close context and destroy Spring-Beans. *//*from ww w .ja va 2s . co m*/ @Override public void contextDestroyed(final ServletContextEvent event) { if (this.contextLoader != null) { this.contextLoader.closeWebApplicationContext(event.getServletContext()); } final ServletContext sc = event.getServletContext(); final Enumeration<?> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { final String attrName = (String) attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { final Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (final Exception ex) { LOGGER.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
From source file:cn.im47.cloud.storage.ftp.FtpServerListener.java
public void contextInitialized(ServletContextEvent sce) { logger.debug("Starting FtpServer"); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); FtpServer server = (FtpServer) ctx.getBean("myFtpServer"); sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server); try {/*ww w . j a v a2 s .c o m*/ server.start(); logger.debug("FtpServer started"); } catch (Exception e) { logger.error("Failed to start FtpServer", e); throw new RuntimeException("Failed to start FtpServer", e); } }
From source file:se.vgregion.webbisar.web.FtpServerListener.java
public void contextInitialized(ServletContextEvent sce) { LOGGER.info("Starting FtpServer"); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); FtpServer server = (FtpServer) ctx.getBean("myServer"); sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server); try {//w w w. j a v a 2s .c om server.start(); LOGGER.info("FtpServer started"); } catch (Exception e) { throw new RuntimeException("Failed to start FtpServer", e); } }
From source file:com.bluexml.xforms.controller.navigation.NavigationSessionListener.java
public void contextInitialized(ServletContextEvent event) { context = event.getServletContext(); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.AssembleModelsSetup.java
public void contextInitialized(ServletContextEvent sce) { OntModel jenaOntModel = null;//from w w w . ja va 2s. c o m try { jenaOntModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel"); } catch (Exception e) { log.error("No baseOntModel found to which to attach assembled models"); return; } // read assemblers out of assemblers directory Set pathSet = sce.getServletContext().getResourcePaths(ASSEMBLERS_DIR_PATH); for (String path : (Set<String>) pathSet) { InputStream assemblerInputStream = sce.getServletContext().getResourceAsStream(path); Model assemblerModel = ModelFactory.createDefaultModel(); try { assemblerModel.read(assemblerInputStream, null, SYNTAX); ExtendedIterator assemblerIt = assemblerModel.listResourcesWithProperty(RDF.type, ASSEMBLER_OBJECT); while (assemblerIt.hasNext()) { Resource assemblerObj = (Resource) assemblerIt.next(); Model assembledModel = Assembler.general.openModel(assemblerObj); /* special stuff here */ Model memModel = ModelFactory.createDefaultModel(); memModel.add(assembledModel); memModel.register(new ModelSynchronizer(assembledModel)); /* end special stuff */ if (assembledModel != null) { jenaOntModel.addSubModel(memModel); } } if (assemblerIt != null) { assemblerIt.close(); } } catch (Exception e) { log.error("Unable to use assembler at " + path); } } System.out.println("ContextListener AssembleModelsSetup done"); }
From source file:org.tangram.guice.DefaultTangramContextListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { LOG.info("contextInitialized()"); ServletContext context = servletContextEvent.getServletContext(); String webModuleClassName = context.getInitParameter(SHIRO_WEB_MODULE_CLASS); String dispatcherPath = context.getInitParameter(DISPATCHER_PATH); dispatcherPath = dispatcherPath == null ? "/s" : dispatcherPath; if (StringUtils.isNotBlank(webModuleClassName)) { try {//from w w w . j a v a 2 s .c om Class<?> forName = Class.forName(webModuleClassName); Object[] args = { context, dispatcherPath }; shiroWebModule = (Module) forName.getConstructors()[0].newInstance(args); } catch (Exception e) { LOG.error("contextInitialized() cannot obtain shiro web module", e); } // try/catch } // if LOG.info("contextInitialized() shiro web module: {} :{}", shiroWebModule, webModuleClassName); String servletModuleClassName = context.getInitParameter(SERVLET_MODULE_CLASS); if (StringUtils.isNotBlank(servletModuleClassName)) { try { Class<?> forName = Class.forName(servletModuleClassName); servletModule = (ServletModule) forName.getConstructors()[0].newInstance(new Object[0]); } catch (Exception e) { LOG.error("contextInitialized() cannot obtain servlet module", e); } // try/catch } // if servletModule = servletModule == null ? new TangramServletModule() : servletModule; LOG.info("contextInitialized() servlet module: {} :{}", servletModule, servletModuleClassName); super.contextInitialized(servletContextEvent); }
From source file:nl.b3p.viewer.solr.SolrInitializer.java
@Override public void contextInitialized(ServletContextEvent sce) { log.debug("SolrInitializer initializing"); this.context = sce.getServletContext(); init();/*w w w.j a va 2s .co m*/ System.setProperty("solr.solr.home", datadirectory + File.separator + SOLR_DIR); File dataDirectory = new File(datadirectory); if (!isCorrectDir(dataDirectory)) { log.error("Cannot read/write data dir " + datadirectory + ". Solr searching not possible."); return; } log.info("Data dir set " + datadirectory); File solrDir = new File(dataDirectory, SOLR_DIR); if (setupSolr && !solrDir.exists()) { setupSolr(solrDir); } inializeSolr(solrDir); }