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.jsquant.listener.JsquantContextListener.java

public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    context.removeAttribute(ATTR_FILE_CACHE);

    HttpClient httpClient = getHttpClient(context);
    if (httpClient != null) {
        httpClient.getConnectionManager().shutdown();
    }/* w ww. j  av a 2s  .  c om*/
    context.removeAttribute(ATTR_HTTP_CLIENT);
}

From source file:mitm.djigzo.web.utils.SetDefaultSystemPropertiesServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    String propertiesParam = contextEvent.getServletContext().getInitParameter("djigzo.system.properties");

    if (propertiesParam != null) {
        Properties properties = new Properties();

        try {/*  w w  w .jav  a 2 s . c om*/
            properties.load(IOUtils.toInputStream(propertiesParam, "UTF-8"));

            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                if (System.getProperty((String) entry.getKey()) == null) {
                    System.setProperty((String) entry.getKey(), (String) entry.getValue());
                }
            }
        } catch (IOException e) {
            logger.error("Error loading properties.", e);
        }
    } else {
        logger.warn("property djigzo.systemproperties.default is missing.");
    }
}

From source file:edu.mayo.cts2.framework.core.config.ConfigInitializerFactory.java

public void contextInitialized(ServletContextEvent sce) {
    try {/*from   ww  w .  j  a  v  a  2 s  .  co m*/
        ConfigInitializer.initialize(StringUtils.removeStart(sce.getServletContext().getContextPath(), "/"));
    } catch (Cts2ConfigAlreadyInitializedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.pentaho.platform.web.http.context.HsqldbStartupListener.java

public void contextInitialized(ServletContextEvent sce) {
    ServletContext ctx = sce.getServletContext();

    logger.debug("Starting HSQLDB Embedded Listener"); //$NON-NLS-1$
    HsqlDatabaseStarterBean starterBean = new HsqlDatabaseStarterBean();
    String port = ctx.getInitParameter("hsqldb-port"); //$NON-NLS-1$
    int portNum = -1;
    if (port != null) {
        logger.debug(String.format("Port override specified: %s", port)); //$NON-NLS-1$
        try {//from   w w  w.  j  av  a2 s.c o  m
            portNum = Integer.parseInt(port);
            starterBean.setPort(portNum);
        } catch (NumberFormatException ex) {
            logger.error(Messages.getErrorString("HsqldbStartupListener.ERROR_0004_INVALID_PORT", "9001")); //$NON-NLS-1$
            port = null; // force check default port
        }
    }

    starterBean.setDatabases(getDatabases(ctx));

    String sampleDataAllowPortFailover = ctx.getInitParameter("hsqldb-allow-port-failover"); //$NON-NLS-1$
    if ((sampleDataAllowPortFailover != null) && (sampleDataAllowPortFailover.equalsIgnoreCase("true"))) { //$NON-NLS-1$
        logger.debug(String.format("Allow Port Failover specified")); //$NON-NLS-1$
        starterBean.setAllowPortFailover(true);
    }

    if (starterBean.start()) {
        ctx.setAttribute("hsqldb-starter-bean", starterBean); //$NON-NLS-1$
    }

}

From source file:org.topazproject.ambra.auth.web.AuthServletContextListener.java

public void contextInitialized(final ServletContextEvent event) {
    final ServletContext context = event.getServletContext();

    Configuration conf = ConfigurationStore.getInstance().getConfiguration();
    String url = conf.getString(PREF + "url");

    final Properties dbProperties = new Properties();
    dbProperties.setProperty("url", url);
    dbProperties.setProperty("user", conf.getString(PREF + "user"));
    dbProperties.setProperty("password", conf.getString(PREF + "password"));

    try {//from  w  w w . j  a va  2  s  .  c o m
        dbContext = DatabaseContext.createDatabaseContext(conf.getString(PREF + "driver"), dbProperties,
                conf.getInt(PREF + "initialSize"), conf.getInt(PREF + "maxActive"),
                conf.getString(PREF + "connectionValidationQuery"));
    } catch (final DatabaseException ex) {
        throw new Error("Failed to initialize the database context to '" + url + "'", ex);
    }

    final UserService userService = new UserService(dbContext, conf.getString(PREF + "usernameToGuidSql"),
            conf.getString(PREF + "guidToUsernameSql"));
    context.setAttribute(AuthConstants.USER_SERVICE, userService);
}

From source file:org.solmix.wmix.web.context.WmixContextLoaderListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    servletContext = event.getServletContext();
    String root = servletContext.getRealPath("/");
    if (LOG.isInfoEnabled()) {
        LOG.info("Initial Web context,used path:" + root + " As [solmix.base]");
    }/*from www.j ava  2 s.  c o  m*/
    System.setProperty("solmix.base", root);
    WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    if (context == null) {
        String msg = "Can't found spring WebApplicationContext";
        servletContext.log(msg);
        throw new IllegalStateException(msg);
    }
    SpringContainerFactory factory = new SpringContainerFactory(context);
    Container c = factory.createContainer();
    ContainerFactory.setThreadDefaultContainer(c);
    servletContext.setAttribute(CONTAINER_KEY, c);
}

From source file:com.openmeap.web.servlet.Log4JConfiguratorListener.java

@Override
public void contextInitialized(ServletContextEvent arg0) {
    BasicConfigurator.configure();//from   ww  w. j ava 2s .co m
    ServletContext servletContext = arg0.getServletContext();
    String xmlLoc = servletContext.getInitParameter("openmeap-log4j-xml");
    if (xmlLoc == null) {
        return;
    }
    try {
        Resource res = new ClassPathResource(xmlLoc);
        DOMConfigurator.configure(XmlUtils.getDocument(res.getInputStream()).getDocumentElement());
    } catch (Exception ioe) {
        servletContext.log("The configuration failed.", ioe);
    }
}

From source file:org.callistasoftware.netcare.web.listener.ApplicationListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);

    final ServletContext sc = event.getServletContext();

    if (WebUtil.isProfileActive(sc, "ios-testdata")) {
        WebUtil.setupIosTestData(sc);/*from   www  .j a v  a 2 s  .  c om*/
    } else if (WebUtil.isProfileActive(sc, "db-embedded")
            || (WebUtil.isProfileActive(sc, "test") && WebUtil.isProfileActive(sc, "db-psql"))) {
        log.debug("Setting up application test data...");
        WebUtil.setupTestData(sc);
        log.debug("Test data setup completed.");
    }

    if (WebUtil.isProfileActive(sc, "prod")) {
        WebUtil.setProdData(sc);
    }

    log.info("======== NETCARE STARTED ========");
}

