List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.cubusmail.gwtui.server.services.CubusStartupListener.java
public void contextInitialized(ServletContextEvent servletcontextevent) { try {// www .j ava 2s. com WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(servletcontextevent.getServletContext()); BeanFactory.setContext(context); } catch (Throwable e) { log.fatal(e.getMessage(), e); throw new IllegalStateException("Could not load " + CubusConstants.LOGIN_MODULE_CONFIG_FILE); } try { URL test = CubusStartupListener.class.getClassLoader() .getResource(CubusConstants.LOGIN_MODULE_CONFIG_FILE); System.setProperty(CubusConstants.JAAS_PROPERTY_NANE, test.getFile()); } catch (Throwable e) { log.fatal(e.getMessage(), e); throw new IllegalStateException("Could not load " + CubusConstants.LOGIN_MODULE_CONFIG_FILE); } }
From source file:edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup.java
@Override public void contextDestroyed(ServletContextEvent sce) { IndexBuilder builder = (IndexBuilder) sce.getServletContext().getAttribute(IndexBuilder.class.getName()); if (builder != null) builder.stopIndexingThread();//ww w .j a v a 2s . co m }
From source file:org.giavacms.cache.listener.CacheListener.java
@Override public void contextInitialized(ServletContextEvent sce) { StringBuffer physicalDir = new StringBuffer(); String docBaseProperty = sce.getServletContext().getInitParameter("baseFolderSystemProperty"); logger.info("baseFolderSystemProperty: " + docBaseProperty); if (docBaseProperty != null && !docBaseProperty.trim().isEmpty()) { // se inizia per $ una var di sistema if (docBaseProperty.trim().startsWith("$")) { String docBase = System.getenv(docBaseProperty.trim().substring(1)); if (docBase != null && !docBase.isEmpty()) physicalDir.append(docBase); } else {/* www . j a va2s .co m*/ // altrimenti la suo cosi com' physicalDir.append(docBaseProperty); } } String pagesPath = sce.getServletContext().getInitParameter(MappingFilter.PAGES_PATH_PARAM_NAME); physicalDir.append(pagesPath); backupDir = new File(physicalDir.toString()); boolean backupRestored = false; if (backupDir.exists() && backupDir.isDirectory()) { try { cacheDir = cacheService.getAbsolutePath(pagesPath); if (cacheDir.exists()) { cacheDir.delete(); } FileUtils.moveDirectory(backupDir, cacheDir); logger.info("Pages backup restored from " + backupDir.getAbsolutePath() + " --> " + cacheDir.getAbsolutePath()); backupRestored = true; } catch (Exception e) { logger.error("Pages backup NOT restored from " + backupDir.getAbsolutePath()); logger.error(e.getMessage(), e); } } if (!backupRestored) { cacheService.writeAll(pagesPath); logger.warn("Pages backup NOT restored; brand new pages cache saved to " + pagesPath); } try { cacheDir = cacheService.getAbsolutePath(pagesPath); } catch (Exception e) { } }
From source file:org.wso2.carbon.mdm.mobileservices.windows.common.util.ConfigInitializerContextListener.java
/** * This method loads wap-provisioning file / property file, sets wap-provisioning file and * extracted properties as attributes in servlet context. * * @param servletContextEvent - Uses when servlet communicating with servlet container. *///from w ww . j a va2 s .c o m @Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); File propertyFile = new File(getClass().getClassLoader() .getResource(PluginConstants.CertificateEnrolment.PROPERTIES_XML).getFile()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; Document document = null; try { docBuilder = docBuilderFactory.newDocumentBuilder(); if (docBuilder != null) { document = docBuilder.parse(propertyFile); } } catch (ParserConfigurationException e) { log.error("Parser configuration failure while reading properties.xml."); } catch (SAXException e) { log.error("Parsing error occurred while reading properties.xml."); } catch (IOException e) { log.error("File reading error occurred while accessing properties.xml."); } String password = null; String privateKeyPassword = null; String signedCertCommonName = null; String authPolicy = null; String domain = null; int signedCertNotBeforeDate = INITIAL_VALUE; int signedCertNotAfterDate = INITIAL_VALUE; if (document != null) { password = document.getElementsByTagName(PropertyName.PROPERTY_PASSWORD.getValue()).item(0) .getTextContent(); privateKeyPassword = document .getElementsByTagName(PropertyName.PROPERTY_PRIVATE_KEY_PASSWORD.getValue()).item(0) .getTextContent(); signedCertCommonName = document.getElementsByTagName(PropertyName.PROPERTY_SIGNED_CERT_CN.getValue()) .item(0).getTextContent(); authPolicy = document.getElementsByTagName(PropertyName.AUTH_POLICY.getValue()).item(0) .getTextContent(); signedCertNotBeforeDate = Integer .valueOf(document.getElementsByTagName(PropertyName.PROPERTY_SIGNED_CERT_NOT_BEFORE.getValue()) .item(0).getTextContent()); signedCertNotAfterDate = Integer .valueOf(document.getElementsByTagName(PropertyName.PROPERTY_SIGNED_CERT_NOT_AFTER.getValue()) .item(0).getTextContent()); domain = document.getElementsByTagName(PropertyName.DOMAIN.getValue()).item(0).getTextContent(); } WindowsPluginProperties properties = new WindowsPluginProperties(); properties.setKeyStorePassword(password); properties.setPrivateKeyPassword(privateKeyPassword); properties.setCommonName(signedCertCommonName); properties.setNotBeforeDays(signedCertNotBeforeDate); properties.setNotAfterDays(signedCertNotAfterDate); properties.setAuthPolicy(authPolicy); properties.setDomain(domain); servletContext.setAttribute(PluginConstants.WINDOWS_PLUGIN_PROPERTIES, properties); File wapProvisioningFile = new File(getClass().getClassLoader() .getResource(PluginConstants.CertificateEnrolment.WAP_PROVISIONING_XML).getFile()); servletContext.setAttribute(PluginConstants.CONTEXT_WAP_PROVISIONING_FILE, wapProvisioningFile); }
From source file:org.psikeds.common.config.ContextLoaderListener.java
/** * Initialization of web application is starting. * Install context-loader and -proxy.//from ww w . ja v a 2 s. c o m */ @Override public void contextInitialized(final ServletContextEvent event) { if (this.contextLoader == null) { this.contextLoader = this; } final ServletContext ctx = ServletContextProxy.newInstance(event.getServletContext()); this.contextLoader.initWebApplicationContext(ctx); }
From source file:edu.cornell.mannlib.vitro.webapp.startup.StartupManager.java
/** * Build a list of the listeners, and run contextInitialized() on each of * them, at least until we get a fatal error. * /*w ww .j a v a 2 s. c o m*/ * Each step of this should handle its own exceptions, but we'll wrap the * whole thing in a try/catch just in case. */ @Override public void contextInitialized(ServletContextEvent sce) { ctx = sce.getServletContext(); ss = StartupStatus.getBean(ctx); try { findAndInstantiateListeners(); for (ServletContextListener listener : initializeList) { if (ss.isStartupAborted()) { ss.listenerNotExecuted(listener); } else { initialize(listener, sce); } } log.info("Called 'contextInitialized' on all listeners."); } catch (Exception e) { ss.fatal(this, "Startup threw an unexpected exception.", e); log.error("Startup threw an unexpected exception.", e); } catch (Throwable t) { log.fatal("Startup threw an unexpected error.", t); throw t; } }
From source file:org.opencms.main.OpenCmsListener.java
/** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) *//*from w ww . j a v a2 s . c om*/ public void contextInitialized(ServletContextEvent event) { try { // upgrade the OpenCms runlevel OpenCmsCore.getInstance().upgradeRunlevel(event.getServletContext()); } catch (CmsInitException e) { if (e.isNewError()) { // only log new init errors LOG.error(e.getLocalizedMessage(), e); } } catch (Throwable t) { // make sure all other errors are displayed in the OpenCms log LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_GENERIC_0), t); // throw a new init Exception to make sure a "context destroyed" event is triggered throw new CmsInitException( Messages.get().container(Messages.ERR_CRITICAL_INIT_GENERIC_1, t.getMessage())); } }
From source file:alpha.portal.webapp.listener.UserCounterListener.java
/** * Initialize the context./*from www . ja v a 2 s . c o m*/ * * @param sce * the event */ public synchronized void contextInitialized(final ServletContextEvent sce) { this.servletContext = sce.getServletContext(); this.servletContext.setAttribute((UserCounterListener.COUNT_KEY), Integer.toString(this.counter)); }
From source file:org.apache.jetspeed.security.mfa.impl.MFAServletListener.java
public void contextInitialized(ServletContextEvent event) { String configLocation = "/WEB-INF/mfa.properties"; String ttsConfigLocation = "/WEB-INF/tts.properties"; try {// www.j av a 2s .c o m InputStream is = event.getServletContext().getResourceAsStream(configLocation); PropertiesConfiguration config = new PropertiesConfiguration(); config.load(is); is.close(); InputStream tis = event.getServletContext().getResourceAsStream(ttsConfigLocation); PropertiesConfiguration ttsConfig = new PropertiesConfiguration(); ttsConfig.load(tis); tis.close(); String rootPath = event.getServletContext().getRealPath("/"); MultiFacetedAuthentication mfa = new MultiFacetedAuthenticationImpl(config, ttsConfig, rootPath); MFA.setInstance(mfa); } catch (Throwable e) { logger.error("Unexpected error during loading configuration.", e); PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfiguration ttsConfig = new PropertiesConfiguration(); MultiFacetedAuthentication mfa = new MultiFacetedAuthenticationImpl(config, ttsConfig); MFA.setInstance(mfa); } }
From source file:eionet.gdem.web.listeners.AppServletContextListener.java
/** * Method that is triggered once on start of application (context initialization): * *//*from ww w. ja v a 2 s. c o m*/ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { System.out.println("Application started !"); try { Properties.metaXSLFolder = servletContextEvent.getServletContext().getRealPath("/dcm"); Properties.convFile = servletContextEvent.getServletContext().getRealPath("/dcm/conversions.xml"); Properties.odsFolder = servletContextEvent.getServletContext().getRealPath("/opendoc/ods"); Properties.appHome = servletContextEvent.getServletContext().getRealPath("/WEB-INF/classes"); checkFolders(); servletContextEvent.getServletContext().setAttribute("qascript.resulttypes", loadConvTypes(XQScript.SCRIPT_RESULTTYPES)); servletContextEvent.getServletContext().setAttribute("qascript.scriptlangs", loadConvTypes(XQScript.SCRIPT_LANGS)); servletContextEvent.getServletContext().setAttribute(QAScriptListLoader.QASCRIPT_PERMISSIONS_ATTR, QAScriptListLoader.loadQAScriptPermissions(null)); servletContextEvent.getServletContext().setAttribute(StylesheetListLoader.STYLESHEET_PERMISSIONS_ATTR, StylesheetListLoader.loadStylesheetPermissions(null)); } catch (Exception e1) { e1.printStackTrace(); } }