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.red5.server.war.WarLoaderServlet.java

/**
 * Main entry point for the Red5 Server as a war
 *//*from  www  .jav  a 2s  . c  o m*/
// Notification that the web application is ready to process requests
@Override
public void contextInitialized(ServletContextEvent sce) {
    if (null != servletContext) {
        return;
    }
    System.setProperty("red5.deployment.type", "war");

    servletContext = sce.getServletContext();
    String prefix = servletContext.getRealPath("/");

    long time = System.currentTimeMillis();

    logger.info("RED5 Server (http://www.osflash.org/red5)");
    logger.info("WAR loader");
    logger.debug("Path: " + prefix);

    try {
        // instance the context loader
        contextLoader = createContextLoader();
        applicationContext = (ConfigurableWebApplicationContext) contextLoader
                .initWebApplicationContext(servletContext);
        logger.debug("Root context path: " + applicationContext.getServletContext().getContextPath());

        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();

        // register default
        factory.registerSingleton("default.context", applicationContext);

        // get the main factory
        parentFactory = (DefaultListableBeanFactory) factory.getParentBeanFactory();

    } catch (Throwable t) {
        logger.error("", t);
    }

    long startupIn = System.currentTimeMillis() - time;
    logger.info("Startup done in: " + startupIn + " ms");

}

From source file:io.joynr.runtime.MessagingServletConfig.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {

    ServletContext servletContext = servletContextEvent.getServletContext();

    // properties from appProperties will extend and override the default
    // properties
    Properties properties = new LowerCaseProperties(
            PropertyLoader.loadProperties(DEFAULT_SERVLET_MESSAGING_PROPERTIES));
    String appPropertiesFileName = servletContext.getInitParameter("properties");
    if (appPropertiesFileName != null) {
        Properties appProperties = ServletPropertyLoader.loadProperties(appPropertiesFileName, servletContext);
        properties.putAll(appProperties);
    } else {//w  w  w. ja  v  a2s  .co  m
        logger.warn("to load properties, set the initParameter 'properties' ");
    }

    // add OS environment properties
    properties.putAll(System.getenv());

    servletModuleName = properties.getProperty(INIT_PARAM_SERVLET_MODULE_CLASSNAME);
    servletModuleName = servletModuleName == null ? DEFAULT_SERVLET_MODULE_NAME : servletModuleName;

    // create a reflection set used to find
    // * all plugin application classes implementing the JoynApplication interface
    // * all servlets annotated as WebServlet
    // * the class implementing JoynrInjectorFactory (should be only one)
    Object[] appPackages = mergeAppPackages(properties);

    // Add Java system properties (set with -D)
    properties.putAll(System.getProperties());

    // TODO if reflections is ever a performance problem, can statically scan and save the reflections data using
    // Maven,
    // then work on the previously scanned data
    // see: https://code.google.com/p/reflections/wiki/UseCases
    Reflections reflections = new Reflections("io.joynr.runtime", appPackages);
    final Set<Class<?>> classesAnnotatedWithWebServlet = reflections
            .getTypesAnnotatedWith(JoynrWebServlet.class);
    final Set<Class<?>> classesAnnotatedWithProvider = reflections
            .getTypesAnnotatedWith(javax.ws.rs.ext.Provider.class);

    // The jerseyServletModule injects the servicing classes using guice,
    // instead of letting jersey do it natively
    jerseyServletModule = new AbstractJoynrServletModule() {

        @SuppressWarnings("unchecked")
        @Override
        protected void configureJoynrServlets() {
            bind(GuiceContainer.class);
            bind(JacksonJsonProvider.class).asEagerSingleton();

            bind(MessagingService.class);
            //get all classes annotated with @Provider and bind them
            for (Class<?> providerClass : classesAnnotatedWithProvider) {
                bind(providerClass).in(Scopes.SINGLETON);
            }

            for (Class<?> webServletClass : classesAnnotatedWithWebServlet) {
                if (!HttpServlet.class.isAssignableFrom(webServletClass)) {
                    continue;
                }

                bind(webServletClass);
                JoynrWebServlet webServletAnnotation = webServletClass.getAnnotation(JoynrWebServlet.class);
                if (webServletAnnotation == null) {
                    logger.error("webServletAnnotation was NULL.");
                    continue;
                }
                serve(webServletAnnotation.value()).with((Class<? extends HttpServlet>) webServletClass);
            }
        }

        // this @SuppressWarnings is needed for the build on jenkins
        @SuppressWarnings("unused")
        @Provides
        public IServletMessageReceivers providesMessageReceivers() {
            return messageReceivers;
        }

    };
    Class<?> servletModuleClass = null;
    Module servletModule = null;
    try {
        servletModuleClass = this.getClass().getClassLoader().loadClass(servletModuleName);
        servletModule = (Module) servletModuleClass.newInstance();
    } catch (ClassNotFoundException e) {
        logger.debug("Servlet module class not found will use default configuration");
    } catch (Exception e) {
        logger.error("", e);
    }

    if (servletModule == null) {
        servletModule = new EmptyModule();
    }

    properties.put(MessagingPropertyKeys.PROPERTY_SERVLET_CONTEXT_ROOT, servletContext.getContextPath());

    String hostPath = properties.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH);
    if (hostPath == null) {
        hostPath = properties.getProperty("hostpath");
    }
    if (hostPath != null) {
        properties.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, hostPath);
    }

    // find all plugin application classes implementing the JoynApplication interface
    Set<Class<? extends JoynrApplication>> joynrApplicationsClasses = reflections
            .getSubTypesOf(JoynrApplication.class);
    Set<Class<? extends AbstractJoynrInjectorFactory>> joynrInjectorFactoryClasses = reflections
            .getSubTypesOf(AbstractJoynrInjectorFactory.class);
    assert (joynrInjectorFactoryClasses.size() == 1);

    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
        }
    });
    AbstractJoynrInjectorFactory injectorFactory = injector
            .getInstance(joynrInjectorFactoryClasses.iterator().next());
    appLauncher = injector.getInstance(JoynrApplicationLauncher.class);

    logger.info("starting joynr with properties: {}", properties);

    appLauncher.init(properties, joynrApplicationsClasses, injectorFactory,
            Modules.override(jerseyServletModule, new CCInProcessRuntimeModule()).with(servletModule,
                    new ServletMessagingModule()));

    super.contextInitialized(servletContextEvent);
}

