Example usage for javax.servlet ServletContextEvent getServletContext

List of usage examples for javax.servlet ServletContextEvent getServletContext

Introduction

In this page you can find the example usage for javax.servlet ServletContextEvent getServletContext.

Prototype

public ServletContext getServletContext() 

Source Link

Document

Return the ServletContext that changed.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup.java

@Override
public void contextDestroyed(ServletContextEvent sce) {
    log.info("received contextDestroyed notification");

    SimpleReasoner simpleReasoner = getSimpleReasonerFromServletContext(sce.getServletContext());
    if (simpleReasoner != null) {
        log.info("sending stop request to SimpleReasoner");
        simpleReasoner.setStopRequested();
    }// ww w  . j a  v a 2s  . c  om

    SimpleReasonerTBoxListener simpleReasonerTBoxListener = getSimpleReasonerTBoxListenerFromContext(
            sce.getServletContext());
    if (simpleReasonerTBoxListener != null) {
        log.info("sending stop request to simpleReasonerTBoxListener");
        simpleReasonerTBoxListener.setStopRequested();
    }

}

From source file:org.hippoecm.hst.demo.servlet.SolrConfigContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {

    String existingSolrHome = StringUtils.trimToNull(System.getProperty(SOLR_SOLR_HOME));
    if (existingSolrHome != null) {
        log.info("{} already exists: {}", SOLR_SOLR_HOME, existingSolrHome);
        return;//from ww  w  .j  ava  2 s  .  c  o m
    }

    String solrHome = StringUtils.trimToNull(sce.getServletContext().getInitParameter(SOLR_SOLR_HOME));
    if (solrHome == null) {
        return;
    }

    String realSolrHomePath = solrHome;

    if (solrHome.startsWith("/")) {
        realSolrHomePath = sce.getServletContext().getRealPath(solrHome);
    } else if (solrHome.startsWith("file:")) {
        try {
            realSolrHomePath = new File(URI.create(solrHome)).getCanonicalPath();
        } catch (IOException e) {
            throw new RuntimeException("Invalid parameter for " + SOLR_SOLR_HOME + ": " + solrHome + ". " + e);
        }
    }
    System.setProperty(SOLR_SOLR_HOME, realSolrHomePath);
    log.info("{}={}", SOLR_SOLR_HOME, System.getProperty(SOLR_SOLR_HOME));
}

From source file:org.onehippo.forge.solr.indexer.servlet.SolrConfigContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {

    String existingSolrHome = StringUtils.trimToNull(System.getProperty(SOLR_SOLR_HOME));
    if (existingSolrHome != null) {
        log.info("{} already exists: {}", SOLR_SOLR_HOME, existingSolrHome);
        return;/*from ww  w .ja v a2  s .  c  om*/
    }

    String solrHome = StringUtils.trimToNull(sce.getServletContext().getInitParameter(SOLR_SOLR_HOME));
    if (solrHome == null) {
        return;
    }

    String realSolrHomePath = solrHome;

    if (solrHome.startsWith("/")) {
        realSolrHomePath = sce.getServletContext().getRealPath(solrHome);
    } else if (solrHome.startsWith("file:")) {
        try {
            realSolrHomePath = new File(URI.create(solrHome)).getCanonicalPath();
        } catch (IOException e) {
            throw new RuntimeException("Invalid parameter for " + SOLR_SOLR_HOME + ": " + solrHome + ". " + e);
        }
    }

    System.setProperty(SOLR_SOLR_HOME, realSolrHomePath);
    log.info("{}={}", SOLR_SOLR_HOME, System.getProperty(SOLR_SOLR_HOME));
}

From source file:org.josso.gateway.signon.SSOContextListener.java

