List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.apdplat.platform.spring.APDPlatContextLoaderListener.java
/** * Close the root web application context. */// ww w . j a v a 2s. c o m public void contextDestroyed(ServletContextEvent event) { SystemListener.contextDestroyed(event); if (this.contextLoader != null) { this.contextLoader.closeWebApplicationContext(event.getServletContext()); } ContextCleanupListener.cleanupAttributes(event.getServletContext()); }
From source file:pt.webdetails.cdc.servlet.CdcServletContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { logger.info("contextInitialized"); HazelcastManager manager = HazelcastManager.INSTANCE; ICdcConfig cdcConfig = new CdcServletConfig(new ServletContextConfig(sce.getServletContext())); manager.configure(cdcConfig);// ww w. j ava2 s. c o m try { manager.init(); } catch (IOException e) { logger.error("Hazelcast Manager failed to initialize", e); } }
From source file:org.sakaiproject.util.ToolListener.java
/** * Initialize.//w w w .j av a 2 s .c o m */ public void contextInitialized(ServletContextEvent event) { // The the location of resource and registration files. Set paths = event.getServletContext().getResourcePaths("/tools/"); final String sakaiHomePath = ServerConfigurationService.getSakaiHomePath(); // First Pass: Search for tool registration file. if (paths == null) { return; } int registered = 0; for (Iterator i = paths.iterator(); i.hasNext();) { final String path = (String) i.next(); // skip directories if (path.endsWith("/")) continue; // If an XML file, use it as the tool registration file. if (path.endsWith(".xml")) { final File f = new File(sakaiHomePath + path); if (f.exists()) { ActiveToolManager.register(f, event.getServletContext()); ToolListener.M_log.info("overriding tools configuration: registering tools from resource: " + sakaiHomePath + path); } else { M_log.info("registering tools from resource: " + path); ActiveToolManager.register(event.getServletContext().getResourceAsStream(path), event.getServletContext()); } registered++; } } if (registered == 0) { // Probably misconfigured as we should have at least one registered. M_log.warn("No tools found to be registered."); } // Second pass, search for message bundles. Two passes are necessary to make sure the tool is registered first. for (Iterator j = paths.iterator(); j.hasNext();) { String path = (String) j.next(); // skip directories if (path.endsWith("/")) continue; // Check for a message properties file. if (path.endsWith(".properties")) { // Extract the tool id from the resource file name. File reg = new File(path); String tn = reg.getName(); String tid = null; if (tn.indexOf('_') == -1) tid = tn.substring(0, tn.lastIndexOf('.')); // Default file. else tid = tn.substring(0, tn.indexOf('_')); // Locale-based file. String msg = event.getServletContext() .getRealPath(path.substring(0, path.lastIndexOf('.')) + ".properties"); if (tid != null) { ActiveToolManager.setResourceBundle(tid, msg); M_log.info("Added localization resources for " + tid); } } } }
From source file:org.jumpmind.metl.ui.init.AppInitializer.java
@Override public void contextInitialized(ServletContextEvent sce) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); LogUtils.initLogging(getConfigDir(false), ctx); initDatabase(ctx);/*from ww w . j a va 2 s . c o m*/ initAgentRuntime(ctx); }
From source file:com.liangc.hq.base.web.ConfiguratorListener.java
/** * Respond to the <em>context initialized</em> container event by * loading the application properties file and the portals * definition file.// w w w . j ava 2 s . c o m * */ public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); loadConfig(ctx); loadPreferences(ctx); loadTablePreferences(ctx); loadBuildNumber(ctx); }
From source file:org.toobsframework.servlet.ContextListener.java
public void contextDestroyed(ServletContextEvent event) { if (scheduler != null) { scheduler.destroy();/*from w w w. j a v a 2 s. c o m*/ } //super.contextDestroyed(event); if (this.contextLoader != null) { this.contextLoader.closeWebApplicationContext(event.getServletContext()); } context = null; }
From source file:com.bstek.dorado.web.servlet.DoradoPreloadListener.java
public void contextInitialized(ServletContextEvent event) { try {/*from w w w . j a v a 2 s .c o m*/ DelegatingServletContextListenersManager.fireContextInitialized(event); DoradoLoader doradoLoader = DoradoLoader.getInstance(); ServletContext servletContext = event.getServletContext(); doradoLoader.preload(servletContext, false); } catch (Exception e) { logger.error(e, e); } }
From source file:org.sindice.analytics.servlet.AssistedSparqlEditorListener.java
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); final ServletContext context = sce.getServletContext(); logger.info("initializing ASE context"); XMLConfiguration config = (XMLConfiguration) sce.getServletContext().getAttribute("config"); context.setAttribute(RECOMMENDER_WRAPPER + RANKING_CONFIGURATION, createRankingConfigFile()); final String datasetLabelDef = getParameterWithLogging(config, RECOMMENDER_WRAPPER + "." + DATASET_LABEL_DEF, AnalyticsVocab.DATASET_LABEL_DEF.toString()); context.setAttribute(RECOMMENDER_WRAPPER + DATASET_LABEL_DEF, datasetLabelDef); final String domainUriPrefix = getParameterWithLogging(config, RECOMMENDER_WRAPPER + "." + DOMAIN_URI_PREFIX, AnalyticsVocab.DOMAIN_URI_PREFIX); context.setAttribute(RECOMMENDER_WRAPPER + DOMAIN_URI_PREFIX, domainUriPrefix); final String backend = getParameterWithLogging(config, RECOMMENDER_WRAPPER + "." + BACKEND, BackendType.HTTP.toString()); context.setAttribute(RECOMMENDER_WRAPPER + BACKEND, backend); final String[] backendArgs = getParametersWithLogging(config, RECOMMENDER_WRAPPER + "." + BACKEND_ARGS, new String[] { "http://sparql.sindice.com/sparql" }); context.setAttribute(RECOMMENDER_WRAPPER + BACKEND_ARGS, backendArgs); final String limit = getParameterWithLogging(config, RECOMMENDER_WRAPPER + "." + PAGINATION, Integer.toString(SesameBackend.LIMIT)); context.setAttribute(RECOMMENDER_WRAPPER + PAGINATION, Integer.valueOf(limit)); final String[] classAttributes = getParametersWithLogging(config, RECOMMENDER_WRAPPER + "." + CLASS_ATTRIBUTES, new String[] { AnalyticsClassAttributes.DEFAULT_CLASS_ATTRIBUTE }); context.setAttribute(RECOMMENDER_WRAPPER + CLASS_ATTRIBUTES, classAttributes); final String useMemcached = getParameterWithLogging(config, "USE_MEMCACHED", "false"); final String memcachedHost = getParameterWithLogging(config, "MEMCACHED_HOST", "localhost"); final String memcachedPort = getParameterWithLogging(config, "MEMCACHED_PORT", "11211"); if (Boolean.parseBoolean(useMemcached)) { try {//from w w w . j ava 2 s . c om final List<InetSocketAddress> addresses = AddrUtil .getAddresses(memcachedHost + ":" + memcachedPort); wrapper = new MemcachedClientWrapper(new MemcachedClient(addresses)); sce.getServletContext().setAttribute(MemcachedClientWrapper.class.getName(), wrapper); } catch (IOException e) { logger.error("Could not initialize memcached !!!", e); } } }
From source file:org.sindice.core.analytics.commons.webapps.SparqledContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { final ServletContext context = sce.getServletContext(); addEnvToContext(context);//from w w w . ja v a 2 s . c o m final String home = (String) context.getInitParameter(SPARQLED_HOME); final File sparqledHome = home == null ? null : new File(home); if (sparqledHome == null || !sparqledHome.exists()) { throw new RuntimeException("Missing sparqled home"); } logger.info("Looking for configuration in [{}]", sparqledHome); configureLogging(context, sparqledHome); final XMLConfiguration config = createXMLConfiguration(context); final File applicationConfigFile = new File(sparqledHome, CONFIG_XML); try { config.load(applicationConfigFile); } catch (ConfigurationException e) { throw new RuntimeException("Invalid configuration file: " + applicationConfigFile, e); } // important to set this as it is used later in logback.xml context.setAttribute("sparqled.home", home); context.setAttribute("config", config); logger.info("config now availabe via the following line of code\n" + " XMLConfiguration appConfig = (XMLConfiguration) servletContext.getAttribute(\"config\");"); }
From source file:org.eap.web.listener.WebApplicationDataListener.java
public void contextInitialized(final ServletContextEvent sce) { EapDataContext.setWac(WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext())); EapDataContext.REAL_PATH = sce.getServletContext().getRealPath("/WEB-INF/"); EapDataContext.SAVE_FILE_DIR = sce.getServletContext().getRealPath(EapDataContext.SAVE_FILE_DIR); EapDataContext.initPlugin();// www .j a v a2 s . c o m EapSmcDataContext.initData(); /** * ??RPC? */ try { // Thread checkThread = new Thread(new Runnable() { // @Override // public void run() { // String[] hosts = sce.getServletContext().getInitParameter("rpc.host").split(",") ; // while(true){ //// for(int i=0 ; i<APIContext.getRpcServers().size() ; ){ //// Client client = APIContext.getRpcServers().get(i) ; //// if((System.currentTimeMillis()-client.getLastPingTime())> 10 * 1000 && client.isConnected()){ //// client.close() ; //// APIContext.getRpcServers().remove(i) ; //// continue ; //// } //// i++; //// } // if((APIContext.getRpcServers().size() + APIContext.getWaitConnectionServers().size())==hosts.length){ // try { // Thread.sleep(3000) ; // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // }else{ // for(String host : hosts){ // boolean live = false ; // for(Client client:APIContext.getRpcServers()){ // if(host.equals(client.getHost())){ // live = true ; // break ; // } // } // for(Client client:APIContext.getWaitConnectionServers()){ // if(host.equals(client.getHost())){ // live = true ; // break ; // } // } // if(!live){ // System.out.println("Server"); // String[] server = host.split(":"); // if(server.length == 2){ // new Client( server[0] , Integer.parseInt(server[1]),host , new MessageHandler()); // } // // } // } // } // } // } // }); // checkThread.start(); EapDataContext.initJars(EapDataContext.REAL_PATH); EapDataContext.initInstruct(); /** * ?? */ IndexTools.getInstance(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }