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.i18n.selection.LocaleSelectionSetup.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    ctx = sce.getServletContext();
    ss = StartupStatus.getBean(ctx);/*from   w  w w.j  a  v a2 s.  c  o m*/
    props = ConfigurationProperties.getBean(sce);

    readProperties();

    if (isForcing() && hasSelectables()) {
        warnAboutOverride();
    }

    if (isForcing()) {
        forceLocale();
    } else if (hasSelectables()) {
        setUpSelections();
    } else {
        reportNoLocales();
    }
}

From source file:org.sakaiproject.login.impl.velocity.LoginRenderEngineContextListener.java

public void contextInitialized(ServletContextEvent event) {
    try {/*from w ww  .j av a2s . c  om*/
        vengine = new VelocityLoginRenderEngine();
        vengine.setContext(event.getServletContext());
        vengine.setServerConfigurationService(ServerConfigurationService.getInstance());
        vengine.setSessionManager(SessionManager.getInstance());
        vengine.init();
        vengine.setLoginService(LoginService.getInstance());
        LoginService.getInstance().addRenderEngine(Login.DEFAULT_LOGIN_CONTEXT, vengine);
    } catch (Exception ex) {
        log.error("Failed to register render engine with the login service, this is probably fatal ", ex);
    }
}

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

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

    try {/*from  w  ww . j av  a  2s . c  o  m*/
        InputStream stream = null;
        try {
            File vitroHomeDir = ApplicationUtils.instance().getHomeDirectory().getPath().toFile();

            File runtimePropertiesFile = locateRuntimePropertiesFile(vitroHomeDir, ss);
            stream = new FileInputStream(runtimePropertiesFile);

            Map<String, String> preempts = createPreemptiveProperties(VHD_CONFIGURATION_PROPERTY, vitroHomeDir);

            ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(stream, preempts,
                    new BuildProperties(ctx).getMap());

            ConfigurationProperties.setBean(ctx, bean);
            ss.info(this, "Loaded " + bean.getPropertyMap().size() + " properties.");
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e) {
                    log.error(e, e);
                }
            }
        }
    } catch (Exception e) {
        ss.fatal(this, e.getMessage(), e);
    }
}

From source file:org.jasig.cas.CasEnvironmentContextListener.java

@Override
public void contextInitialized(final ServletContextEvent event) {
    LOGGER.info("[{}] has loaded the CAS application context", event.getServletContext().getServerInfo());
}

From source file:org.jbpm.bpel.integration.server.IntegrationConfigurator.java

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

    String configResource = servletContext.getInitParameter(JBPM_CONFIG_RESOURCE_PARAM);
    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(configResource);

    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
    try {//w  w w . j ava2s  .  c  o m
        // read the app descriptor from a classpath resource
        DeploymentDescriptor deploymentDescriptor = DeploymentDescriptor.readDeploymentDescriptor(jbpmContext);
        // obtain the integration control for the process definition referenced in the descriptor
        BpelProcessDefinition processDefinition = deploymentDescriptor.findProcessDefinition(jbpmContext);
        JmsIntegrationServiceFactory integrationServiceFactory = JmsIntegrationServiceFactory
                .getConfigurationInstance(jbpmConfiguration);
        IntegrationControl integrationControl = integrationServiceFactory
                .getIntegrationControl(processDefinition);

        // make app descriptor available to message activities
        integrationControl.setDeploymentDescriptor(deploymentDescriptor);
        // start receiving requests
        integrationControl.enableInboundMessageActivities(jbpmContext);

        // make integration control available to jax-rpc handlers
        servletContext.setAttribute(SoapHandler.INTEGRATION_CONTROL_ATTR, integrationControl);

        log.info("message reception enabled for process: " + deploymentDescriptor.getName());
    } catch (RuntimeException e) {
        jbpmContext.setRollbackOnly();
        throw e;
    } catch (NamingException e) {
        jbpmContext.setRollbackOnly();
        throw new BpelException("could not start bpel application", e);
    } catch (JMSException e) {
        jbpmContext.setRollbackOnly();
        throw new BpelException("could not start bpel application", e);
    } finally {
        jbpmContext.close();
    }
}

