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.ericsson.eif.hansoft.HansoftManager.java

@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    final ServletContext servletContext = servletContextEvent.getServletContext();

    init(servletContext);// w ww .  j  a v  a  2  s.com

    // We are getting the adapter server name, port and scheme from the
    // adapter.properties file (8080 and 8080 are defaults if empty).
    // Alternative is to lazily get from the http request in first call,
    // but not given that those should be used. This way more explicit, but
    // less convenient - as need to be configured.

    String host = "";
    if (hansoftAdapterServer == null || hansoftAdapterServer.isEmpty()) {
        try {
            host = InetAddress.getLocalHost().getCanonicalHostName();
        } catch (final UnknownHostException exception) {
            host = "localhost";
        }
    } else {
        host = hansoftAdapterServer;
    }
    logger.info("Hansoft Adapter Server: " + host);

    String path = hansoftAdapterServerScheme + "://" + host;
    path += (hansoftAdapterServerPort.isEmpty() ? "" : ":" + hansoftAdapterServerPort);
    path += PROVIDER_CONTEXT_PATH;

    servletBase = path;
    serviceBase = path + PROVIDER_SERVICE_PATH;
    System.setProperty(SYSTEM_PROPERTY_NAME_REGISTRY_URI, serviceBase + "/" + CATALOG_PATH_SEGMENT);

    logger.info("Hansoft Adapter Servlet base: " + servletBase);
    logger.info("Hansoft Adapter Service base: " + serviceBase);
    logger.info("Initialize of Hansoft adapter done.");
}

From source file:org.dmb.trueprice.utils.internal.InitContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {

    log.warn("\n\t >>> \t INITIALIZING APPLICATION ....");

    //        sce.getServletConfig().gets

    ServletContext sctxt = sce.getServletContext();

    log.debug("\t >>>\t SHOW servlets names list ");
    //            log.debug("\t >>>\t SERVLET NAME IS > " + sctxt.getServletContextName());
    Map<String, ? extends ServletRegistration> eParam = sctxt.getServletRegistrations();
    for (String paramName : eParam.keySet()) {
        //                String paramName = eParam.nextElement();
        //                String paramValue = sctxt.getInitParameter(paramName).toString();

        if (paramName != null) {
            String paramValue = eParam.get(paramName)
                    //on ajoute .getName car l'obejt dans la Map extends ServletRegistration
                    .getName();//from   www  .  ja v  a 2  s .  c om
            log.debug("\t >> New servlet [" + ("".equals(paramName) ? "???" : paramName)
            //                    log.debug("\t >> New servlet [" + ("".equals(paramName) ? "???" : paramName) 
                    + "] > " + ("".equals(paramValue) ? "???" : paramValue));
            servletsContext.put(paramName, null);
        }

    }

    //            log.debug("\t >>>\t SHOW INIT PARAMETERS of SERVLET CONTEXT");
    //            log.debug("\t >>>\t SERVLET NAME IS > " + sctxt.getServletContextName());
    //            Enumeration<String> eParam = sctxt.getInitParameterNames();
    //            while (eParam.hasMoreElements()) {
    //            String paramName = eParam.nextElement();
    //            String paramValue = sctxt.getInitParameter(paramName).toString();
    //            log.debug("New init param [" + (paramName == null ? "???" : paramName) 
    //                    + "] > " + (paramValue == null ? "???" : paramValue)
    //            );
    //            }
    //        
    //            log.debug("\t >>>\t SHOW ATTRIBUTES of SERVLET CONTEXT");
    //            Enumeration<String> e = sctxt.getAttributeNames();
    //            while (e.hasMoreElements()) {
    //            String attName = e.nextElement();
    //            String attValue = sctxt.getAttribute(attName).toString();
    //            log.debug("New att [" + (attName == null ? "???" : attName) 
    //                    + "] > " + (attValue == null ? "???" : attValue)
    //            );
    //              }

    //    servletsContext = sctxt;

}

From source file:org.kuali.coeus.sys.framework.service.KcServiceLocatorListener.java

/**
 * ServletContextListener interface implementation that schedules the start of the lifecycle
 *//*from   ww w. ja va2  s.com*/
@Override
public void contextInitialized(ServletContextEvent sce) {
    long startInit = System.currentTimeMillis();
    LOG.info("Initializing Kuali Coeus Application...");

    // Stop Quartz from "phoning home" on every startup
    System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");

    String bootstrapSpringBeans = "";
    if (!StringUtils.isBlank(System.getProperty(WEB_BOOTSTRAP_SPRING_FILE))) {
        bootstrapSpringBeans = System.getProperty(WEB_BOOTSTRAP_SPRING_FILE);
    } else if (!StringUtils.isBlank(sce.getServletContext().getInitParameter(WEB_BOOTSTRAP_SPRING_FILE))) {
        String bootstrapSpringInitParam = sce.getServletContext().getInitParameter(WEB_BOOTSTRAP_SPRING_FILE);
        // if the value comes through as ${bootstrap.spring.beans}, we ignore it
        if (!DEFAULT_SPRING_BEANS_REPLACEMENT_VALUE.equals(bootstrapSpringInitParam)) {
            bootstrapSpringBeans = bootstrapSpringInitParam;
            LOG.info("Found bootstrap Spring Beans file defined in servlet context: " + bootstrapSpringBeans);
        }
    }

    Properties baseProps = new Properties();
    baseProps.putAll(getContextParameters(sce.getServletContext()));
    baseProps.putAll(System.getProperties());

    final String configFile = baseProps.getProperty("web.bootstrap.config.file");

    JAXBConfigImpl config = StringUtils.isNotBlank(configFile) ? new JAXBConfigImpl(configFile, baseProps)
            : new JAXBConfigImpl(baseProps);

    try {
        config.parseConfig();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    //override all configured items with system properties
    config.putProperties(System.getProperties());
    ConfigContext.init(config);

    context = new XmlWebApplicationContext();
    if (!StringUtils.isEmpty(bootstrapSpringBeans)) {
        context.setConfigLocation(bootstrapSpringBeans);
    }
    context.setServletContext(sce.getServletContext());
    context.refresh();
    context.start();

    KcServiceLocator.setAppContext(getContext());

    long endInit = System.currentTimeMillis();
    LOG.info("...Kuali Coeus Application successfully initialized, startup took " + (endInit - startInit)
            + " ms.");
}

From source file:net.officefloor.plugin.servlet.OfficeFloorServletIntegrationToContainerTest.java

/**
 * Ensure able to render JSP from HTTP state objects.
 */// w w  w .j a va  2s  .co  m
public void testJspStateIntegration() throws Exception {

    // Add the servlet for handling requests
    this.context.addEventListener(new MockJspIntergateServlet());

    // Add the JSP
    this.context.addServlet(new ServletHolder(JspServlet.class), "*.jsp");
    this.context.setClassLoader(Thread.currentThread().getContextClassLoader());

    // Add listener to initialise application object
    this.context.addEventListener(new ServletContextListener() {
        @Override
        public void contextInitialized(ServletContextEvent event) {
            // Load the application object
            MockApplicationObject object = new MockApplicationObject();
            object.text = "INIT";
            event.getServletContext().setAttribute("ApplicationBean", object);
        }

        @Override
        public void contextDestroyed(ServletContextEvent event) {
            // Do nothing
        }
    });

    // Start the server
    this.server.start();

    // Ensure can invoke JSP directly (without initialising)
    this.assertHttpRequest("/Template.jsp", "INIT null null");

    // Invoke to use template submit to create state for JSP
    this.assertHttpRequest("/template-submit.integrate", "application session request");
}

From source file:com.jsmartframework.web.manager.ContextControl.java

@Override
@SuppressWarnings("unchecked")
public void contextInitialized(ServletContextEvent event) {
    try {//from  www . j a v  a  2 s .c o  m
        ServletContext servletContext = event.getServletContext();

        CONFIG.init(servletContext);
        if (CONFIG.getContent() == null) {
            throw new RuntimeException("Configuration file " + Constants.WEB_CONFIG_XML
                    + " was not found in WEB-INF resources folder!");
        }

        String contextConfigLocation = "com.jsmartframework.web.manager";
        if (CONFIG.getContent().getPackageScan() != null) {
            contextConfigLocation += "," + CONFIG.getContent().getPackageScan();
        }

        // Configure necessary parameters in the ServletContext to set Spring configuration without needing an XML file
        AnnotationConfigWebApplicationContext configWebAppContext = new AnnotationConfigWebApplicationContext();
        configWebAppContext.setConfigLocation(contextConfigLocation);

        CONTEXT_LOADER = new ContextLoader(configWebAppContext);
        CONTEXT_LOADER.initWebApplicationContext(servletContext);

        TagEncrypter.init();
        TEXTS.init();
        IMAGES.init(servletContext);
        HANDLER.init(servletContext);

        // ServletControl -> @MultipartConfig @WebServlet(name = "ServletControl", displayName = "ServletControl", loadOnStartup = 1)
        Servlet servletControl = servletContext.createServlet(
                (Class<? extends Servlet>) Class.forName("com.jsmartframework.web.manager.ServletControl"));
        ServletRegistration.Dynamic servletControlReg = (ServletRegistration.Dynamic) servletContext
                .addServlet("ServletControl", servletControl);
        servletControlReg.setAsyncSupported(true);
        servletControlReg.setLoadOnStartup(1);

        // ServletControl Initial Parameters
        InitParam[] initParams = CONFIG.getContent().getInitParams();
        if (initParams != null) {
            for (InitParam initParam : initParams) {
                servletControlReg.setInitParameter(initParam.getName(), initParam.getValue());
            }
        }

        // MultiPart to allow file upload on ServletControl
        MultipartConfigElement multipartElement = getServletMultipartElement();
        if (multipartElement != null) {
            servletControlReg.setMultipartConfig(multipartElement);
        }

        // Security constraint to ServletControl
        ServletSecurityElement servletSecurityElement = getServletSecurityElement(servletContext);
        if (servletSecurityElement != null) {
            servletControlReg.setServletSecurity(servletSecurityElement);
        }

        // TODO: Fix problem related to authentication by container to use SSL dynamically (Maybe create more than one servlet for secure and non-secure patterns)
        // Check also the use of request.login(user, pswd)
        // Check the HttpServletRequest.BASIC_AUTH, CLIENT_CERT_AUTH, FORM_AUTH, DIGEST_AUTH
        // servletReg.setRunAsRole("admin");
        // servletContext.declareRoles("admin");

        // ServletControl URL mapping
        String[] servletMapping = getServletMapping();
        servletControlReg.addMapping(servletMapping);

        // ErrorFilter -> @WebFilter(urlPatterns = {"/*"})
        Filter errorFilter = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.ErrorFilter"));
        FilterRegistration.Dynamic errorFilterReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("ErrorFilter", errorFilter);

        errorFilterReg.setAsyncSupported(true);
        errorFilterReg.addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR), true, "/*");

        // EncodeFilter -> @WebFilter(urlPatterns = {"/*"})
        Filter encodeFilter = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.EncodeFilter"));
        FilterRegistration.Dynamic encodeFilterReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("EncodeFilter", encodeFilter);

        encodeFilterReg.setAsyncSupported(true);
        encodeFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR), true,
                "/*");

        // CacheFilter -> @WebFilter(urlPatterns = {"/*"})
        Filter cacheFilter = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.CacheFilter"));
        FilterRegistration.Dynamic cacheFilterReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("CacheFilter", cacheFilter);

        cacheFilterReg.setAsyncSupported(true);
        cacheFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR), true,
                "/*");

        // Add custom filters defined by client
        for (String filterName : sortCustomFilters()) {
            Filter customFilter = servletContext
                    .createFilter((Class<? extends Filter>) HANDLER.webFilters.get(filterName));
            HANDLER.executeInjection(customFilter);

            WebFilter webFilter = customFilter.getClass().getAnnotation(WebFilter.class);
            FilterRegistration.Dynamic customFilterReg = (FilterRegistration.Dynamic) servletContext
                    .addFilter(filterName, customFilter);

            if (webFilter.initParams() != null) {
                for (WebInitParam initParam : webFilter.initParams()) {
                    customFilterReg.setInitParameter(initParam.name(), initParam.value());
                }
            }
            customFilterReg.setAsyncSupported(webFilter.asyncSupported());
            customFilterReg.addMappingForUrlPatterns(EnumSet.copyOf(Arrays.asList(webFilter.dispatcherTypes())),
                    true, webFilter.urlPatterns());
        }

        // FilterControl -> @WebFilter(servletNames = {"ServletControl"})
        Filter filterControl = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.FilterControl"));
        FilterRegistration.Dynamic filterControlReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("FilterControl", filterControl);

        filterControlReg.setAsyncSupported(true);
        filterControlReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
                DispatcherType.ERROR, DispatcherType.INCLUDE), true, "ServletControl");

        // OutputFilter -> @WebFilter(servletNames = {"ServletControl"})
        Filter outputFilter = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.OutputFilter"));
        FilterRegistration.Dynamic outputFilterReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("OutputFilter", outputFilter);

        outputFilterReg.setAsyncSupported(true);
        outputFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
                DispatcherType.ERROR, DispatcherType.INCLUDE), true, "ServletControl");

        // AsyncFilter -> @WebFilter(servletNames = {"ServletControl"})
        // Filter used case AsyncContext is dispatched internally by AsyncBean implementation
        Filter asyncFilter = servletContext.createFilter(
                (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.AsyncFilter"));
        FilterRegistration.Dynamic asyncFilterReg = (FilterRegistration.Dynamic) servletContext
                .addFilter("AsyncFilter", asyncFilter);

        asyncFilterReg.setAsyncSupported(true);
        asyncFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.ASYNC), true, "ServletControl");

        // SessionControl -> @WebListener
        EventListener sessionListener = servletContext.createListener((Class<? extends EventListener>) Class
                .forName("com.jsmartframework.web.manager.SessionControl"));
        servletContext.addListener(sessionListener);

        // RequestControl -> @WebListener
        EventListener requestListener = servletContext.createListener((Class<? extends EventListener>) Class
                .forName("com.jsmartframework.web.manager.RequestControl"));
        servletContext.addListener(requestListener);

        // Custom WebServlet -> Custom Servlets created by application
        for (String servletName : HANDLER.webServlets.keySet()) {
            Servlet customServlet = servletContext
                    .createServlet((Class<? extends Servlet>) HANDLER.webServlets.get(servletName));
            HANDLER.executeInjection(customServlet);

            WebServlet webServlet = customServlet.getClass().getAnnotation(WebServlet.class);
            ServletRegistration.Dynamic customReg = (ServletRegistration.Dynamic) servletContext
                    .addServlet(servletName, customServlet);

            customReg.setLoadOnStartup(webServlet.loadOnStartup());
            customReg.setAsyncSupported(webServlet.asyncSupported());

            WebInitParam[] customInitParams = webServlet.initParams();
            if (customInitParams != null) {
                for (WebInitParam customInitParam : customInitParams) {
                    customReg.setInitParameter(customInitParam.name(), customInitParam.value());
                }
            }

            // Add mapping url for custom servlet
            customReg.addMapping(webServlet.urlPatterns());

            if (customServlet.getClass().isAnnotationPresent(MultipartConfig.class)) {
                customReg.setMultipartConfig(new MultipartConfigElement(
                        customServlet.getClass().getAnnotation(MultipartConfig.class)));
            }
        }

        // Controller Dispatcher for Spring MVC
        Set<String> requestPaths = HANDLER.requestPaths.keySet();
        if (!requestPaths.isEmpty()) {
            ServletRegistration.Dynamic mvcDispatcherReg = servletContext.addServlet("DispatcherServlet",
                    new DispatcherServlet(configWebAppContext));
            mvcDispatcherReg.setLoadOnStartup(1);
            mvcDispatcherReg.addMapping(requestPaths.toArray(new String[requestPaths.size()]));

            // RequestPathFilter -> @WebFilter(servletNames = {"DispatcherServlet"})
            Filter requestPathFilter = servletContext.createFilter((Class<? extends Filter>) Class
                    .forName("com.jsmartframework.web.manager.RequestPathFilter"));
            FilterRegistration.Dynamic reqPathFilterReg = (FilterRegistration.Dynamic) servletContext
                    .addFilter("RequestPathFilter", requestPathFilter);

            reqPathFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST,
                    DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.INCLUDE, DispatcherType.ASYNC),
                    true, "DispatcherServlet");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.geoserver.GeoserverInitStartupListener.java

public void contextInitialized(ServletContextEvent sce) {
    // start up tctool - remove it before committing!!!!
    // new tilecachetool.TCTool().setVisible(true);

    // make sure we remember if GeoServer controls logging or not
    String strValue = GeoServerExtensions.getProperty(LoggingUtils.RELINQUISH_LOG4J_CONTROL,
            sce.getServletContext());
    relinquishLoggingControl = Boolean.valueOf(strValue);

    // if the server admin did not set it up otherwise, force X/Y axis
    // ordering//from  www .j  ava2s.com
    // This one is a good place because we need to initialize this property
    // before any other opeation can trigger the initialization of the CRS
    // subsystem
    if (System.getProperty("org.geotools.referencing.forceXY") == null) {
        System.setProperty("org.geotools.referencing.forceXY", "true");
    }
    if (Boolean.TRUE.equals(Hints.getSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER))) {
        Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, "http");
    }
    Hints.putSystemDefault(Hints.LENIENT_DATUM_SHIFT, true);

    // setup the referencing tolerance to make it more tolerant to tiny differences
    // between projections (increases the chance of matching a random prj file content
    // to an actual EPSG code
    Hints.putSystemDefault(Hints.COMPARISON_TOLERANCE, 1e-9);

    // don't allow the connection to the EPSG database to time out. This is a server app,
    // we can afford keeping the EPSG db always on
    System.setProperty("org.geotools.epsg.factory.timeout", "-1");

    // HACK: java.util.prefs are awful. See
    // http://www.allaboutbalance.com/disableprefs. When the site comes
    // back up we should implement their better way of fixing the problem.
    System.setProperty("java.util.prefs.syncInterval", "5000000");

    // Fix issue with tomcat and JreMemoryLeakPreventionListener causing issues with 
    // IIORegistry leading to imageio plugins not being properly initialized
    ImageIO.scanForPlugins();

    // HACK: under JDK 1.4.2 the native java image i/o stuff is failing
    // in all containers besides Tomcat. If running under jdk 1.4.2 we
    // disable the native codecs, unless the user forced the setting already
    if (System.getProperty("java.version").startsWith("1.4")
            && (System.getProperty("com.sun.media.imageio.disableCodecLib") == null)) {
        LOGGER.warning("Disabling mediaLib acceleration since this is a "
                + "java 1.4 VM.\n If you want to force its enabling, " //
                + "set -Dcom.sun.media.imageio.disableCodecLib=true " + "in your virtual machine");
        System.setProperty("com.sun.media.imageio.disableCodecLib", "true");
    } else {
        // in any case, the native png reader is worse than the pure java ones, so
        // let's disable it (the native png writer is on the other side faster)...
        ImageIOExt.allowNativeCodec("png", ImageReaderSpi.class, false);
        ImageIOExt.allowNativeCodec("png", ImageWriterSpi.class, true);
    }

    // initialize geotools factories so that we don't make a spi lookup every time a factory is needed
    Hints.putSystemDefault(Hints.FILTER_FACTORY, CommonFactoryFinder.getFilterFactory2(null));
    Hints.putSystemDefault(Hints.STYLE_FACTORY, CommonFactoryFinder.getStyleFactory(null));
    Hints.putSystemDefault(Hints.FEATURE_FACTORY, CommonFactoryFinder.getFeatureFactory(null));

    // initialize the default executor service
    final ThreadPoolExecutor executor = new ThreadPoolExecutor(CoverageAccessInfoImpl.DEFAULT_CorePoolSize,
            CoverageAccessInfoImpl.DEFAULT_MaxPoolSize, CoverageAccessInfoImpl.DEFAULT_KeepAliveTime,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    Hints.putSystemDefault(Hints.EXECUTOR_SERVICE, executor);
}

