List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.litt.saap.core.web.listener.InitSystemListener.java
/** * ?.//from w w w. ja v a 2 s.co m */ public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); ServletContext application = event.getServletContext(); //HOME? Configuration config = ConfigManager.getInstance().getConfig(); if (config.isEmpty()) { logger.error("???"); throw new java.lang.RuntimeException("???"); } logger.info("?" + config.getString("system.version")); //homePath = props.getProperty("home.path"); String homePath = config.getString("home.path"); CoreConstants.IS_DEBUG = config.getBoolean("debug", false); SaapConstants.HOME_PATH = homePath; //???? logger.info("?" + homePath); File homeFile = new File(homePath); if (!homeFile.exists()) //??? { homeFile.mkdirs(); } //read license. // File licensePath = new File(homePath, "license"); // File licenseFile = new File(licensePath, "license.xml"); // File publicKeyFile = new File(licensePath, "license.key"); // try { // LicenseManager.reload(licenseFile.getPath(), publicKeyFile.getPath()); // } catch (LicenseException e) { // logger.error("Can't read license file.", e); // } String contextPath = application.getContextPath(); //???APPLICATION ISystemInfoService systemInfoService = BeanManager.getBean("systemInfoService", ISystemInfoService.class); SystemInfoVo systemInfoVo = systemInfoService.getSystemInfo(); systemInfoVo.setBaseUrl(config.getString("baseUrl") + contextPath); systemInfoVo.setHomePath(homePath); application.setAttribute(CoreConstants.APP_SYSTEMINFO, systemInfoVo); //servlet? }
From source file:org.apache.tiles.test.init.InitContextListener.java
/** {@inheritDoc} */ public void contextInitialized(ServletContextEvent event) { DataSource dataSource = createDataSource(); event.getServletContext().setAttribute("dataSource", dataSource); String[] commands = getSQLCommands(); executeCommands(dataSource, commands); }
From source file:org.wso2.carbon.mdm.mobileservices.windows.common.util.ContextListener.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. *//* w w w .j av a2 s . co m*/ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); File propertyFile = new File( getClass().getClassLoader().getResource(Constants.CertificateEnrolment.PROPERTIES_XML).getFile()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { logger.error("XML parsing configuration exception."); } Document document = null; try { document = docBuilder.parse(propertyFile); } catch (SAXException e) { logger.error("XML Parsing Exception."); } catch (IOException e) { logger.error("XML property file reading exception."); } String MDMPassword = document.getElementsByTagName(Constants.CertificateEnrolment.MDM_PASSWORD) .item(FIRST_ITEM).getTextContent(); String MDMPrivateKeyPassword = document .getElementsByTagName(Constants.CertificateEnrolment.MDM_PRIVATE_KEY_PASSWORD).item(FIRST_ITEM) .getTextContent(); String signedCertCommonName = document.getElementsByTagName(SIGNED_CERT_CN).item(FIRST_ITEM) .getTextContent(); int signedCertNotBeforeDate = Integer .valueOf(document.getElementsByTagName(SIGNED_CERT_NOT_BEFORE).item(FIRST_ITEM).getTextContent()); int signedCertNotAfterDate = Integer .valueOf(document.getElementsByTagName(SIGNED_CERT_NOT_AFTER).item(FIRST_ITEM).getTextContent()); servletContext.setAttribute(Constants.CONTEXT_MDM_PASSWORD, MDMPassword); servletContext.setAttribute(Constants.CONTEXT_MDM_PRIVATE_KEY_PASSWORD, MDMPrivateKeyPassword); servletContext.setAttribute(Constants.CONTEXT_COMMON_NAME, signedCertCommonName); servletContext.setAttribute(Constants.CONTEXT_NOT_BEFORE_DATE, signedCertNotBeforeDate); servletContext.setAttribute(Constants.CONTEXT_NOT_AFTER_DATE, signedCertNotAfterDate); File wapProvisioningFile = new File(getClass().getClassLoader() .getResource(Constants.CertificateEnrolment.WAP_PROVISIONING_XML).getFile()); servletContext.setAttribute(Constants.CONTEXT_WAP_PROVISIONING_FILE, wapProvisioningFile); }
From source file:org.wso2.carbon.mdm.mobileservices.windowspc.common.util.ContextListener.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. *//* w ww .j av a 2 s . c om*/ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); File propertyFile = new File( getClass().getClassLoader().getResource(Constants.CertificateEnrollment.PROPERTIES_XML).getFile()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { logger.error("XML parsing configuration exception."); } Document document = null; try { document = docBuilder.parse(propertyFile); } catch (SAXException e) { logger.error("XML Parsing Exception."); } catch (IOException e) { logger.error("XML property file reading exception."); } String MDMPassword = document.getElementsByTagName(Constants.CertificateEnrollment.MDM_PASSWORD) .item(FIRST_ITEM).getTextContent(); String MDMPrivateKeyPassword = document .getElementsByTagName(Constants.CertificateEnrollment.MDM_PRIVATE_KEY_PASSWORD).item(FIRST_ITEM) .getTextContent(); String signedCertCommonName = document.getElementsByTagName(SIGNED_CERT_CN).item(FIRST_ITEM) .getTextContent(); int signedCertNotBeforeDate = Integer .valueOf(document.getElementsByTagName(SIGNED_CERT_NOT_BEFORE).item(FIRST_ITEM).getTextContent()); int signedCertNotAfterDate = Integer .valueOf(document.getElementsByTagName(SIGNED_CERT_NOT_AFTER).item(FIRST_ITEM).getTextContent()); servletContext.setAttribute(Constants.CONTEXT_MDM_PASSWORD, MDMPassword); servletContext.setAttribute(Constants.CONTEXT_MDM_PRIVATE_KEY_PASSWORD, MDMPrivateKeyPassword); servletContext.setAttribute(Constants.CONTEXT_COMMON_NAME, signedCertCommonName); servletContext.setAttribute(Constants.CONTEXT_NOT_BEFORE_DATE, signedCertNotBeforeDate); servletContext.setAttribute(Constants.CONTEXT_NOT_AFTER_DATE, signedCertNotAfterDate); File wapProvisioningFile = new File(getClass().getClassLoader() .getResource(Constants.CertificateEnrollment.WAP_PROVISIONING_XML).getFile()); servletContext.setAttribute(Constants.CONTEXT_WAP_PROVISIONING_FILE, wapProvisioningFile); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.RDFServiceSetup.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); try {//from w w w. jav a 2s. c o m String endpointURI = ConfigurationProperties.getBean(sce) .getProperty("VitroConnection.DataSource.endpointURI"); String updateEndpointURI = ConfigurationProperties.getBean(sce) .getProperty("VitroConnection.DataSource.updateEndpointURI"); if (endpointURI != null) { useEndpoint(endpointURI, updateEndpointURI, ctx); } else { useSDB(ctx, ss); } //experimental //RDFServiceFactory factory = RDFServiceUtils.getRDFServiceFactory(ctx); //RDFServiceUtils.setRDFServiceFactory(ctx, new SameAsFilteringRDFServiceFactory(factory)); } catch (SQLException e) { ss.fatal(this, "Exception in RDFServiceSetup", e); } }
From source file:org.mobicents.servlet.sip.pbx.PbxListener.java
public void contextInitialized(ServletContextEvent event) { try {//from w w w. ja v a 2s . co m LocationService locationService = new DbLocationService(); locationService.start(); event.getServletContext().setAttribute(Constants.LOCATION_SERVICE, locationService); logger.info("Initialized PBX context"); } catch (Exception e) { logger.warn("Failed to initialize PBX context", e); } }
From source file:com.telefonica.euro_iaas.paasmanager.bootstrap.SynchronizationBoostrap.java
/** {@inheritDoc} */ public void contextInitialized(ServletContextEvent event) { log.info("SynchronizationBootstrap. START"); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); log.info("SynchronizationBootstrap. FINISH"); }
From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java
/** On shutdown, clean up. */ @Override/*from www. jav a 2s. c om*/ public void contextDestroyed(ServletContextEvent sce) { RevisionInfoBean.removeBean(sce.getServletContext()); }
From source file:com.xhsoft.framework.common.listener.ApplicationContextListener.java
public void contextInitialized(ServletContextEvent event) { try {/*w ww.jav a 2 s . c o m*/ ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(event.getServletContext()); ServletContext sc = event.getServletContext(); String appName = sc.getServletContextName(); logger.info("[" + appName + "] init context ..."); AppServiceHelper.setApplicationContext(applicationContext); logger.info(" - Put Spring Context to AppServiceHelper"); String facility = sc.getInitParameter("facility"); AppContext.addParam(AppContext.FACILITY, facility); logger.info(" - Put FACILITY[" + facility + "] to AppContext"); logger.info("[" + appName + "] init context[done]"); } catch (Exception e) { logger.error("error detail:", e); } }
From source file:org.alfresco.repo.webdav.WebDAVSessionListener.java
@Override public void contextInitialized(ServletContextEvent sce) { ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(sce.getServletContext()); this.webDAVLockService = (WebDAVLockService) context.getBean(WebDAVLockService.BEAN_NAME); }