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:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListener.java

/**
 * {@inheritDoc}/* ww  w .j a  va  2  s. c o  m*/
 */
@SuppressWarnings("unchecked")
public void contextInitialized(ServletContextEvent event) {
    log.debug("Initializing context...");

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);

    if (config == null) {
        config = new HashMap<String, Object>();
    }

    if (context.getInitParameter(Constants.CSS_THEME) != null) {
        config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME));
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    /*String[] beans = ctx.getBeanDefinitionNames();
    for (String bean : beans) {
    log.debug(bean);
    }*/

    PasswordEncoder passwordEncoder = null;
    try {
        ProviderManager provider = (ProviderManager) ctx
                .getBean("org.springframework.security.authentication.ProviderManager#0");
        for (Object o : provider.getProviders()) {
            AuthenticationProvider p = (AuthenticationProvider) o;
            if (p instanceof RememberMeAuthenticationProvider) {
                config.put("rememberMeEnabled", Boolean.TRUE);
            } else if (ctx.getBean("passwordEncoder") != null) {
                passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
            }
        }
    } catch (NoSuchBeanDefinitionException n) {
        log.debug("authenticationManager bean not found, assuming test and ignoring...");
        // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
        log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
        if (passwordEncoder != null) {
            log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
        }
        log.debug("Populating drop-downs...");
    }

    setupContext(context);
}

From source file:org.openflamingo.engine.util.VersionConfigurer.java

/**
 * Notification that the servlet context is about to be shut down.
 * All servlets and filters have been destroy()ed before any
 * ServletContextListeners are notified of context
 * destruction./*w w w. java  2s  .co m*/
 *
 * @param servletContextEvent {@link javax.servlet.ServletContextEvent}
 */
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    Log4jWebConfigurer.shutdownLogging(servletContextEvent.getServletContext());
}

From source file:com.gisgraphy.webapp.listener.StartupListener.java

@SuppressWarnings({ "unchecked" })
public void contextInitialized(ServletContextEvent event) {
    log.debug("initializing context...");

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);

    if (config == null) {
        config = new HashMap<String, Object>();
    }//from www. j  a va  2s .c o  m

    if (context.getInitParameter(Constants.CSS_THEME) != null) {
        config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME));
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    boolean encryptPassword = true;

    try {
        ProviderManager provider = (ProviderManager) ctx
                .getBean(ctx.getBeanNamesForType(ProviderManager.class)[0]);
        for (Object o : provider.getProviders()) {
            AuthenticationProvider p = (AuthenticationProvider) o;
            if (p instanceof RememberMeAuthenticationProvider) {
                config.put("rememberMeEnabled", Boolean.TRUE);
            }
            config.put(Constants.ENCRYPT_PASSWORD, Boolean.TRUE);
            config.put(Constants.ENC_ALGORITHM, "SHA");
        }
    } catch (NoSuchBeanDefinitionException n) {
        log.debug("authenticationManager bean not found, assuming test and ignoring...");
        // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
        log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
        log.debug("Encrypt Passwords? " + encryptPassword);
        if (encryptPassword) {
            log.debug("Encryption Algorithm: " + config.get(Constants.ENC_ALGORITHM));
        }
        log.debug("Populating drop-downs...");
    }

    setupContext(context);
}

From source file:org.nuxeo.runtime.deployment.NuxeoStarter.java

protected void start(ServletContextEvent event) throws IOException, BundleException {
    ServletContext servletContext = event.getServletContext();
    findBundles(servletContext);/*w w w .  j av a  2s  .c  o  m*/
    findEnv(servletContext);

    ClassLoader cl = getClass().getClassLoader();
    File home = new File((String) env.get(NUXEO_RUNTIME_HOME));
    FrameworkLoader.initialize(cl, home, bundleFiles, env);
    FrameworkLoader.start();
}

From source file:edu.du.penrose.systems.util.MyServletContextListener.java

public void contextInitialized(ServletContextEvent context) {

    MyServletContextListener.myServletContext = context.getServletContext();

    String realPath = myServletContext.getRealPath("/");
    if (!realPath.endsWith("" + File.separatorChar)) {
        realPath = realPath + File.separatorChar;
    }/*ww w  .j  av  a 2  s  .com*/
    System.setProperty("webapp.root", realPath);
}

From source file:org.apache.roller.planet.ui.core.PlanetContext.java

/**
 * Responds to context initialization event by processing context
 * paramters for easy access by the rest of the application.
 *//*from  www . j  a v  a 2s . c o  m*/