public void contextInitialized(ServletContextEvent event) {
    try {/*from  w ww  .  ja  va  2s  .com*/
        // This will initialize all needed components

        Lookup lookup = Lookup.getInstance();
        lookup.init("josso-gateway-config.xml");
        lookup.lookupSSOGateway();

        // Build and initialize the SSO Gateway
        ServletContext ctx = event.getServletContext();
        SSOGateway g = (SSOGateway) ctx.getAttribute(KEY_JOSSO_GATEWAY);
        if (g == null) {
            g = Lookup.getInstance().lookupSSOGateway();
            ctx.setAttribute(KEY_JOSSO_GATEWAY, g);
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

}

From source file:DatabaseListener.java

/**
 * <p>Initialize and load our initial database from persistent
 * storage.</p>//from   w  w w  .j a v  a2s .  com
 *
 * @param event The context initialization event
 */
public void contextInitialized(ServletContextEvent event) {

    log.info("Initializing memory database plug in from '" + pathname + "'");

    // Remember our associated ServletContext
    this.context = event.getServletContext();

    // Construct a new database and make it available
    database = new MemoryUserDatabase();
    try {
        String path = calculatePath();
        if (log.isDebugEnabled()) {
            log.debug(" Loading database from '" + path + "'");
        }
        database.setPathname(path);
        database.open();
    } catch (Exception e) {
        log.error("Opening memory database", e);
        throw new IllegalStateException("Cannot load database from '" + pathname + "': " + e);
    }
    context.setAttribute(DATABASE_KEY, database);

}

From source file:org.cnbi.web.system.listener.WebApplicationInitializer.java

public void contextInitialized(ServletContextEvent contextEvent) {
    this.servletContext = contextEvent.getServletContext();// sqlXmpName
    projectName = servletContext.getInitParameter("cnbi");
    String sqlXmpName = servletContext.getInitParameter(Constants.XMLSQLBEAN);
    realPath = this.servletContext.getRealPath(File.separator);
    springContext = WebApplicationContextUtils.getWebApplicationContext(contextEvent.getServletContext());
    handleService = (IHandleService) springContext.getBean("handleService"); // dashboardService
    initSql(sqlXmpName);//  w ww  .j ava 2  s. c  o  m
    initCompanyData();// ON_LINE_USERS
    // Map<String, HttpSession> onLineUser = new HashMap<String,
    // HttpSession>();
    // servletContext.setAttribute(Constants.ON_LINE_USERS, onLineUser);
    queryMenuList();
    initDimData();
    initSubjectData();
    checkLicenseInvalid();
    logger.info("?" + projectName
            + "????????=="
            + realPath);

}

From source file:com.brick.base.listener.ContextAndDataAccessorLoaderListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    SqlMapClient sqlMapClient = null;/*  w w  w  . j av a  2 s . com*/
    BasicDataSource dataSource_JNDI = null;
    org.apache.commons.dbcp.BasicDataSource dataSource_JDBC = null;
    WebApplicationContext appContext = WebApplicationContextUtils
            .getWebApplicationContext(event.getServletContext());
    if (appContext != null) {
        Object sqlMapClientObj = appContext.getBean("tacSqlMapClient");
        if (sqlMapClientObj instanceof SqlMapClient) {
            sqlMapClient = (SqlMapClient) sqlMapClientObj;
            if (DataAccessor.getSession() == null) {
                //System.out.println("setSqlMapper(" + sqlMapClient +")");
                DataAccessor.setSqlMapper(sqlMapClient);
            }
        }
        Object dataSourceObj = appContext.getBean("dataSource");
        if (dataSourceObj instanceof BasicDataSource) {
            dataSource_JNDI = (BasicDataSource) dataSourceObj;
            if (DataAccessor.JdbcUrl == null) {
                //System.out.println("setJdbcUrl(" +dataSource_JNDI.getUrl() + ")");
                DataAccessor.setJdbcUrl(dataSource_JNDI.getUrl());
            }
        } else if (dataSourceObj instanceof org.apache.commons.dbcp.BasicDataSource) {
            dataSource_JDBC = (org.apache.commons.dbcp.BasicDataSource) dataSourceObj;
            if (DataAccessor.JdbcUrl == null) {
                //System.out.println("setJdbcUrl(" +dataSource_JDBC.getUrl() + ")");
                DataAccessor.setJdbcUrl(dataSource_JDBC.getUrl());
            }
        }
    }
    Chart.setLicenseCode("SXZVFNRN9MZ9L8LGA0E2B1BB");
}

From source file:com.predic8.membrane.servlet.MembraneServletContextListener.java

public void contextInitialized(ServletContextEvent sce) {
    try {// w w w . j ava  2s  .c o m
        log.info(Constants.PRODUCT_NAME + " starting...");

        log.debug("loading proxies configuration from: " + getProxiesXmlLocation(sce));

        appCtx = new BaseLocationXmlWebApplicationContext();
        Router router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, sce.getServletContext(),
                getProxiesXmlLocation(sce));
        if (router != null)
            throw new RuntimeException(
                    "A <router> with a <servletTransport> cannot be used with MembraneServletContextListener. Use MembraneServlet instead.");

        log.info(Constants.PRODUCT_NAME + " running.");
    } catch (Exception ex) {
        log.error("Router not started!", ex);
        throw new RuntimeException("Router not started!", ex);
    }
}

