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.appeligo.config.ConfigurationInitializer.java

/**
 * Expected to initialize n servlet initializaton.
 *///from ww  w.  j  ava  2s .  co  m
public void contextInitialized(ServletContextEvent event) {

    ServletContext context = event.getServletContext();
    String rootPath = context.getInitParameter("ConfigurationRootDir");
    if (rootPath == null) {
        rootPath = "WEB-INF/config";
    }
    File rootDir = new File(context.getRealPath(rootPath));
    ConfigurationService.setRootDir(rootDir);

    String baseName = context.getInitParameter("ConfigurationBaseName");
    if (baseName != null) {
        ConfigurationService.setBaseName(baseName);
    }

    //configure the environment
    String envName = new EnvironmentLookup().getEnvironmentName();

    if (envName == null) {
        //look it up in the web.xml
        envName = context.getInitParameter("ConfigurationEnvName");
    }

    if (envName != null) {
        ConfigurationService.setEnvName(envName);
    } else {
        log.warn(
                "Cannot find envName from \"deploymentEnvironment\" JNDI variable or \"ConfigurationEnvName\" init param in web.xml. Using default name...");
    }

    ConfigurationService.init();
}

From source file:com.dm.platform.listener.base.MyServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("MyServletContextListener");
    ServletContext sc = sce.getServletContext();

    ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class);
    sr.setInitParameter("contextConfigLocation", "/WEB-INF/dispatcher-servlet.xml");
    sr.addMapping("/spring/*");

    FilterRegistration fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");
    //          fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(), DelegatingFilterProxy.class);
    //        fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");

    sc.addListener(new ContextLoaderListener());
}

From source file:com.ryantenney.metrics.spring.servlets.MetricsServletsContextListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext())
            .getAutowireCapableBeanFactory().autowireBean(this);

    metricsServletContextListener.contextInitialized(event);
    healthCheckServletContextListener.contextInitialized(event);
}

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

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

    Server h2TestDb = (Server) context.getAttribute(H2_TESTDB);
    if (h2TestDb != null) {
        h2TestDb.shutdown();//from   w  w  w.  ja v  a 2  s  .c  o m
    }
}

From source file:org.aon.esolutions.appconfig.client.web.SystemPropertiesListener.java

/**
  * @see ServletContextListener#contextInitialized(ServletContextEvent)
  *///  w  ww.jav  a 2s.c o  m
public void contextInitialized(ServletContextEvent evt) {
    loadPropsFromSystem(evt.getServletContext());
    loadPropsFromClasspath(evt.getServletContext());
}

From source file:com.cuubez.visualizer.servlet.VzBootstrapContextListener.java

private ApplicationConfigurationContext generateApplicationConfigurationContext(
        ServletContextEvent contextEvent) {

    String applicationPath = contextEvent.getServletContext().getRealPath("/");
    String applicationName = getApplicationName(contextEvent.getServletContext().getContextPath());
    ApplicationConfigurationContext applicationConfigurationContext = new ApplicationConfigurationContext();
    applicationConfigurationContext.setApplicationName(applicationName);
    applicationConfigurationContext.setApplicationPath(applicationPath);

    String configurationType = contextEvent.getServletContext().getInitParameter("configuration-type");

    if ("xml-configuration".equalsIgnoreCase(configurationType)) {
        applicationConfigurationContext.setConfigurationType(ConfigurationType.XML);
    }//from  w  w  w . j  a v  a 2  s  .  c  o  m

    return applicationConfigurationContext;

}

From source file:org.cruxframework.crux.core.server.InitializerListener.java

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 *//*  w  w w. j  a v  a 2 s  .  c  o  m*/
public void contextInitialized(ServletContextEvent contextEvent) {
    try {
        context = contextEvent.getServletContext();
        if (Environment.isProduction()) {
            CruxBridge.getInstance().setSingleVM(true);
            Scanners.registerScanners(new ScannerRegistrations() {
                @Override
                public boolean initializeEagerly() {
                    return false;
                }

                @Override
                public void doRegistrations() {
                    ClassScanner.initializeScanner();
                }
            });
        }
        ServiceFactoryInitializer.initialize(context);
        RestServiceFactoryInitializer.initialize(context);

    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:com.dm.platform.listener.PlatformServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("contextInitialized");

    ServletContext sc = sce.getServletContext();
    sc.setInitParameter("contextConfigLocation", "/WEB-INF/applicationContext.xml");
    //    sc.addListener(ContextLoaderListener.class);
    FilterRegistration fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(),
            DelegatingFilterProxy.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/spring/*");

    ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class);
    sr.setInitParameter("contextConfigLocation",
            "/WEB-INF/dispatcher-servlet.xml /WEB-INF/platform-security.xml");
    sr.addMapping("/spring/*");

    fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");

}

From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsSmokeTest.java

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

    try {/*from w  w w .  j av a2  s  .c om*/
        new SmokeTester(this, ctx, ss).test();
    } catch (Exception e) {
        ss.fatal(this, "Found a problem while testing the PermissionSets", e);
    }
}

From source file:org.apache.shindig.common.servlet.GuiceServletContextListener.java

public void contextDestroyed(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    context.removeAttribute(INJECTOR_ATTRIBUTE);
}