From source file:edu.cornell.mannlib.vitro.webapp.migration.rel17.RemoveObsoletePermissions.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext ctx = sce.getServletContext();
    StartupStatus ss = StartupStatus.getBean(ctx);

    try {// www .j ava 2  s.c om
        Updater updater = new Updater(ctx);
        updater.update();
        if (updater.statementsRemoved() == 0L) {
            ss.info(this, "User accounts model contained no statements " + "referencing obsolete permissions.");
        } else {
            ss.info(this,
                    String.format(
                            "Adjusted the user accounts model. " + "Removed %s statements referencing "
                                    + "%s obsolete permissions.",
                            updater.statementsRemoved(), OBSOLETE_PERMISSIONS.length));
        }
    } catch (Exception e) {
        ss.fatal(this, "Failed to update URIs of PermissionSets " + "on User Accounts", e);
    }
}

From source file:com.scf.web.context.BeforeSpringContextListener.java

/**
 *
 * @param sce//from w  w  w. ja  va 2s  .c  o m
 */
@Override
public void contextInitialized(ServletContextEvent sce) {
    sce.getServletContext().log("BeforeSpringContextListener  contextInitialized  begin ....");
    //?
    EventBusRepository.regGlobalAsyncBus();
    EventBusRepository.regGlobalSyncBus();

    //?web
    ContextHolder.initIdentiyContext(new DefaultWebContext());
    //init root Resource
    initRootResource(sce);

    //init resource
    initResource(sce);

    //init module config
    ModuleConfigHandler.loadModuleConfigs(getOverrideModuleConfigProperties());
    //init currentSystem
    setCurrentSystemDomain();

    //init currentSystemEnv
    setCurrentSystemEnv();

    sce.getServletContext().log("BeforeSpringContextListener contextInitialized end ....");
}