From source file:org.red5.server.war.WarLoaderServlet.java

/**
 * Clearing the in-memory configuration parameters, we will receive
 * notification that the servlet context is about to be shut down
 *//*w w  w .j a  va2 s  .  com*/
@Override
public void contextDestroyed(ServletContextEvent sce) {
    synchronized (servletContext) {
        logger.info("Webapp shutdown");
        // XXX Paul: grabbed this from
        // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go
        // in hopes that we can clear all the issues with J2EE containers
        // during shutdown
        try {
            ServletContext ctx = sce.getServletContext();
            // prepare spring for shutdown
            Introspector.flushCaches();
            // dereg any drivers
            for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) {
                Driver driver = (Driver) e.nextElement();
                if (driver.getClass().getClassLoader() == getClass().getClassLoader()) {
                    DriverManager.deregisterDriver(driver);
                }
            }
            // shutdown jmx
            JMXAgent.shutdown();
            // shutdown the persistence thread
            FilePersistenceThread persistenceThread = FilePersistenceThread.getInstance();
            if (persistenceThread != null) {
                persistenceThread.shutdown();
            }
            // shutdown spring
            Object attr = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
            if (attr != null) {
                // get web application context from the servlet context
                ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) attr;
                ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
                // for (String scope : factory.getRegisteredScopeNames()) {
                // logger.debug("Registered scope: " + scope);
                // }
                try {
                    for (String singleton : factory.getSingletonNames()) {
                        logger.debug("Registered singleton: " + singleton);
                        factory.destroyScopedBean(singleton);
                    }
                } catch (RuntimeException e) {
                }
                factory.destroySingletons();
                ctx.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
                applicationContext.close();
            }
            getContextLoader().closeWebApplicationContext(ctx);
            //            org.apache.commons.logging.LogFactory.releaseAll();
            //            org.apache.log4j.LogManager.getLoggerRepository().shutdown();
            //            org.apache.log4j.LogManager.shutdown();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

From source file:org.everit.authentication.cas.CasAuthentication.java

/**
 * Removes the previously registered {@link CasHttpSessionRegistry} from the
 * {@link ServletContext} when it is destroyed.
 *//*  w  w  w  . j  av a2  s  .  c o  m*/
@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    CasHttpSessionRegistry.removeInstance(servicePid, servletContext);
}