From source file:com.telefonica.euro_iaas.paasmanager.bootstrap.PropertiesLoaderBootstrap.java

/**
 * {@inheritDoc}/* w w w  .ja  va 2s  .  c  om*/
 */
public void contextInitialized(ServletContextEvent event) {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
    EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory");

    PropertiesProvider propertiesProvider = new PropertiesProviderFactoryImpl().createPropertiesProvider(emf);
    Properties properties = propertiesProvider.load(NAMESPACE);
    try {
        log.info("store namespace: " + NAMESPACE);
        propertiesProvider.store(properties, NAMESPACE);
    } catch (Exception e) {
        throw new PaasManagerServerRuntimeException(e);
    }
}

From source file:org.parancoe.web.ContextListener.java

@Override
public void contextInitialized(ServletContextEvent evt) {
    try {/*from  w w  w. j a  v  a  2  s  .  c  o  m*/
        this.servletContext = evt.getServletContext();

        MemoryAppender instance = MemoryAppender.getInstance();
        instance.clearLogs();

        log.info("loading custom Spring WebApplicationContext");
        loadApplicationContext();
        PluginHelper helper = new PluginHelper(applicationContext);
        helper.initApplicationContextPlugins(evt); // deve essere DOPO loadApplicationContext()
        helper.invokePluginContextInitialized(evt);
        log.info("### Starting up Parancoe in {} mode.", BaseConf.getEnv());
    } catch (Exception e) {
        log.error("Error in base ContextListener.contextInitialized", e);
    }
}

From source file:com.preserve.core.listener.StartupListener.java

@SuppressWarnings("unchecked")
@Override/*from ww  w. j av  a 2s.  c  o m*/
public void contextInitialized(ServletContextEvent sce) {
    ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context = sce.getServletContext());
    //        UserService service=(UserService)ctx.getBean("userService");
    //        User u =new User();
    //        u.setName("test1");
    //        u.setPwd("12312");
    //        service.save(u);

    //        appDao = ctx.getBean(AppDao.class);
    //        tagDao = ctx.getBean(TagDao.class);
    //        appCache = ctx.getBean("appCache", Map.class);
    //        loadAppConfig();
    //        loadTags();
    //        loadSkinMessage();
    //        loadSkins();
    setWebProperty();
}

From source file:com.telefonica.euro_iaas.sdc.bootstrap.PropertiesLoaderBootstrap.java

/**
 * {@inheritDoc}/*from w  w  w. j a  v a  2 s  .  co  m*/
 */

public void contextInitialized(ServletContextEvent event) {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
    EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory");

    PropertiesProvider propertiesProvider = new PropertiesProviderFactoryImpl().createPropertiesProvider(emf);
    Properties properties = propertiesProvider.load(NAMESPACE);
    try {
        log.info("store namespace: " + NAMESPACE);
        propertiesProvider.store(properties, NAMESPACE);
    } catch (Exception e) {
        throw new SdcRuntimeException(e);
    }
}

From source file:org.syncope.buildtools.H2StartStopListener.java

@Override
public void contextInitialized(final ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();

    File workDir = (File) sce.getServletContext().getAttribute("javax.servlet.context.tempdir");
    try {/*from   ww  w  . jav  a2 s. c om*/
        Server h2TestDb = new Server();
        h2TestDb.runTool("-baseDir", workDir.getAbsolutePath(), "-tcp", "-tcpDaemon", "-web", "-webDaemon",
                "-webPort", sce.getServletContext().getInitParameter("testdb.webport"));

        context.setAttribute(H2_TESTDB, h2TestDb);
    } catch (SQLException e) {
        LOG.error("Could not start H2 test db", e);
    }

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
    DataSource datasource = ctx.getBean(DataSource.class);

    Connection conn = null;
    Statement stmt = null;
    try {
        conn = DataSourceUtils.getConnection(datasource);
        stmt = conn.createStatement();
        stmt.executeUpdate("RUNSCRIPT FROM 'classpath:/testdb.sql'");
    } catch (Exception e) {
        LOG.error("While loading data into testdb", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
        DataSourceUtils.releaseConnection(conn, datasource);
    }
}