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.lternet.pasta.portal.ConfigurationListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();

    // Create an absolute path for accessing configuration properties
    String cwd = servletContext.getRealPath(".");

    // Initialize log4j
    String log4jPropertiesPath = cwd + "/WEB-INF/conf/log4j.properties";
    PropertyConfigurator.configureAndWatch(log4jPropertiesPath);

    // Initialize commons configuration
    String appConfigPath = cwd + "/WEB-INF/conf/dataportal.properties";
    try {/*from  ww w  .j  a v  a  2s. com*/
        config = new PropertiesConfiguration(appConfigPath);
        config.setProperty("system.cwd", cwd);
        config.save();
    } catch (ConfigurationException e) {
        logger.error(e);
        e.printStackTrace();
    }

}

From source file:org.apereo.portal.jmx.JavaManagementServerListener.java

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 *///from w  ww .j  a  va  2  s.  com
public void contextInitialized(ServletContextEvent event) {
    final ServletContext servletContext = event.getServletContext();

    //Create the bean
    this.javaManagementServerBean = new JavaManagementServerBean();

    //Get the failOnException option
    final String failOnExceptionStr = servletContext.getInitParameter(FAIL_ON_EXCEPTION);
    boolean failOnException = Boolean.parseBoolean(failOnExceptionStr);
    this.javaManagementServerBean.setFailOnException(failOnException);

    final String host = servletContext.getInitParameter(JMX_RMI_HOST);
    this.javaManagementServerBean.setHost(host);

    //Get the base rmi port from the init parameters
    final String portOneStr = servletContext.getInitParameter(JMX_RMI_PORT_1);
    try {
        final int portOne = Integer.parseInt(portOneStr);
        this.javaManagementServerBean.setPortOne(portOne);
    } catch (NumberFormatException nfe) {
        getLogger().warn("init-parameter '" + JMX_RMI_PORT_1 + "' is required and must contain a number. '"
                + portOneStr + "' is not a valid number.", nfe);
    }

    //Get the second rmi port from the init parameters
    final String portTwoStr = servletContext.getInitParameter(JMX_RMI_PORT_2);
    try {
        final int portTwo = Integer.parseInt(portTwoStr);
        this.javaManagementServerBean.setPortTwo(portTwo);
    } catch (NumberFormatException nfe) {
        getLogger().debug("Failed to convert init-parameter '" + JMX_RMI_PORT_2 + "' with value '" + portTwoStr
                + "' to a number, defaulting portTwo to portOne + 1", nfe);
    }

    this.javaManagementServerBean.startServer();
}

From source file:org.jclouds.demo.tweetstore.config.GuiceServletConfig.java

private Properties loadJCloudsProperties(ServletContextEvent servletContextEvent) {
    InputStream input = servletContextEvent.getServletContext()
            .getResourceAsStream("/WEB-INF/jclouds.properties");
    Properties props = new Properties();
    try {//from   w w  w . j av  a2 s  .c  o m
        props.load(input);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(input);
    }
    return props;
}

From source file:org.sonar.server.platform.PlatformServletContextListener.java

public void contextInitialized(ServletContextEvent event) {
    try {//from  w w w  . jav  a 2s .  com
        configureLogback(event);
        Platform.getInstance().init(event.getServletContext());
        Platform.getInstance().doStart();
    } catch (Throwable t) {
        // Tomcat 7 "limitations":
        // - server does not stop if webapp fails at startup
        // - the second listener for jruby on rails is started even if this listener fails. It generates
        // unexpected errors
        LoggerFactory.getLogger(getClass()).error("Fail to start server", t);
        stopQuietly();
        System.exit(1);
    }
}

From source file:org.tizzit.core.classloading.ExternalLibClassLoaderInitializeListener.java

public void contextInitialized(ServletContextEvent sce) {
    if (log.isDebugEnabled())
        log.debug("contextInitialized() -> begin");
    ExternalLibClassLoaderManager.createExternalLibClassLoader(sce.getServletContext());
    if (log.isDebugEnabled())
        log.debug("contextInitialized() -> end");
}

From source file:org.jresearch.gossip.listeners.ContextListener.java

