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.parancoe.plugin.configuration.InitializerContextListener.java

@Override
public void contextInitialized(ServletContextEvent evt) {
    log.info("parancoe-plugin-configuration contextInitialized");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(evt.getServletContext());
    Map<String, ConfigurationCollection> configurationCollections = webApplicationContext
            .getBeansOfType(ConfigurationCollection.class);
    log.info("Found " + configurationCollections.size() + " configuration collections.");
    for (Map.Entry<String, ConfigurationCollection> entry : configurationCollections.entrySet()) {
        log.info("Loading " + entry.getKey() + " configuration collection...");
        ConfigurationCollection value = entry.getValue();
        configurationService.initializeConfiguration(value);
    }/*from   ww w . j  a v a  2 s  . c om*/
}

From source file:com.alefissak.web.AlefissakListener.java

/**
 * Launching Alefissak in a web context/*from  www  .j  a  v a2 s  . c  o m*/
 * {@inheritDoc}
 */
@Override
public void contextInitialized(ServletContextEvent contextEvent) {

    LOG.debug("Starting Alefissak Configuration");

    try {

        ServletContext servletContext = contextEvent.getServletContext();

        if (servletContext != null) {

            planningsConfigUri = servletContext.getInitParameter(PLANNINGS_CONFIG_PARAM_NAME);

            if (null != planningsConfigUri) {

                LOG.debug("Considering the configuration located here : {}", planningsConfigUri);

                Alefissak alefissak;

                if (isURL(planningsConfigUri)) {

                    alefissak = new Alefissak(new AlefissakPlanningParser(new URL(planningsConfigUri)));
                } else {

                    alefissak = new Alefissak(new AlefissakPlanningParser(planningsConfigUri));
                }

                alefissak.run();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.dubbo.config.spring.initializer.DubboContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    if (springContextListener != null) {
        // if spring context listener has already been registered, then do nothing
        ServletContext context = servletContextEvent.getServletContext();
        if (context.getAttribute(SPRING_CONTEXT_ROOT) == null) {
            executed = true;/* ww w . j  a  v a2  s . c  om*/
            springContextListener.contextInitialized(servletContextEvent);
        }
    }
}

From source file:org.sakaiproject.resteasy.ResteasyK2Bootstrap.java

/**
 * {@inheritDoc}/*www  . ja  va  2  s.c  om*/
 *
 * @see org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    Registry restEasyRegistry = (Registry) event.getServletContext().getAttribute(Registry.class.getName());

    defaultDocumentation = (RootRestEasyDocumentation) event.getServletContext()
            .getAttribute(Documentable.class.getName());
    if (defaultDocumentation == null) {
        defaultDocumentation = new RootRestEasyDocumentation();
        event.getServletContext().setAttribute(Documentable.class.getName(), defaultDocumentation);
    }

    // Add listeners to keep the kernel registries aligned with the resteasy
    // registry
    singletonListener = new JaxRsSingletonRegistryListener(restEasyRegistry, defaultDocumentation);
    prototypeListener = new JaxRsPrototypeRegistryListener(restEasyRegistry, defaultDocumentation);

    // Add all of the resources in our JAX-RS providers to the resteasy registry
    KernelManager km = new KernelManager();
    RegistryService registryService = km.getService(RegistryService.class);
    org.sakaiproject.kernel.api.Registry<String, JaxRsSingletonProvider> jaxRsSingletonRegistry = registryService
            .getRegistry(JAXRS_SINGLETON_REGISTRY);
    org.sakaiproject.kernel.api.Registry<String, JaxRsPrototypeProvider> jaxRsPrototypeRegistry = registryService
            .getRegistry(JAXRS_PROTOTYPE_REGISTRY);

    // Sync the JAX-RS implementation's registry with the kernel's registry
    syncRestEasyRegistry(restEasyRegistry, jaxRsSingletonRegistry, jaxRsPrototypeRegistry);

    // Listen for changes to the kernel registry
    jaxRsSingletonRegistry.addListener(singletonListener);
    jaxRsPrototypeRegistry.addListener(prototypeListener);

    LOG.info("Added JAX-RS registry listener for updates to " + jaxRsSingletonRegistry);
}

From source file:com.mqm.frame.infrastructure.startup.ContextInit.java

/**
 * ?DI/*www  . j a  v a 2s. c  om*/
 * 
 * @param context ServletContextEvent
 */
public void contextInitialized(ServletContextEvent context) {

    final ServletContext servletContext = context.getServletContext();

    ContextInit.servletContext = servletContext;

    super.contextInitialized(context);

    // FBRP
    setContext(WebApplicationContextUtils.getRequiredWebApplicationContext(context.getServletContext()));
    ContextUtil.setApplicationContext(ContextInit.context);

    // ?FBRP?
    ContextUtil.setApplicationPath(context.getServletContext().getRealPath("/"));

    /*log.info("?Portlet...");
    log.debug("DriverConfiguration");
    DriverConfiguration driverConfiguration = (DriverConfiguration) ContextInit.context
    .getBean("fbrp_admin_driverConfiguration");
    log.debug("DriverConfiguration");
    servletContext.setAttribute(AttributeKeys.DRIVER_CONFIG, driverConfiguration);
            
    log.debug("?AdminConfiguration");
    AdminConfiguration adminConfiguration = (AdminConfiguration) ContextInit.context
    .getBean("fbrp_admin_adminConfiguration");
            
    if (adminConfiguration != null) {
       log.debug("?AdminConfiguration");
       servletContext.setAttribute(AttributeKeys.DRIVER_ADMIN_CONFIG, adminConfiguration);
    }
            
    log.debug("Portlet");
    PortletContainer container = (PortletContainer) ContextInit.context
    .getBean("fbrp_admin_portletContainer");
            
    log.debug("Portlet");
    servletContext.setAttribute(AttributeKeys.PORTLET_CONTAINER, container);
    log.info("Portlet????");
    */

    //TODO luxiaocheng  ?? 
    /*try {
       // 
       Scheduler scheduler = (Scheduler) ContextInit.getContext().getBean(
       "fbrp_scheduler");
       if (scheduler != null) {
    scheduler.start();
       }
    } catch (Exception e) {
       log.warn("??", e);
    }*/

    LicenseColl licenseList = null;
    try {
        licenseList = (LicenseColl) ContextInit.getContext().getBean("fbrp_licenseColl");
    } catch (Exception exe) {
        log.warn("License?");
    }
    if (licenseList != null) {
        boolean licenseIsValid = ValidateLicense.validateLicense(licenseList, ContextUtil.getApplicationPath());
        ContextUtil.put("licenseIsValid", licenseIsValid, ContextUtil.SCOPE_APPLICATION);
    } else {
        ContextUtil.put("licenseIsValid", true, ContextUtil.SCOPE_APPLICATION);
    }
}

From source file:org.openhie.openempi.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 w  w  w. ja  v  a  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);

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

    PasswordEncoder passwordEncoder = null;
    try {
        ProviderManager provider = (ProviderManager) ctx.getBean("_authenticationManager");
        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().getName());
        }
        log.debug("Populating drop-downs...");
    }

    setupContext(context);
}

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

