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.lbogdanov.poker.web.AppInitializer.java

/**
 * {@inheritDoc}//from w w w . ja  v a 2 s.  c o m
 */
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    servletContext = servletContextEvent.getServletContext();
    super.contextInitialized(servletContextEvent);
}

From source file:com.cubusmail.server.services.CubusStartupListener.java

public void contextInitialized(ServletContextEvent servletcontextevent) {

    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletcontextevent.getServletContext());

    try {/*from  w ww .j  av  a2  s  .  c  om*/
        DBManager dbManager = context.getBean(DBManager.class);
        dbManager.initInternalDB();
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not initialize internal database!");
    }

    try {
        URL test = CubusStartupListener.class.getClassLoader()
                .getResource(CubusConstants.LOGIN_MODULE_CONFIG_FILE);
        System.setProperty(CubusConstants.JAAS_PROPERTY_NANE, test.getFile());
    } catch (Exception e) {
        log.fatal(e.getMessage(), e);
        throw new IllegalStateException("Could not load " + CubusConstants.LOGIN_MODULE_CONFIG_FILE);
    }
}

From source file:org.apache.openejb.arquillian.tests.listenerenventry.PojoServletContextListener.java

public void contextInitialized(ServletContextEvent event) {
    final String name = "OpenEJB";
    final ServletContext context = event.getServletContext();

    if (car != null) {
        context.setAttribute(ContextAttributeName.KEY_Car.name(), car.drive(name));
    }/*from   w  w w.j  a  v a 2  s .  c  o  m*/
    if (localCompany != null) {
        context.setAttribute(ContextAttributeName.KEY_LocalEjb.name(), "Local: " + localCompany.employ(name));
    }
    if (market != null) {
        context.setAttribute(ContextAttributeName.KEY_Market.name(), market.shop(name));
    }
    if (connectionPool != null) {
        context.setAttribute(ContextAttributeName.KEY_ConnPool.name(), "Connection Pool: " + connectionPool);
    }
    if (startCount != null) {
        context.setAttribute(ContextAttributeName.KEY_StartCount.name(),
                "Start Expressions.Count: " + startCount);
    }
    if (initSize != null) {
        context.setAttribute(ContextAttributeName.KEY_InitSize.name(), "Init Size: " + initSize);
    }
    if (totalQuantity != null) {
        context.setAttribute(ContextAttributeName.KEY_TotalQuantity.name(), "Total Quantity: " + totalQuantity);
    }
    if (enableEmail != null) {
        context.setAttribute(ContextAttributeName.KEY_EnableEmail.name(), "Enable Email: " + enableEmail);
    }
    if (optionDefault != null) {
        context.setAttribute(ContextAttributeName.KEY_DefaultOption.name(), "Option Default: " + optionDefault);
    }
    if (StringUtils.isNotEmpty(returnEmail) && returnEmail.equals("tomee@apache.org")) {
        context.setAttribute(ContextAttributeName.KEY_ReturnEmail.name(), returnEmail);
    }
    if (auditWriter != null) {
        context.setAttribute(ContextAttributeName.KEY_AuditWriter.name(), auditWriter.getClass().getName());
    }
    if (defaultCode != null) {
        context.setAttribute(ContextAttributeName.KEY_DefaultCode.name(), "DefaultCode: " + defaultCode);
    }
}

From source file:org.openflamingo.web.util.VersionConfigurer.java

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    Log4jWebConfigurer.shutdownLogging(servletContextEvent.getServletContext());
}

From source file:com.littcore.web.listener.InitSystemListener.java

/**
 * ?.//from  ww w.  j a v a2  s .  c  om
 * 1????
 * 2?license
 *    2.1?Web????
 *  2.2??
 *  2.3?????
 * 
 * @param event 
 *            
 */
public void contextInitialized(ServletContextEvent event) {
    //??
    logger.info("System initializing...");
    super.contextInitialized(event);
    ServletContext application = event.getServletContext();
    CoreConstants.ROOT_PATH = application.getRealPath("/");
    logger.info("Run-time root path - " + CoreConstants.ROOT_PATH);
    //register date converter
    ConvertUtils.register(new DateConverter(), java.util.Date.class);
}

From source file:com.icanft.common.listener.ProjectInitListener.java