From source file:org.apache.wookie.server.ContextListener.java

public void contextInitialized(ServletContextEvent event) {
    try {/*from   w w w.  j av  a 2s  . co  m*/
        ServletContext context = event.getServletContext();

        /* 
         *  load the widgetserver.properties file and put it into this context
         *  as an attribute 'properties' available to all resources
         */
        PropertiesConfiguration configuration;
        File localPropsFile = new File(
                System.getProperty("user.dir") + File.separator + "local.widgetserver.properties");
        if (localPropsFile.exists()) {
            configuration = new PropertiesConfiguration(localPropsFile);
            _logger.info("Using local widget server properties file: " + localPropsFile.toString());
        } else {
            configuration = new PropertiesConfiguration("widgetserver.properties");
            configuration.setFile(localPropsFile);
            configuration.save();
            _logger.info("Using default widget server properties, configure your local server using: "
                    + localPropsFile.toString());
        }
        context.setAttribute("properties", (Configuration) configuration);

        /*
         * Merge in system properties overrides
         */
        Iterator<Object> systemKeysIter = System.getProperties().keySet().iterator();
        while (systemKeysIter.hasNext()) {
            String key = systemKeysIter.next().toString();
            if (configuration.containsKey(key) || key.startsWith("widget.")) {
                String setting = configuration.getString(key);
                String override = System.getProperty(key);
                if ((override != null) && (override.length() > 0) && !override.equals(setting)) {
                    configuration.setProperty(key, override);
                    if (setting != null) {
                        _logger.info("Overridden server configuration property: " + key + "=" + override);
                    }
                }
            }
        }

        /*
         * Initialize persistence manager factory now, not on first request
         */
        PersistenceManagerFactory.initialize(configuration);

        /*
         * Initialise the locale handler
         */
        LocaleHandler.getInstance().initialize(configuration);
        final Locale locale = new Locale(configuration.getString("widget.default.locale"));
        final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale);

        /* 
        *  load the opensocial.properties file and put it into this context
        *  as an attribute 'opensocial' available to all resources
        */
        PropertiesConfiguration opensocialConfiguration;
        File localOpenSocialPropsFile = new File(
                System.getProperty("user.dir") + File.separator + "local.opensocial.properties");
        if (localOpenSocialPropsFile.exists()) {
            opensocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile);
            _logger.info("Using local open social properties file: " + localOpenSocialPropsFile.toString());
        } else {
            opensocialConfiguration = new PropertiesConfiguration("opensocial.properties");
            opensocialConfiguration.setFile(localOpenSocialPropsFile);
            opensocialConfiguration.save();
            _logger.info("Using default open social properties, configure your local server using: "
                    + localOpenSocialPropsFile.toString());
        }
        context.setAttribute("opensocial", (Configuration) opensocialConfiguration);

        /*
         * Load installed features
         */
        PropertiesConfiguration featuresConfiguration;
        File localFeaturesPropsFile = new File(
                System.getProperty("user.dir") + File.separator + "local.features.properties");
        if (localFeaturesPropsFile.exists()) {
            featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile);
            _logger.info("Loading local features file: " + localOpenSocialPropsFile.toString());
        } else {
            featuresConfiguration = new PropertiesConfiguration("features.properties");
            featuresConfiguration.setFile(localFeaturesPropsFile);
            featuresConfiguration.save();
            _logger.info("Loading default features, configure your local server using: "
                    + localFeaturesPropsFile.toString());
        }
        FeatureLoader.loadFeatures(featuresConfiguration);

        /*
         * Run diagnostics
         */
        Diagnostics.run(context, configuration);

        /*
         * Start hot-deploy widget watcher
         */
        if (configuration.getBoolean("widget.hot_deploy")) {
            startWatcher(context, configuration, localizedMessages);
        } else {
            _logger.info(localizedMessages.getString("WidgetHotDeploy.0"));
        }
    } catch (ConfigurationException ex) {
        _logger.error("ConfigurationException thrown: " + ex.toString());
    }
}