From source file:com.concursive.connect.web.listeners.ContextListener.java

/**
 * Code initialization for global objects like ConnectionPools
 *
 * @param event Description of the Parameter
 *//*from ww  w . j  av a  2 s  .co  m*/
public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    LOG.info("Initializing");
    LOG.info("Version: " + ApplicationVersion.VERSION);
    // Start the connection pool
    try {
        ConnectionPool cp = new ConnectionPool();
        cp.setDebug(true);
        cp.setTestConnections(false);
        cp.setAllowShrinking(true);
        cp.setMaxConnections(10);
        cp.setMaxIdleTime(60000);
        cp.setMaxDeadTime(300000);
        context.setAttribute(Constants.CONNECTION_POOL, cp);
        LOG.info("Connection pool added");
    } catch (Exception e) {
        LOG.error("Connection pool error", e);
    }

    // Start the cache manager (caches are configured later)
    CacheManager.create();
    LOG.info("CacheManager created");
    // Start the work flow manager
    try {
        // Workflow manager
        WorkflowManager wfManager = new WorkflowManager();
        context.setAttribute(Constants.WORKFLOW_MANAGER, wfManager);
        // Hook manager
        ObjectHookManager hookManager = new ObjectHookManager();
        hookManager.setWorkflowManager(wfManager);
        context.setAttribute(Constants.OBJECT_HOOK_MANAGER, hookManager);
        LOG.info("Workflow manager added");
    } catch (Exception e) {
        LOG.error("Workflow manager error", e);
    }

    // Setup a web tracker
    Tracker tracker = new Tracker();
    context.setAttribute(Constants.USER_SESSION_TRACKER, tracker);

    // Setup Webdav Manager
    WebdavManager webdavManager = new WebdavManager();
    context.setAttribute(Constants.WEBDAV_MANAGER, webdavManager);
    LOG.info("Webdav manager added");

    // Setup scheduler
    try {
        SchedulerFactory schedulerFactory = new org.quartz.impl.StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        context.setAttribute(Constants.SCHEDULER, scheduler);
        LOG.info("Scheduler added");
    } catch (Exception e) {
        LOG.error("Scheduler error", e);
    }

    // Portlet container
    try {
        // Add the Container
        PortletContainerFactory portletFactory = PortletContainerFactory.getInstance();
        ContainerServicesImpl services = new ContainerServicesImpl();
        PortletContainer portletContainer = portletFactory.createContainer("PortletContainer", services,
                services);
        portletContainer.init(context);
        context.setAttribute(Constants.PORTLET_CONTAINER, portletContainer);
        LOG.info("PortletContainer added");
    } catch (Exception e) {
        LOG.error("PortletContainer error", e);
    }

    // Finished
    LOG.info("Initialized");
}

From source file:org.wso2.bps.humantask.sample.listener.HTAppServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    Properties properties = new Properties();
    // load configuration properties at context initialization
    try {//from   w  w  w  .  j a  va 2  s  . com
        properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
        //initialize the required parameters
        ServletContext sc = servletContextEvent.getServletContext();
        sc.setInitParameter(HumanTaskSampleConstants.BACKEND_SERVER_URL,
                properties.get(HumanTaskSampleConstants.BACKEND_SERVER_URL).toString());
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH));
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD));
        sc.setInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE,
                properties.getProperty(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE));

    } catch (IOException e) {
        String errMsg = "Couldn't load properties from config file";
        log.error(errMsg, e);
    }
}