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.ovalsearch.listener.OvalsearchContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    LOG.info("Context Initialization event called");
    WebApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(sce.getServletContext());
    final IStartupService startupService = context.getBean(IStartupService.class);
    try {/*from  ww  w.  j  a va  2  s  . c  o m*/
        LOG.info("Loading Application Context");
        startupService.loadContext();
    } catch (Exception e) {
        LOG.error("Error while initializing application:", e);
    }
}

From source file:lt.bsprendimai.ddesk.servlets.LocaleContextListener.java

/**
 * ### Method from ServletContextListener ###
 *
 * Called when a Web application is first ready to process requests
 * (i.e. on Web server startup and when a context is added or reloaded).
 *
 * For example, here might be database connections established
 * and added to the servlet context attributes.
 *///from w  w w .ja va 2  s  . co  m
public void contextInitialized(ServletContextEvent evt) {

    try {
        Configuration.setPreferences(new Properties());

        File f = new File(evt.getServletContext().getRealPath("/") + "/WEB-INF/configuration.properties")
                .getAbsoluteFile();

        Configuration.setPropertiesFile(f);

        if (f.exists()) {
            InputStream ins = new FileInputStream(f);
            Configuration.getPreferences().load(ins);
            ins.close();
        }

        f = new File(evt.getServletContext().getRealPath("/"));
        Configuration.setRootFile(f);

        Configuration.setMailSession(Session.getInstance(Configuration.getPreferences()));

    } catch (Exception excv) {
        excv.printStackTrace();
        LogFactory.getLog(Configuration.class).error("error loading configuration ", excv);
    }
}

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

public void contextInitialized(ServletContextEvent sce) {
    System.out.println("Starting FtpServer");

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());

    FtpServer server = (FtpServer) ctx.getBean("myServer");

    sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);

    try {//ww  w .ja  va2 s.c o m
        server.start();
        System.out.println("FtpServer started");
    } catch (Exception e) {
        throw new RuntimeException("Failed to start FtpServer", e);
    }
}

From source file:burrito.Configurator.java

@Override
public void contextInitialized(ServletContextEvent ctx) {
    if (isDevMode(ctx.getServletContext())) {
        SITE_IDENTIFIER = configureSiteIdentifier() + DEV_MODE_CONFIGURATION_SUFFIX;
    } else {//w  ww.java  2 s. c o m
        SITE_IDENTIFIER = configureSiteIdentifier();
    }
    BROADCAST_SETTINGS = configureBroadcastSettings();
    ADMIN_PROTECTOR = configureAdminProtector();
    MAY_RETIRE_SITELETS = mayRetireSitelets();

    init();
}

From source file:org.iterx.miru.support.servlet.dispatcher.context.BootstrapServletContextListener.java

public void contextDestroyed(ServletContextEvent servletContextEvent) {
    ServletContext servletContext;/*from w  ww  .  ja va 2 s .c  o  m*/

    servletContext = servletContextEvent.getServletContext();
    servletContext.removeAttribute((DispatcherApplicationContext.class).getName());

    synchronized (contexts) {
        contexts.remove(resolveContextPath(servletContext));
    }
}

From source file:org.sindice.servlet.sparqlqueryservlet.SparqlQueryServletListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);

    final ServletContext context = sce.getServletContext();

    logger.info("initializing SQS context");
    XMLConfiguration config = (XMLConfiguration) sce.getServletContext().getAttribute("config");

    // PreProcessing
    final String prep = config.getString(SQS_WRAPPER + "." + PREPROCESSING, "");
    context.setAttribute(SQS_WRAPPER + PREPROCESSING, prep);
    final String[] prepArgs = getParametersWithLogging(config, SQS_WRAPPER + "." + PREPROCESSING_ARGS,
            new String[] {});
    context.setAttribute(SQS_WRAPPER + PREPROCESSING_ARGS, prepArgs);

    final String backend = config.getString(SQS_WRAPPER + "." + BACKEND, BackendType.NATIVE.toString());
    context.setAttribute(SQS_WRAPPER + BACKEND, backend);
    // TODO handle HTTPmode
    final String[] backendArgs = getParametersWithLogging(config, SQS_WRAPPER + "." + BACKEND_ARGS,
            new String[] { "./native-repository" });
    context.setAttribute(SQS_WRAPPER + BACKEND_ARGS, backendArgs);

    logger.info("Backend={} BackendArgs={}", backend, Arrays.toString(backendArgs));

    final String useMemcached = getParameterWithLogging(config, "USE_MEMCACHED", "false");
    final String memcachedHost = getParameterWithLogging(config, "MEMCACHED_HOST", "localhost");
    final String memcachedPort = getParameterWithLogging(config, "MEMCACHED_PORT", "11211");

    if (Boolean.parseBoolean(useMemcached)) {
        try {//from  ww w .j a  v  a 2  s.  co m
            final List<InetSocketAddress> addresses = AddrUtil
                    .getAddresses(memcachedHost + ":" + memcachedPort);
            wrapper = new MemcachedClientWrapper(new MemcachedClient(addresses));
            sce.getServletContext().setAttribute(SQS_WRAPPER + MemcachedClientWrapper.class.getName(), wrapper);
        } catch (IOException e) {
            logger.error("Could not initialize memcached !!!", e);
        }
    }
}

From source file:es.logongas.ix3.web.database.DatabaseMigrateContextListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContextEvent.getServletContext());
    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    //Permitirmos varias "locations" en el parmetro separados por "\n"
    String[] rawLocations = (servletContextEvent.getServletContext()
            .getInitParameter("databasemigration.location") + "").split("\\n");
    List<String> locations = new ArrayList<String>();
    for (String location : rawLocations) {
        if ((location != null) && (location.trim().isEmpty() == false)) {
            locations.add(location);//w w w  . j a  v a2 s  . c o m
        }
    }

    databaseMigration.migrate(locations);
}

From source file:com.fpmislata.banco.presentation.database.ServerContextListenerImpl.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("Iniciando");
    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sce.getServletContext());
    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    databaseMigration.migrate();/*w w w  .jav  a  2s .  c om*/

}

From source file:edu.lternet.pasta.datapackagemanager.dataserver.ConfigurationListener.java

/**
 * Run initialization code when at web application start-up.
 * //from w  w w. ja  va  2 s  .co m
 * 
 * @param  servletContextEvent     The ServletContextEvent object
 * @throws ResourceNotFoundException
 *                 if the properties file can not be found
 * @throws IllegalStateException
 *                 if an {@link IOException} is thrown while reading the 
 *                 properties file
 */
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();

    // Create an absolute path for accessing configuration properties
    String cwd = servletContext.getRealPath(".");

    // Initialize log4j
    String log4jPropertiesPath = cwd + "/WEB-INF/conf/log4j.properties";
    PropertyConfigurator.configureAndWatch(log4jPropertiesPath);

    // Initialize commons configuration
    String appConfigPath = cwd + "/WEB-INF/conf/datapackagemanager.properties";
    try {
        config = new PropertiesConfiguration(appConfigPath);
        config.setProperty("system.cwd", cwd);
        config.save();
    } catch (ConfigurationException e) {
        logger.error(e);
        e.printStackTrace();
    }

}

From source file:org.jasig.portlet.announcements.spring.PortletApplicationContextLocator.java

public void contextInitialized(ServletContextEvent sce) {
    servletContext = sce.getServletContext();
}