private File getWebInfDirectory(final ServletContextEvent sce) {
    final String path = sce.getServletContext().getRealPath("/WEB-INF");
    if (StringUtils.isNotBlank(path)) {
        return new File(path);
    }/*from  w ww . ja va  2s.c  o  m*/
    return null;
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.ApplicationModelSetup.java

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

    setupDisplayModel(bds, ctx, ss);//from  w ww.  j av  a  2s  .  c o m
}

From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    Log curLogger = logger;//  w  w w  .j  a va 2  s .c o  m
    try {
        ServletContext context = sce.getServletContext();
        logger = ServletUtils.wrapServletContext(context, Level.CONFIG);
        contextInitialized(context);
        logger.info("contextInitialized(" + context.getContextPath() + ")");
    } catch (Throwable t) {
        logger.error("Failed (" + t.getClass().getSimpleName() + ") to initialize: " + t.getMessage(), t);
        throw ExtendedExceptionUtils.toRuntimeException(t, true);
    } finally {
        logger = curLogger;
    }
}

From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java

@Override
public void contextDestroyed(ServletContextEvent sce) {
    Log curLogger = logger;//from  w ww.  java2  s.  co  m
    try {
        ServletContext context = sce.getServletContext();
        logger = ServletUtils.wrapServletContext(context, Level.CONFIG);
        contextDestroyed(context);
        logger.info("contextDestroyed(" + context.getContextPath() + ")");
    } catch (Throwable t) {
        logger.error("Failed (" + t.getClass().getSimpleName() + ") to destroy: " + t.getMessage(), t);
        throw ExtendedExceptionUtils.toRuntimeException(t, true);
    } finally {
        logger = curLogger;
    }
}