public void contextInitialized(ServletContextEvent sce) {

    log.info("Roller Planet Initializing ... ");

    // keep a reverence to ServletContext object
    this.context = sce.getServletContext();

    // call Spring's context ContextLoaderListener to initialize
    // all the context files specified in web.xml. This is necessary
    // because listeners don't initialize in the order specified in
    // 2.3 containers
    super.contextInitialized(sce);

    // Now prepare the core services of the app so we can bootstrap
    try {
        PlanetStartup.prepare();
    } catch (StartupException ex) {
        log.fatal("Roller Planet startup failed during app preparation", ex);
        return;
    }

    // if preparation failed or is incomplete then we are done,
    // otherwise try to bootstrap the business tier
    if (!PlanetStartup.isPrepared()) {
        log.info("Roller Planet startup requires interaction from user to continue");
    } else {
        try {
            // trigger bootstrapping process
            PlanetFactory.bootstrap();

            // trigger initialization process
            PlanetFactory.getPlanet().initialize();

        } catch (BootstrapException ex) {
            log.fatal("Roller PlanetFactory bootstrap failed", ex);
        } catch (PlanetException ex) {
            log.fatal("Roller PlanetFactory initialization failed", ex);
        }
    }

    log.info("Roller Planet Initialization Complete");
}

From source file:org.nuxeo.opensocial.servlet.GuiceContextListener.java

public void contextInitialized(ServletContextEvent event) {
    log.info("GuiceContextListener contextInitialized");
    context = event.getServletContext();

    modules = getModuleList(context.getInitParameter(MODULES_ATTRIBUTE));
    log.info("GuiceContextListener getModuleList");
    try {//from w  w  w.  jav a 2  s .  c o m
        runInjection();
    } catch (Exception e) {
        throw new RuntimeException("Cannot find opensocial service for " + "initialization!", e);
    }
}

From source file:com.edmunds.etm.client.impl.ClientServletContextListener.java

/**
 * Notification that the web application initialization process is starting. All ServletContextListeners are
 * notified of context initialization before any filter or servlet in the web application is initialized.
 *
 * @param servletContextEvent the servlet context event.
 *///from  ww  w  .ja  va2 s .  c o m
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    logger.debug("Starting ETM listener.");
    ServletContext ctx = servletContextEvent.getServletContext();

    final String ipAddress = getIpAddress();
    final String contextPath = ctx.getContextPath();

    ClientConfigDto clientConfig = readClientConfiguration();
    MavenModuleDto mavenModule = clientConfig.getMavenModule();

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("ETM application: %s", clientConfig.getMavenModule()));
    }

    // validate IP address and maven module
    if (StringUtils.isBlank(ipAddress)) {
        logger.error("Unable to register with ETM: IP address is blank");
        return;
    } else if (mavenModule == null) {
        logger.error("Unable to register with ETM: Maven artifact information is missing");
        return;
    }

    final ApplicationContext appCtx = SpringContextLoader.loadClassPathSpringContext(CLIENT_CONTEXT_PATH,
            getMavenProperties(mavenModule));

    final ClientRegistrationHelper helper = (ClientRegistrationHelper) appCtx
            .getBean("clientRegistrationHelper");
    clientManager = (ClientManager) appCtx.getBean("clientManager");

    // register with the ETM controller
    helper.register(ctx.getServerInfo(), ipAddress, contextPath, clientConfig);
}

From source file:org.jbr.commons.container.http.WebAppHttpServer.java

@Override
protected void configureApplication(final Server server) throws Exception {
    final ServletContextHandler handler = new ServletContextHandler();
    handler.addEventListener(new ServletContextListener() {
        public void contextDestroyed(final ServletContextEvent event) {
            // NO-OP
        }//  w ww  . j a  v a  2 s  .c  om

        public void contextInitialized(final ServletContextEvent event) {
            try {
                webApplicationInitializer.onStartup(event.getServletContext());
            } catch (final Exception e) {
                log.error(e.getMessage(), e);
                throw new RuntimeException(e);
            }
        }
    });
    server.setHandler(handler);
}

From source file:eu.openanalytics.rsb.config.BootstrapConfigurationServletContextListener.java

@Override
public void contextInitialized(final ServletContextEvent sce) {
    copyUiFragments(sce.getServletContext());

    if (isConfigurationPresent(sce.getServletContext())) {
        return;/* w ww .ja v  a 2 s.c om*/
    }

    final File configurationDirectory = getWritableConfigurationDirectory(sce);

    if (configurationDirectory != null) {
        try {
            createDefaultConfigurationFile(
                    new File(configurationDirectory, Configuration.DEFAULT_JSON_CONFIGURATION_FILE),
                    getWebInfDirectory(sce));
        } catch (final URISyntaxException urie) {
            LOGGER.error("Failed to create a default configuration file", urie);
        }
    } else {
        LOGGER.error("Configuration file " + Configuration.DEFAULT_JSON_CONFIGURATION_FILE
                + " not found and no way to create a default configuration in "
                + ConfigurationFactory.RSB_CONFIGURATION_DIRECTORY
                + " or on the classpath: RSB will not start properly!");
    }
}