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:com.bekk.boss.pluto.embedded.util.PortalStartupListener.java

public void contextInitialized(ServletContextEvent sce) {
    Context.SContext servletContext = (Context.SContext) sce.getServletContext();
    ContextHandler contextHandler = servletContext.getContextHandler();
    Map initParams = contextHandler.getInitParams();
    String configLocations = (String) initParams.get(ContextLoader.CONFIG_LOCATION_PARAM);
    if (configLocations != null) {
        configLocations = configLocations + " " + PLUTO_SERVICE_CONFIG_LOCATION;
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
    } else {/*from  w w w  . j av a 2s  .c  o m*/
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, PLUTO_SERVICE_CONFIG_LOCATION);
    }
    // Traverse listeners to see if there's a configured
    // ContextLoaderListener
    EventListener[] listeners = contextHandler.getEventListeners();
    if (listeners != null) {
        List newListenerList = new ArrayList();
        for (int i = 0; i < listeners.length; i++) {
            EventListener listener = listeners[i];
            if (!(listener instanceof ContextLoaderListener)) {
                newListenerList.add(listener);
            }
        }
        contextHandler.setEventListeners(
                (EventListener[]) newListenerList.toArray(new EventListener[newListenerList.size()]));
    }
    ServletContext wrapped = new WrappedServletContext(sce.getServletContext());
    realStartupListener.contextInitialized(new ServletContextEvent(wrapped));
}

From source file:org.accesointeligente.server.RobotContext.java

@Override
public void contextInitialized(ServletContextEvent event) {
    try {/* www . java  2 s. c om*/
        context = new FileSystemXmlApplicationContext(
                event.getServletContext().getResource("/WEB-INF/robots.xml").toString());
        logger.info("Context initialized");
    } catch (Exception ex) {
        logger.error("Failed to initialize context", ex);
    }
}

From source file:org.encuestame.init.EnMeContext.java

/**
 * On start application.//from   ww  w.  jav a  2 s  .  c o m
 */
@Override
public void contextInitialized(final ServletContextEvent sce) {
    EnMeContext.servletContext = sce.getServletContext();
    super.contextInitialized(sce);
    boolean existHomeDirectory = DirectorySetupOperations.isHomeDirectoryValid();
    if (!existHomeDirectory) {
        log.fatal("**********************************************");
        log.fatal("*           ENCUESTAME HOME IS MISSING");
        log.fatal("*           Troubles ?? Visit the wiki a get your answer.");
        log.fatal("*  http://www.encuestame.org/wiki/display/DOC/Troubleshooting+Guides");
        log.fatal("**********************************************");
        throw new IllegalStateException("home not valid, please set a home property in the configuration file");
    } else {
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        //servletContext.setInitParameter("spring.profiles.active", "live");
        final StartupProcess startup = (StartupProcess) ctx.getBean("applicationStartup");
        try {
            startup.startProcess();
            log.info("**********************************************");
            log.info("*     ENCUESTAME IS RUNNING SUCCESSFULLY      *");
            log.info("*        http://www.encuestame.org           *");
            log.info("**********************************************");
        } catch (Exception e) {
            log.fatal("EnMe: Error on start encuestame context: " + e.getMessage());
            this.closeWebApplicationContext(servletContext);
            throw new IllegalStateException("EnMe: Error on stat encuestame context : " + e.getMessage());
        }
    }
}

From source file:com.geodan.ngr.serviceintegration.listener.ApplicationListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    log.debug("context initializing..");
    ServletContext servletContext = servletContextEvent.getServletContext();
    String ctxName = servletContext.getServletContextName();
    String realP = servletContext.getRealPath(ctxName);
    String fixedRealPath = realP.substring(0, realP.lastIndexOf(ctxName));
    log.debug("realpath: " + fixedRealPath);
    RealPath.init(fixedRealPath);/*from   w  w w. j  a  v a  2  s.c o  m*/
    log.debug("context initialized");
}

From source file:com.ning.metrics.action.binder.modules.SetupServer.java

@Override
public void contextInitialized(final ServletContextEvent event) {
    final String moduleClassName = event.getServletContext().getInitParameter("guiceModuleClassName");
    if (StringUtils.isEmpty(moduleClassName)) {
        throw new IllegalStateException("Missing parameter for the base Guice module!");
    }/* www .j  a  va  2 s .  co  m*/

    try {
        final Class<?> moduleClass = Class.forName(moduleClassName);
        if (!Module.class.isAssignableFrom(moduleClass)) {
            throw new IllegalStateException(
                    String.format("%s exists but is not a Guice Module!", moduleClassName));
        }

        guiceModule = (Module) moduleClass.newInstance();
        log.info("Instantiated " + moduleClassName + " as the main guice module.");
    } catch (ClassNotFoundException cnfe) {
        throw new IllegalStateException(cnfe);
    } catch (InstantiationException ie) {
        throw new IllegalStateException(ie);
    } catch (IllegalAccessException iae) {
        throw new IllegalStateException(iae);
    }

    super.contextInitialized(event);
}