public void contextInitialized(ServletContextEvent evt) {
    boolean useDatasource = Boolean.valueOf(evt.getServletContext().getInitParameter("useDatasource"))
            .booleanValue();//from   w w w . j  ava2  s . co m
    String datasourceName = evt.getServletContext().getInitParameter("datasourceName");

    InitialContext ic;
    try {
        ic = new InitialContext();
        if (useDatasource) {
            if (datasourceName == null)
                throw new RuntimeException(
                        "Using datasource is enabled but datasourceName parameter is not specified.");

            DataSource dataSource = (DataSource) PortableRemoteObject.narrow(ic.lookup(datasourceName),
                    javax.sql.DataSource.class);
            ic.rebind("jgossip_db", dataSource);

        } else {
            Properties dbconf = new Properties();
            dbconf.load(evt.getServletContext()
                    .getResourceAsStream("/WEB-INF/classes/org/jresearch/gossip/resources/db.properties"));
            // Construct BasicDataSource reference
            Reference ref = new Reference("javax.sql.DataSource",
                    "org.apache.commons.dbcp.BasicDataSourceFactory", null);
            ref.add(new StringRefAddr("driverClassName", dbconf.getProperty("driverClassName")));
            ref.add(new StringRefAddr("url", dbconf.getProperty("url")));
            ref.add(new StringRefAddr("password", dbconf.getProperty("password")));
            ref.add(new StringRefAddr("username", dbconf.getProperty("username")));
            ref.add(new StringRefAddr("maxActive", dbconf.getProperty("maxActive")));
            ref.add(new StringRefAddr("maxWait", dbconf.getProperty("maxWait")));
            ref.add(new StringRefAddr("initialSize", dbconf.getProperty("initialSize")));
            ref.add(new StringRefAddr("defaultAutoCommit", dbconf.getProperty("defaultAutoCommit")));
            ref.add(new StringRefAddr("defaultReadOnly", dbconf.getProperty("defaultReadOnly")));
            ref.add(new StringRefAddr("poolPreparedStatements", dbconf.getProperty("poolPreparedStatements")));
            ref.add(new StringRefAddr("maxOpenPreparedStatements",
                    dbconf.getProperty("maxOpenPreparedStatements")));

            ic.rebind("jgossip_db", ref);
        }

    } catch (NamingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:it.scoppelletti.programmerpower.wui.WebApplicationRegistry.java

/**
 * Inizializzazione di un’applicazione Web.
 *
 * <P>Questa implementazione del metodo {@code contextInitialized} imposta
 * l&rsquo;istante di avvio dell&rsquo;applicazione Web nel registro delle
 * applicazioni (se l&rsquo;applicazione non esiste nel registro la 
 * inserisce).</P>/*  w w  w  .  j  a  va  2s.  c o  m*/
 * 
 * @param event Evento.
 */
public void contextInitialized(ServletContextEvent event) {
    registerApplication(event.getServletContext().getContextPath());
}

From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java

/**
 * On startup, read the revision info from the resource file in the
 * classpath.// ww  w  . java 2s  . c  o  m
 * 
 * If we can't find the file, or can't parse it, store an empty bean.
 * 
 * Don't allow any Exceptions to percolate up past this point.
 */
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    RevisionInfoBean bean;
    try {
        List<String> lines = readRevisionInfo(context);
        bean = parseRevisionInformation(lines);
    } catch (Exception e) {
        StartupStatus.getBean(context).warning(this, "Failed to load the revision info", e);
        bean = DUMMY_BEAN;
    }

    RevisionInfoBean.setBean(sce.getServletContext(), bean);
}

From source file:org.infoglue.calendar.util.CalendarContextListener.java

/**
 * This method is called when the servlet context is 
 * initialized(when the Web Application is deployed). 
 * You can initialize servlet context related data here.
 *//*from w  w w  .ja va 2s.c om*/

public void contextInitialized(ServletContextEvent event) {
    System.out.println("contextInitialized for calendar...");
    try {
        String contextRootPath = event.getServletContext().getRealPath("/");
        if (!contextRootPath.endsWith("/") && !contextRootPath.endsWith("\\"))
            contextRootPath = contextRootPath + "/";

        PropertyHelper.setProperty("contextRootPath", contextRootPath);

        InfoglueInstanceMonitor.getInstance();
        //CmsPropertyHandler.setApplicationName("application");

        //InfoGlueAuthenticationFilter.initializeProperties();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.kimios.core.CoreListener.java

public void contextDestroyed(ServletContextEvent event) {
    log.info("kimios Web Client Closing ...");
    SpringWebContextLauncher.shutdownApp(event.getServletContext(), this.contextLoader);
    log.info("kimios Web Client Closed");
}