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.apache.hawq.pxf.service.utilities.Log4jConfigure.java

/**
 * Initializes log4j logging for the webapp.
 *
 * Reads log4j properties file location from log4jConfigLocation parameter
 * in web.xml. When not using aboslute path, the path starts from the webapp
 * root directory. If the file can't be read, reverts to default
 * configuration file under WEB-INF/classes/pxf-log4j.properties.
 *
 * @param event Servlet context, used to determine webapp root directory.
 *///from  w w w. j a v  a  2 s .com
public static void configure(ServletContextEvent event) {

    final String defaultLog4jLocation = "WEB-INF/classes/pxf-log4j.properties";

    ServletContext context = event.getServletContext();
    String log4jConfigLocation = context.getInitParameter("log4jConfigLocation");

    if (!log4jConfigLocation.startsWith(File.separator)) {
        log4jConfigLocation = context.getRealPath("") + File.separator + log4jConfigLocation;
    }

    // revert to default properties file if file doesn't exist
    File log4jConfigFile = new File(log4jConfigLocation);
    if (!log4jConfigFile.canRead()) {
        log4jConfigLocation = context.getRealPath("") + File.separator + defaultLog4jLocation;
    }
    PropertyConfigurator.configure(log4jConfigLocation);
    LOG.info("log4jConfigLocation = " + log4jConfigLocation);
}

From source file:edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties.java

public static ConfigurationProperties getBean(ServletContextEvent sce) {
    if (sce == null) {
        throw new NullPointerException("sce may not be null.");
    }//w ww .ja v a2 s.c o m
    return getBean(sce.getServletContext());
}

From source file:com.tacitknowledge.util.migration.jdbc.util.ConfigurationUtil.java

/**
 * Returns the value of the specified servlet context initialization parameter.
 *
 * @param param          the parameter to return
 * @param sce            the <code>ServletContextEvent</code> being handled
 * @param caller         calling object, used for printing information if there is a problem
 * @param throwException if <code>true</code> then the method will throw an exception; if
 *                       <code>false</code> is supplied then it will return <code>null</code>
 * @return the value of the specified servlet context initialization parameter if found;
 *         <code>null</code> otherwise
 * @throws IllegalArgumentException if the parameter does not exist
 *//*from  www .j  a  va  2  s .  com*/
private static String getServletContextParam(String param, ServletContextEvent sce, Object caller,
        boolean throwException) throws IllegalArgumentException {
    ServletContext context = sce.getServletContext();
    String value = context.getInitParameter(param);

    if (value == null && throwException) {
        throw new IllegalArgumentException(
                "'" + param + "' is a required " + "servlet context initialization parameter for the \""
                        + caller.getClass().getName() + "\" class.  Aborting.");
    }

    return value;
}

From source file:org.lobzik.home_sapiens.pi.AppData.java

public static void init(ServletContextEvent sce) {
    try {//w  w  w. ja  va2s . c o  m
        List<String> eps = getHTTPEndPoints();
        if (!eps.isEmpty()) {
            localUrlContPath = eps.get(0) + sce.getServletContext().getContextPath();
        }
        System.out.println("checking for run file");
        runsAfterFailure = new File(RUN_FILE).exists();
        if (runsAfterFailure) {
            System.err.println("!!!! Runs after failure!!!");
        }
        System.out.println("checking for reboot file");
        runsAfterReboot = new File(REBOOT_FILE).exists();
        if (runsAfterReboot) {
            System.out.println("Runs after reboot");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (localUrlContPath == null) {
        localUrlContPath = "http://localhost/" + sce.getServletContext().getContextPath();
    }
}

From source file:org.kuali.rice.core.web.util.PropertySources.java

/**
 * Check system properties and servlet context init params for an annotated Spring configuration
 * class located under {@code key}. If present, create a new
 * {@AnnotationConfigWebApplicationContext} and register
 * the annotated configuration class. Refresh the context and then examine it for a
 * {@code PropertySource<?>} bean. There must be exactly one {@code PropertySource<?>} bean
 * present in the application context.//from   www.ja  v  a 2s .  c o  m
 */
public static Optional<PropertySource<?>> getPropertySource(ServletContextEvent sce, String key) {
    Optional<String> annotatedClass = getProperty(sce, key);
    if (annotatedClass.isPresent()) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setServletContext(sce.getServletContext());
        PropertySource<?> propertySource = getPropertySource(annotatedClass.get(), context);
        return Optional.<PropertySource<?>>of(propertySource);
    } else {
        return Optional.absent();
    }
}

From source file:org.kuali.rice.core.web.util.PropertySources.java

/**
 * Examine both system properties and servlet context init parameters for the presence of a
 * value under {@code key}./*from ww  w  . j av a 2s. com*/
 */
public static Optional<String> getProperty(ServletContextEvent sce, String key) {
    checkNotNull(key, "'key' cannot be null");

    // If there is a system property value, use it
    String sys = System.getProperty(key);
    if (!StringUtils.isBlank(sys)) {
        logger.info("Found [{}] defined in system properties: [{}]", key, sys);
        return Optional.of(sys);
    }

    // If there is a servlet context value, use it. Unless it's blank or an unresolved placeholder
    String web = sce.getServletContext().getInitParameter(key);
    if (StringUtils.isBlank(web) || isPlaceHolder(web)) {
        return Optional.absent();
    } else {
        logger.info("Found [{}] defined in servlet context: [{}]", key, web);
        return Optional.of(web);
    }
}

From source file:me.j360.boot.advance.listener.J360ServletContextListener.java

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

From source file:sindica.to.dropwizard.spring.servlet.SpringContextLoaderListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    sce.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    context.setServletContext(sce.getServletContext());
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerSetup.java

@Override
public void contextInitialized(ServletContextEvent event) {
    ServletContext sc = event.getServletContext();
    FreemarkerComponentGenerator.setServletContext(sc);
    UrlBuilder.contextPath = sc.getContextPath();

    log.info("Freemarker templating system initialized.");
}

From source file:ContextLogger.java

public void contextDestroyed(ServletContextEvent sce) {

    String name = sce.getServletContext().getServletContextName();

    //log request of the INFO level
    log.info("ServletContext shut down: " + (name == null ? "" : name));

}