From source file:org.accada.epcis.repository.RepositoryContextListener.java

/**
 * {@inheritDoc}//from w  w w . j a  va2s  .co  m
 * 
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();

    /*
     * Note: logging is initialized automatically by reading
     * logging.properties and log4j.properties from the classpath.
     * logging.properties is used to tell commons-logging to use LOG4J as
     * its underlying logging toolkit; log4j.properties is used to configure
     * LOG4J. To initialize LOG4J manually from LOG4J_CONFIG_LOCATION,
     * un-comment the following code (LOG4J_CONFIG_LOCATION =
     * "log4jConfigLocation") ...
     */
    // "log4jConfigLocation";
    // String path = ctx.getRealPath("/");
    // String log4jCfg = ctx.getInitParameter(LOG4J_CONFIG_LOCATION);
    // // initialize Log4j
    // if (log4jCfg != null) {
    // // if no log4j properties file found, then do not try
    // // to load it (the application runs without logging)
    // PropertyConfigurator.configure(path + log4jCfg);
    // }
    // log = LogFactory.getLog(this.getClass());

    // set a system property to configure CXF to use LOG4J
    System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");

    LOG.info("Starting Accada EPCIS Repository application");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Logging application context init-parameters:");
        Enumeration<?> e = ctx.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            LOG.debug(param + "=" + ctx.getInitParameter(param));
        }
    }
}

From source file:org.apache.tiles.web.startup.TilesListener.java

/**
 * Remove the tiles container from service.
 *
 * @param event The intercepted event./*from   w w w .j  ava2  s.c o m*/
 */
public void contextDestroyed(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();
    try {
        ServletUtil.setContainer(servletContext, null);
    } catch (TilesException e) {
        log.warn("Unable to remove tiles container from service.", e);
    }
}

From source file:org.fosstrak.epcis.repository.RepositoryContextListener.java

/**
 * {@inheritDoc}/*from  www . j  a v  a 2 s  . com*/
 * 
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();

    /*
     * Note: logging is initialized automatically by reading
     * logging.properties and log4j.properties from the classpath.
     * logging.properties is used to tell commons-logging to use LOG4J as
     * its underlying logging toolkit; log4j.properties is used to configure
     * LOG4J. To initialize LOG4J manually from LOG4J_CONFIG_LOCATION,
     * un-comment the following code (LOG4J_CONFIG_LOCATION =
     * "log4jConfigLocation") ...
     */
    // "log4jConfigLocation";
    // String path = ctx.getRealPath("/");
    // String log4jCfg = ctx.getInitParameter(LOG4J_CONFIG_LOCATION);
    // // initialize Log4j
    // if (log4jCfg != null) {
    // // if no log4j properties file found, then do not try
    // // to load it (the application runs without logging)
    // PropertyConfigurator.configure(path + log4jCfg);
    // }
    // log = LogFactory.getLog(this.getClass());

    // set a system property to configure CXF to use LOG4J
    System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");

    LOG.info("Starting Fosstrak EPCIS Repository application");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Logging application context init-parameters:");
        Enumeration<?> e = ctx.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            LOG.debug(param + "=" + ctx.getInitParameter(param));
        }
    }
}

From source file:ar.com.allium.rules.core.listener.AlliumRuleListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    log.debug("start initialize alliumRules");

    ServletContext ctx = servletContextEvent.getServletContext();
    WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(ctx);

    LoadAlliumRules loadAlliumRules = new LoadAlliumRules(springContext);

    loadAlliumRules.loadAlliumRules();//from  w ww .  ja va  2  s .c om

    log.debug("end initialize alliumRules");
}

From source file:cn.im47.cloud.storage.ftp.FtpServerListener.java

public void contextDestroyed(ServletContextEvent sce) {
    logger.debug("Stopping FtpServer");

    FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);

    if (server != null) {
        server.stop();/*  ww w.j av a 2 s.co  m*/
        sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);
        logger.debug("FtpServer stopped");
    } else {
        logger.warn("No running FtpServer found");
    }

}