From source file:org.everit.authentication.cas.CasAuthentication.java

/**
 * Registers the {@link CasHttpSessionRegistry} to the {@link ServletContext} when it is
 * initialized.//from  w w  w .  j a v  a 2s.  co  m
 */
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    CasHttpSessionRegistry.registerInstance(servicePid, servletContext);
}

From source file:com.streamsets.datacollector.http.TestWebServerTaskHttpHttps.java

@Test
public void testWebAppSSOServiceDelegation() throws Exception {
    final DummySSOService delegatedTo = new DummySSOService();
    WebAppProvider webAppProvider = new WebAppProvider() {
        @Override/*from  w w w . j  a v  a  2  s.com*/
        public ServletContextHandler get() {
            ServletContextHandler handler = new ServletContextHandler();
            handler.setContextPath("/webapp");
            handler.addEventListener(new ServletContextListener() {
                @Override
                public void contextInitialized(ServletContextEvent sce) {
                    SSOService ssoService = (SSOService) sce.getServletContext()
                            .getAttribute(SSOService.SSO_SERVICE_KEY);
                    ssoService.setDelegateTo(delegatedTo);
                }

                @Override
                public void contextDestroyed(ServletContextEvent sce) {

                }
            });
            handler.addServlet(new ServletHolder(new PingServlet()), "/ping");
            return handler;
        }

        @Override
        public void postStart() {
        }
    };
    Configuration conf = new Configuration();
    int httpPort = getRandomPort();
    conf.set(WebServerTask.DPM_ENABLED, true);
    conf.set(WebServerTask.HTTP_PORT_KEY, httpPort);
    final WebServerTask ws = createWebServerTask(createTestDir(), conf, ImmutableSet.of(webAppProvider));
    try {
        ws.initTask();
        new Thread() {
            @Override
            public void run() {
                ws.runTask();
            }
        }.start();
        Thread.sleep(1000);

        Assert.assertTrue(delegatedTo.inited);
    } finally {
        ws.stopTask();
    }
}