From source file:org.openspaces.pu.container.jee.jetty.JettyWebApplicationContextListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    final ServletContext servletContext = servletContextEvent.getServletContext();
    // a hack to get the jetty context
    final ServletContextHandler jettyContext = (ServletContextHandler) ((ContextHandler.Context) servletContext)
            .getContextHandler();//w w  w .j  a  v  a  2 s. c  o m
    final SessionHandler sessionHandler = jettyContext.getSessionHandler();
    BeanLevelProperties beanLevelProperties = (BeanLevelProperties) servletContext
            .getAttribute(JeeProcessingUnitContainerProvider.BEAN_LEVEL_PROPERTIES_CONTEXT);
    ClusterInfo clusterInfo = (ClusterInfo) servletContext
            .getAttribute(JeeProcessingUnitContainerProvider.CLUSTER_INFO_CONTEXT);
    if (beanLevelProperties != null) {

        // automatically enable GigaSpaces Session Manager when passing the relevant property
        String sessionsSpaceUrl = beanLevelProperties.getContextProperties().getProperty(JETTY_SESSIONS_URL);
        if (sessionsSpaceUrl != null) {
            logger.info("Jetty GigaSpaces Session support using space url [" + sessionsSpaceUrl + "]");
            GigaSessionManager gigaSessionManager = new GigaSessionManager();

            if (sessionsSpaceUrl.startsWith("bean://")) {
                ApplicationContext applicationContext = (ApplicationContext) servletContext
                        .getAttribute(JeeProcessingUnitContainerProvider.APPLICATION_CONTEXT_CONTEXT);
                if (applicationContext == null) {
                    throw new IllegalStateException("Failed to find servlet context bound application context");
                }
                GigaSpace space;
                Object bean = applicationContext.getBean(sessionsSpaceUrl.substring("bean://".length()));
                if (bean instanceof GigaSpace) {
                    space = (GigaSpace) bean;
                } else if (bean instanceof IJSpace) {
                    space = new GigaSpaceConfigurer((IJSpace) bean).create();
                } else {
                    throw new IllegalArgumentException(
                            "Bean [" + bean + "] is not of either GigaSpace type or IJSpace type");
                }
                gigaSessionManager.setSpace(space);
            } else {
                gigaSessionManager.setUrlSpaceConfigurer(
                        new UrlSpaceConfigurer(sessionsSpaceUrl).clusterInfo(clusterInfo));
            }

            String scavangePeriod = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_SCAVENGE_PERIOD);
            if (scavangePeriod != null) {
                gigaSessionManager.setScavengePeriod(Integer.parseInt(scavangePeriod));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting scavenge period to [" + scavangePeriod + "] seconds");
                }
            }
            String savePeriod = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_SAVE_PERIOD);
            if (savePeriod != null) {
                gigaSessionManager.setSavePeriod(Integer.parseInt(savePeriod));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting save period to [" + savePeriod + "] seconds");
                }
            }
            String lease = beanLevelProperties.getContextProperties().getProperty(JETTY_SESSIONS_LEASE);
            if (lease != null) {
                gigaSessionManager.setLease(Long.parseLong(lease));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting lease to [" + lease + "] milliseconds");
                }
            }

            // copy over session settings

            SessionManager sessionManager = sessionHandler.getSessionManager();
            gigaSessionManager.getSessionCookieConfig()
                    .setName(sessionManager.getSessionCookieConfig().getName());
            gigaSessionManager.getSessionCookieConfig()
                    .setDomain(sessionManager.getSessionCookieConfig().getDomain());
            gigaSessionManager.getSessionCookieConfig()
                    .setPath(sessionManager.getSessionCookieConfig().getPath());
            gigaSessionManager.setUsingCookies(sessionManager.isUsingCookies());
            gigaSessionManager.getSessionCookieConfig()
                    .setMaxAge(sessionManager.getSessionCookieConfig().getMaxAge());
            gigaSessionManager.getSessionCookieConfig()
                    .setSecure(sessionManager.getSessionCookieConfig().isSecure());
            gigaSessionManager.setMaxInactiveInterval(sessionManager.getMaxInactiveInterval());
            gigaSessionManager.setHttpOnly(sessionManager.getHttpOnly());
            gigaSessionManager.getSessionCookieConfig()
                    .setComment(sessionManager.getSessionCookieConfig().getComment());

            String sessionTimeout = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_TIMEOUT);
            if (sessionTimeout != null) {
                gigaSessionManager.setMaxInactiveInterval(Integer.parseInt(sessionTimeout) * 60);
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting session timeout to [" + sessionTimeout + "] seconds");
                }
            }

            GigaSessionIdManager sessionIdManager = new GigaSessionIdManager(jettyContext.getServer());
            sessionIdManager.setWorkerName(clusterInfo.getUniqueName().replace('.', '_'));
            gigaSessionManager.setIdManager(sessionIdManager);
            // replace the actual session manager inside the LazySessionManager with GS session manager, this is
            // because in Jetty 9 it no more possible to replace the session manager after the server started
            // without deleting all webapps.
            if ("GSLazySessionManager".equals(sessionManager.getClass().getSimpleName())) {
                try {
                    Method method = ReflectionUtils.findMethod(sessionManager.getClass(), "replaceDefault",
                            SessionManager.class);
                    if (method != null) {
                        ReflectionUtils.invokeMethod(method, sessionManager, gigaSessionManager);
                    } else {
                        throw new NoSuchMethodException("replaceDefault");
                    }
                } catch (Exception e) {
                    throw new RuntimeException(
                            "Failed to replace default session manager with GSSessionManager", e);
                }
            }
        }

        // if we have a simple hash session id manager, set its worker name automatically...
        if (sessionHandler.getSessionManager().getSessionIdManager() instanceof HashSessionIdManager) {
            HashSessionIdManager sessionIdManager = (HashSessionIdManager) sessionHandler.getSessionManager()
                    .getSessionIdManager();
            if (sessionIdManager.getWorkerName() == null) {
                final String workerName = clusterInfo.getUniqueName().replace('.', '_');
                if (logger.isDebugEnabled()) {
                    logger.debug("Automatically setting worker name to [" + workerName + "]");
                }
                stop(sessionIdManager, "to set worker name");
                sessionIdManager.setWorkerName(workerName);
                start(sessionIdManager, "to set worker name");
            }
        }
    }
}

