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.cipango.sipatra.DefaultContextLoader.java

public void contextDestroyed(ServletContextEvent sce) {
    GenericObjectPool pool = (GenericObjectPool) sce.getServletContext().getAttribute(Attributes.POOL);
    stopPool(pool);// w  ww.  java2  s . co m
}

From source file:org.opennms.web.osgi.FrameworkStartupContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    try {// w  w w  .  j a v  a2 s .c om
        m_service = new Osgid();
        m_service.setHomeDirectory(sce.getServletContext().getRealPath("/") + File.separator + "WEB-INF"
                + File.separator + "karaf");
        m_service.start();
        sce.getServletContext().setAttribute(BundleContext.class.getName(), m_service.getBundleContext());
    } catch (Exception e) {
        LogUtils.errorf(this, e, "Could not start up OSGi container: %s", e.getMessage());
    }
}

From source file:com.athena.sqs.MessageReceiveListener.java

public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    listenQueueName = servletContext.getInitParameter("listenQueueName");
    if (listenQueueName == null) {
        listenQueueName = "your_listen_queue_name";
    }/*from w  w  w  . j a  v a  2  s  .  co m*/

    ApplicationContext applicationContext = (ApplicationContext) servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    receiver = applicationContext.getBean(MessageReceiver.class);

    // If you want to run multiple receivers, create tasks or change doReceive method to async.
    /*
     * List<BizQueue> list = dao.getBizQueueList();
     * for(BizQueue queue : list) {
     *     BizQueueTask task = new BiaQueueTask(sqsContext, queue);
     *     task.run(); // thread start.
     * }
     */
    try {
        logger.debug("***********************************************");
        logger.debug("SQS Message Receiver is starting");
        logger.debug("***********************************************");

        // Queue names are loaded from sqsContext.xml

        List<String> queueList = (List<String>) applicationContext.getBean("initialQueueList");

        for (String queueName : queueList) {
            receiver.doReceive(queueName);
            Thread.sleep(2000);
        }

        // Default listen queue start
        receiver.doReceive(listenQueueName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.indeed.boxcar.server.servlet.AbstractBoxcarContextListener.java

@Override
public void contextInitialized(final ServletContextEvent event) {
    final ServletContext servletContext = event.getServletContext();
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    try {//from w  ww. j av a  2  s .co  m
        final int maximumRequestsPerConnection = getIntInitParameter(servletContext,
                "maximumRequestsPerConnection", 1000);
        final int servicePort = getRequiredIntInitParameter(servletContext, "servicePort");
        final int localReservedPoolSize = getIntInitParameter(servletContext, "localReservedPoolSize", 0);
        if (localReservedPoolSize < 0) {
            throw new IllegalArgumentException(
                    "localReservedPoolSize must be >= 0, but was " + localReservedPoolSize);
        }

        server = createServer(servletContext, applicationContext, servicePort, maximumRequestsPerConnection,
                localReservedPoolSize);

        final Thread isdThread = new Thread(server);
        isdThread.setDaemon(true);
        isdThread.start();
    } catch (final Exception e) {
        logger.fatal("Error initializing webapp", e);
        throw new RuntimeException("Error in JobSearchContextListener init", e);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup.java

/**
 * Create an implementation of {@link FileStorage} and store it in the
 * {@link ServletContext}, as an attribute named according to
 * {@link #ATTRIBUTE_NAME}.//from w w w.ja v a  2  s  . c o  m
 */
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext ctx = sce.getServletContext();
    StartupStatus ss = StartupStatus.getBean(ctx);

    try {
        File baseDirectory = figureBaseDir(sce);
        Collection<String> fileNamespace = confirmDefaultNamespace(sce);
        FileStorage fs = new FileStorageImpl(baseDirectory, fileNamespace);

        ctx.setAttribute(ATTRIBUTE_NAME, fs);
    } catch (Exception e) {
        log.fatal("Failed to initialize the file system.", e);
        ss.fatal(this, "Failed to initialize the file system.", e);
    }
}

From source file:com.baomidou.framework.log.LogbackConfigListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    try {/*from   w w  w  . jav  a  2s  .  c  om*/
        String location = event.getServletContext().getInitParameter(CONFIG_LOCATION_PARAM);
        Resource resource = new DefaultResourceLoader().getResource(location);
        Map<Object, Object> context = new HashMap<Object, Object>();
        context.put("env", getRunEnvironment());
        StringWriter writer = new StringWriter();
        BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream(), getCharset()));
        Velocity.evaluate(new VelocityContext(context), writer, "LogbackConfigListener", br);
        this.initLogging(new ByteArrayInputStream(writer.toString().getBytes(getCharset())));
    } catch (Exception e) {
        throw new SpringWindException(e);
    }
}

From source file:org.apache.ftpserver.example.springwar.FtpServerListener.java

public void contextDestroyed(ServletContextEvent sce) {
    System.out.println("Stopping FtpServer");

    FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);

    if (server != null) {
        server.stop();/*  w w w.  j a v a  2  s .co m*/

        sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);

        System.out.println("FtpServer stopped");
    } else {
        System.out.println("No running FtpServer found");
    }

}

From source file:org.constretto.examples.dashboard.ConstrettoTaglibListener.java

public void contextInitialized(ServletContextEvent sce) {
    final WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sce.getServletContext());
    context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AUTOWIRE_BY_TYPE, true);
}

From source file:fr.cls.atoll.motu.web.servlet.listener.Log4JConfigListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    final String paramValue = sce.getServletContext().getInitParameter(CONFIG_LOCATION_PARAM);

    final String configFilename = (paramValue == null ? DEFAULT_CONFIG_FILE_NAME : paramValue);

    URL url = null;// w ww.  j a  v a2  s .c  o m
    try {
        if (configFilename.indexOf("file:") == 0) {
            url = new URL(configFilename);
        } else {
            url = ConfigLoader.getInstance().get(configFilename);
        }
        if (url == null) {
            url = new URL(configFilename);
        }
        if (url != null) {
            DOMConfigurator.configure(url);
        } else {
            System.err.println(configFilename + " configuration failure.");
            return;
        }
        Log log = LogFactory.getLog(Log4JConfigListener.class);
        log.info(configFilename + " configuration success.");
    } catch (FactoryConfigurationError ex) {
        System.err.println(configFilename + " configuration failure.");
    } catch (IOException e) {
        System.err.println("File \"" + configFilename + "\" not found in file system.");
    }

}

From source file:net.noday.core.listener.StartupListener.java

@SuppressWarnings("unchecked")
@Override/*www.  j  a va  2s  .  com*/
public void contextInitialized(ServletContextEvent sce) {
    ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context = sce.getServletContext());
    appDao = ctx.getBean(AppDao.class);
    appCache = ctx.getBean("appCache", Map.class);
    loadAppConfig();
    setWebProperty();
}