public void contextInitialized(ServletContextEvent event) {
    System.out.println("==========?==========");
    final ServletContext servletContext = event.getServletContext();

    ProjectInitListener.servletContext = servletContext;

    super.contextInitialized(event);

    setContext(WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext()));

    ContextUtil.setApplicationContext(ProjectInitListener.context);

    // ?FBRP?/*from  w ww . java  2  s .  com*/
    ContextUtil.setApplicationPath(event.getServletContext().getRealPath("/"));

    LicenseColl licenseList = null;
    try {
        licenseList = (LicenseColl) ProjectInitListener.getContext().getBean("fbrp_licenseColl");
    } catch (Exception exe) {
        log.warn("License?");
    }
    if (licenseList != null) {
        boolean licenseIsValid = ValidateLicense.validateLicense(licenseList, ContextUtil.getApplicationPath());
        ContextUtil.put("licenseIsValid", licenseIsValid, ContextUtil.SCOPE_APPLICATION);
    } else {
        ContextUtil.put("licenseIsValid", true, ContextUtil.SCOPE_APPLICATION);
    }
}

From source file:org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener.java

public void contextDestroyed(ServletContextEvent sce) {
    // destroy services factory
    CmisServiceFactory factory = (CmisServiceFactory) sce.getServletContext().getAttribute(SERVICES_FACTORY);

    if (factory != null) {
        factory.destroy();/*ww w  .j a  va2 s  .co  m*/
    }
}

From source file:org.os890.ds.addon.spring.impl.bidirectional.WebappAwareSpringContainerManager.java

@Override
public void contextInitialized(ServletContextEvent event) {
    //add (spring-)attributes to real context
    for (Map.Entry<String, String> entry : servletContext.getAttributes().entrySet()) {
        event.getServletContext().setAttribute(entry.getKey(), entry.getValue());
    }//from   w w w  .  j av  a 2 s  . c  om
}

From source file:com.serotonin.m2m2.web.M2M2ContextListener.java

@Override
public void contextInitialized(ServletContextEvent evt) {
    log.info("Mango Automation context starting");

    // Get a handle on the context.
    ServletContext ctx = evt.getServletContext();

    // Create all the stuff we need.
    constantsInitialize(ctx);//from ww  w.  j a  v  a  2  s  .com

    log.info("Mango Automation context started");
}

From source file:org.jasig.portal.jmx.JavaManagementServerListener.java

/**
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 *//*ww w.ja v  a 2  s  .  co  m*/
public void contextInitialized(ServletContextEvent event) {
    Log logger = LogFactory.getLog(LOGGER_NAME);
    final ServletContext servletContext = event.getServletContext();

    //Create the bean
    this.javaManagementServerBean = new JavaManagementServerBean();

    //Get the failOnException option
    final String failOnExceptionStr = servletContext.getInitParameter(FAIL_ON_EXCEPTION);
    boolean failOnException = Boolean.parseBoolean(failOnExceptionStr);
    this.javaManagementServerBean.setFailOnException(failOnException);

    final String host = servletContext.getInitParameter(JMX_RMI_HOST);
    this.javaManagementServerBean.setHost(host);

    //Get the base rmi port from the init parameters
    final String portOneStr = servletContext.getInitParameter(JMX_RMI_PORT_1);
    try {
        final int portOne = Integer.parseInt(portOneStr);
        this.javaManagementServerBean.setPortOne(portOne);
    } catch (NumberFormatException nfe) {
        logger.warn("init-parameter '" + JMX_RMI_PORT_1 + "' is required and must contain a number. '"
                + portOneStr + "' is not a valid number.", nfe);
    }

    //Get the second rmi port from the init parameters
    final String portTwoStr = servletContext.getInitParameter(JMX_RMI_PORT_2);
    try {
        final int portTwo = Integer.parseInt(portTwoStr);
        this.javaManagementServerBean.setPortTwo(portTwo);
    } catch (NumberFormatException nfe) {
        logger.debug("Failed to convert init-parameter '" + JMX_RMI_PORT_2 + "' with value '" + portTwoStr
                + "' to a number, defaulting portTwo to portOne + 1", nfe);
    }

    this.javaManagementServerBean.startServer();
}