From source file:com.siberhus.web.ckeditor.CkeditorConfigurationHolder.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    try {//w  ww. j  av  a  2s  .  c  om
        init(sce.getServletContext());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.sakaiproject.kernel.webapp.JaxRsApplicationListener.java

@SuppressWarnings("unchecked")
public void contextInitialized(ServletContextEvent event) {
    Registry<String, JaxRsSingletonProvider> singletonRegistry = getSingletonRegistry();
    Registry<String, JaxRsPrototypeProvider> prototypeRegistry = getPrototypeRegistry();
    String appClass = event.getServletContext().getInitParameter(Application.class.getName());
    Application app;//from   w ww . j a  va  2 s .c o m
    try {
        Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(appClass.trim());
        app = (Application) clazz.newInstance();
    } catch (Exception e) {
        LOG.warn("Unable to instantiate JAX-RS Application " + appClass);
        e.printStackTrace();
        return;
    }
    for (final Object object : app.getSingletons()) {
        if (!(object instanceof Documentable)) {
            throw new IllegalStateException(object + " must implement " + Documentable.class);
        }
        JaxRsSingletonProvider provider = new JaxRsSingletonProvider() {
            // The Application object is out of our hands, so we can't
            // properly constrain the classes it returns. Hence, cast it.
            private Documentable documentable = (Documentable) object;

            public Documentable getJaxRsSingleton() {
                return documentable;
            }

            public String getKey() {
                return documentable.getClass().getName();
            }

            public int getPriority() {
                return 0;
            }

            @Override
            public String toString() {
                return "Provider for: " + object.toString();
            }
        };
        jaxRsSingletonProviders.add(provider);
        singletonRegistry.add(provider);
        LOG.info("Added " + provider.getJaxRsSingleton() + " to JAX-RS registry " + singletonRegistry);
    }
    for (final Class<?> clazz : app.getClasses()) {
        if (!(Documentable.class.isAssignableFrom(clazz))) {
            throw new IllegalStateException(clazz + " must implement " + Documentable.class);
        }

        JaxRsPrototypeProvider provider = new JaxRsPrototypeProvider() {
            // The Application object is out of our hands, so we can't
            // properly constrain the classes it returns. Hence, cast it.
            private Class<? extends Documentable> documentable = (Class<? extends Documentable>) clazz;

            public Class<? extends Documentable> getJaxRsPrototype() {
                return documentable;
            }

            public String getKey() {
                return documentable.getClass().getName();
            }

            public int getPriority() {
                return 0;
            }

            @Override
            public String toString() {
                return "Provider for: " + clazz.toString();
            }
        };
        jaxRsPrototypeProviders.add(provider);
        prototypeRegistry.add(provider);
        LOG.info("Added " + provider.getJaxRsPrototype() + " to JAX-RS registry " + prototypeRegistry);

    }
}

From source file:io.seldon.servlet.ResourceManagerListener.java

public void contextInitialized(ServletContextEvent sce) {
    logger.info("**********************  STARTING API-SERVER INITIALISATION **********************");
    JDOFactory jdoFactory = null;// ww  w .  j  av  a  2s  . c  om
    try {
        final WebApplicationContext springContext = WebApplicationContextUtils
                .getWebApplicationContext(sce.getServletContext());
        jdoFactory = (JDOFactory) springContext.getBean("JDOFactory");

        zkClientConfigHandler = (ZkClientConfigHandler) springContext.getBean("zkClientConfigHandler");
        //InputStream propStream = sce.getServletContext().getResourceAsStream("/WEB-INF/labs.properties");
        InputStream propStream = getClass().getClassLoader().getResourceAsStream("/labs.properties");
        SecurityHashPeer.initialise();
        Properties props = new Properties();
        props.load(propStream);

        // Set the default client name from properties if it exists
        String defClientName = props.getProperty("io.seldon.labs.default.client");
        if (defClientName != null && defClientName.length() > 0) {
            Constants.DEFAULT_CLIENT = defClientName;
        }

        MemCachePeer.initialise(props);

        StatsdPeer.initialise(props);

        ZkCuratorHandler curatorHandler = ZkCuratorHandler.getPeer();
        if (curatorHandler != null) {
            ZkAlgorithmUpdaterFactory.initialise(props, curatorHandler);
        }

        zkClientConfigHandler.contextIntialised();
        logger.info("**********************  ENDING API-SERVER INITIALISATION **********************");
    } catch (IOException ex) {
        logger.error("IO Exception", ex);
    } catch (Exception ex) {
        logger.error("Exception at resource initialization", ex);
    } catch (Throwable e) {
        logger.error("Throwable during initialization ", e);
    } finally {
        if (jdoFactory != null)
            jdoFactory.cleanupPM();
    }
}

From source file:org.ohmage.jee.listener.ConfigurationFileImport.java

/**
 * Find the log file, if it exists, and add its properties to the system
 * properties./*from  www .  java  2s.  c  om*/
 */
@Override
public void contextInitialized(ServletContextEvent event) {
    // An empty Properties object that will be populated with the default
    // configuration.
    Properties defaultProperties = new Properties();
    File defaultConfiguration = new File(event.getServletContext().getRealPath("/") + CONFIG_FILE_DEFAULT);
    try {
        defaultProperties.load(new FileReader(defaultConfiguration));
    }
    // The default properties file didn't exist, which is alarming.
    catch (FileNotFoundException e) {
        LOGGER.log(Level.WARNING,
                "The default properties file is missing: " + defaultConfiguration.getAbsolutePath(), e);
    }
    // There was an error reading the default properties file.
    catch (IOException e) {
        LOGGER.log(Level.WARNING, "There was an error reading the default properties " + "file: "
                + defaultConfiguration.getAbsolutePath(), e);
    }

    // Get a handler for the properties file based on the operating system.
    File propertiesFile;
    if (System.getProperty("os.name").contains("Windows")) {
        propertiesFile = new File(CONFIG_FILE_DEFAULT_WINDOWS);
    } else {
        propertiesFile = new File(CONFIG_FILE_DEFAULT_POSIX);
    }

    // Attempts to retrieve the custom configuration file and store it.
    Properties customProperties = new Properties();
    try {
        customProperties.load(new FileReader(propertiesFile));
        LOGGER.log(Level.INFO, "The properties file was imported: " + propertiesFile.getAbsolutePath());
    }
    // The properties file didn't exist, which is fine.
    catch (FileNotFoundException e) {
        LOGGER.log(Level.INFO, "The properties file does not exist: " + propertiesFile.getAbsolutePath());
    }
    // There was a problem reading the properties.
    catch (IOException e) {
        LOGGER.log(Level.WARNING,
                "There was an error reading the properties file: " + propertiesFile.getAbsolutePath(), e);
    }

    // Set the properties files.
    PROPERTIES_ARRAY[0] = defaultProperties;
    PROPERTIES_ARRAY[1] = customProperties;

    // Create a merged properties and save it.
    for (Object key : defaultProperties.keySet()) {
        PROPERTIES.put(key, defaultProperties.get(key));
    }
    for (Object key : customProperties.keySet()) {
        PROPERTIES.put(key, customProperties.get(key));
    }
}

From source file:com.nec.harvest.servlet.listener.WebApplicationContextLoaderListener.java

/**
 * Close the root web application context
 *///from w w  w . j  a v a  2  s . c o  m
@Override
public void contextDestroyed(ServletContextEvent event) {
    super.contextDestroyed(event);

    // Destroying Harvest application.......
    if (logger.isDebugEnabled()) {
        logger.debug("Destroying Harvest application.......");
    }

    /// You can get Servlet Context
    ServletContext servletContext = event.getServletContext();
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    String jasperReportPath = getReportPath(webApplicationContext);

    // Delete jasper report folder
    logger.info("Trying to remove storaged folder for all reports", jasperReportPath);

    File folder = new File(jasperReportPath);
    if (folder.exists()) {
        try {
            FileUtil.delete(folder);
        } catch (IOException ex) {
            logger.warn(ex.getMessage());
        }
    }
}

From source file:org.apache.pluto.driver.PortalStartupListener.java

/**
 * Receives the startup notification and subsequently starts up the portal
 * driver. The following are done in this order:
 * <ol>//from  w  w  w.j  a  v  a  2s. co m
 * <li>Retrieve the ResourceConfig File</li>
 * <li>Parse the ResourceConfig File into ResourceConfig Objects</li>
 * <li>Create a Portal Context</li>
 * <li>Create the ContainerServices implementation</li>
 * <li>Create the Portlet Container</li>
 * <li>Initialize the Container</li>
 * <li>Bind the configuration to the ServletContext</li>
 * <li>Bind the container to the ServletContext</li>
 * <ol>
 *
 * @param event the servlet context event.
 */
public void contextInitialized(ServletContextEvent event) {
    LOG.info("Starting up Pluto Portal Driver. . .");

    ServletContext servletContext = event.getServletContext();

    WebApplicationContext springContext = null;

    try {
        springContext = (WebApplicationContext) servletContext
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    } catch (RuntimeException ex) {
        String msg = "Problem getting Spring context: " + ex.getMessage();
        LOG.error(msg, ex);
        throw ex;
    }

    LOG.debug(" [1a] Loading DriverConfiguration. . . ");
    DriverConfiguration driverConfiguration = (DriverConfiguration) springContext
            .getBean("DriverConfiguration");

    driverConfiguration.init(servletContext);

    LOG.debug(" [1b] Registering DriverConfiguration. . .");
    servletContext.setAttribute(DRIVER_CONFIG_KEY, driverConfiguration);

    LOG.debug(" [2a] Loading Optional AdminConfiguration. . .");
    AdminConfiguration adminConfiguration = (AdminConfiguration) springContext.getBean("AdminConfiguration");

    if (adminConfiguration != null) {
        LOG.debug(" [2b] Registering Optional AdminConfiguration");
        servletContext.setAttribute(ADMIN_CONFIG_KEY, adminConfiguration);
    } else {
        LOG.info("Optional AdminConfiguration not found. Ignoring.");
    }

    //        LOG.debug(" [3a] Loading VWBConfiguration. . .");
    //        VWBConfiguration vwbconfig = (VWBConfiguration)springContext.getBean("VWBConfiguration");
    //        vwbconfig.init(servletContext);

    //        LOG.debug(" [3b] Registering VWBConfiguration. . .");
    //        servletContext.setAttribute(VWB_CONFIG_KEY, vwbconfig);
    //        PortalSessionServiceImpl.init(vwbconfig);

    initContainer(servletContext);

    LOG.info("********** Pluto Portal Driver Started **********\n\n");
}