Example usage for javax.servlet ServletConfig getServletContext

List of usage examples for javax.servlet ServletConfig getServletContext

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:com.videobox.web.util.dwr.DwrVideoboxServlet.java

@Override
protected Container createContainer(ServletConfig servletConfig) {
    if (logger.isDebugEnabled()) {
        logger.debug("Creating container for Custom DWR servlet");
    }/*  w  w w .  j  a  v  a 2  s  .  co  m*/
    try {
        String packageList = servletConfig.getInitParameter("packages");
        ServletContext ctx = servletConfig.getServletContext();
        AutoAnnotationDiscoveryContainer container = new AutoAnnotationDiscoveryContainer();
        String classNames = container.findAnnotatedClasses(packageList, ctx);
        if (logger.isDebugEnabled()) {
            logger.debug("discovered @RemoteProxy annotated classes: " + classNames);
        }
        container.addParameter("classes", classNames);
        StartupUtil.setupDefaultContainer(container, servletConfig);
        return container;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        logger.info("Creation of Custom DWR servlet container done.");
    }
}

From source file:org.wandora.modules.servlet.ModulesServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    moduleManager = new ModuleManager();

    servletHome = config.getServletContext().getRealPath("/") + "WEB-INF";
    moduleManager.setVariable("servletHome", servletHome);

    //        SimpleLog log=new SimpleLog("ModulesServlet");
    //        log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
    Log log = new Jdk14Logger("ModulesServlet");
    moduleManager.setLogging(log);// w w w. j  a  v  a  2  s  .  c o  m
    String configFile = config.getInitParameter("modulesconfig");
    if (configFile == null) {
        configFile = config.getInitParameter("modulesConfig");
        if (configFile == null)
            configFile = "modulesconfig.xml";
    }

    bindAddress = config.getInitParameter("bindaddress");
    if (bindAddress == null) {
        bindAddress = config.getInitParameter("bindAddress");
    }

    moduleManager.addModule(servletModule, new ModuleSettings("rootServlet"));
    moduleManager.readXMLOptionsFile(configFile);

    if (bindAddress == null) {
        bindAddress = moduleManager.getVariable("bindAddress");
        if (bindAddress == null)
            bindAddress = DEFAULT_BIND_ADDRESS;
    }

    try {
        moduleManager.autostartModules();
    } catch (ModuleException me) {
        throw new ServletException("Unable to start modules.", me);
    }
}

From source file:com.iorga.iraj.servlet.AgglomeratorServlet.java

private void parseResourcesFromMappings(final ServletConfig config) throws ServletException {
    for (final String mapping : config.getServletContext().getServletRegistration(config.getServletName())
            .getMappings()) {//from w w  w .j ava  2s  .  c  o m
        try {
            parseResource(config, mapping);
        } catch (final IOException | URISyntaxException e) {
            throw new ServletException("Problem while parsing the mapping " + mapping, e);
        }
    }
}

From source file:org.n52.io.PreRenderingJob.java

@Override
public void setServletConfig(ServletConfig servletConfig) {
    webappFolder = servletConfig.getServletContext().getRealPath("/");
}

From source file:org.appcelerator.transport.ProxyTransportServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    if (this.embeddedMode) {
        AnnotationHelper.initializeAnnotationDBFromClasspath();
    } else {/*  w w w.  j  a  v  a2  s  . c o m*/
        AnnotationHelper.initializeAnnotationDBFromServlet(config.getServletContext());
    }
}

From source file:com.cyclopsgroup.waterview.servlet.WaterviewServlet.java

/**
 * Override method init in super class of MainServlet
 *
 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
 */// ww w  . j  a va  2  s. co m
public void init(ServletConfig config) throws ServletException {
    applicationBase = config.getInitParameter("application.base");

    servletConfig = config;
    String basedir = config.getServletContext().getRealPath("");
    Properties initProperties = new Properties();
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);
    Enumeration i = config.getInitParameterNames();
    while (i.hasMoreElements()) {
        String key = (String) i.nextElement();
        String value = config.getInitParameter(key);
        initProperties.setProperty(key, value);
    }
    try {
        container = new WaterviewPlexusContainer();
        serviceManager = new ServiceManagerAdapter(container);
        for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
            String initPropertyName = (String) j.next();
            container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
        }

        container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
        container.initialize();
        container.start();
    } catch (Exception e) {
        container.getLogger().fatalError("Can not start container", e);
    }
}

From source file:org.exoplatform.login.openid.OpenIDConsumerServlet.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);

    context = config.getServletContext();

    log.debug("context: " + context);

    try {//from w  w w .j  a  v a 2 s.  com
        // --- Forward proxy setup (only if needed) ---
        // ProxyProperties proxyProps = new ProxyProperties();
        // proxyProps.setProxyName("proxy.example.com");
        // proxyProps.setProxyPort(8080);
        // HttpClientFactory.setProxyProperties(proxyProps);
        this.manager = new ConsumerManager();
        manager.setAssociations(new InMemoryConsumerAssociationStore());
        manager.setNonceVerifier(new InMemoryNonceVerifier(5000));
    } catch (ConsumerException e) {
        throw new ServletException(e);
    }
}

From source file:ai.h2o.servicebuilder.MakePythonWarServlet.java

public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    try {/*www. j a v  a  2s  .c o  m*/
        servletPath = new File(servletConfig.getServletContext().getResource("/").getPath());
        logger.debug("servletPath = " + servletPath);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:org.mot.feeder.iab.MyOpenTraderFeederIAB.java

/**
 * The init class is used by the servlet, in case the app is started through Tomcat or Jersey.
 * // ww w .j a  v  a2s .  com
 * @see Servlet#init(ServletConfig)
 */
public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub

    System.out.println("Starting MyOpenTraderFeederIAB Component ...");
    logger.info("*** Initializing MyOpenTraderFeederIAB Component  ...");
    startWorkers(config.getServletContext().getRealPath("/WEB-INF/conf"), null);

}

From source file:uk.ac.cam.caret.sakai.rwiki.tool.RWikiServlet.java

public void init(ServletConfig servletConfig) throws ServletException {

    super.init(servletConfig);

    ServletContext sc = servletConfig.getServletContext();

    wac = WebApplicationContextUtils.getWebApplicationContext(sc);
    headerPreContent = servletConfig.getInitParameter("headerPreContent");
    headerScriptSource = servletConfig.getInitParameter("headerScriptSource");
    footerScript = servletConfig.getInitParameter("footerScript");
    try {/*  ww  w . java2s  . co m*/
        boolean logResponse = "true".equalsIgnoreCase(servletConfig.getInitParameter("log-response"));
        TimeLogger.setLogResponse(logResponse);
    } catch (Exception ex) {

    }
    try {
        boolean logFullResponse = "true".equalsIgnoreCase(servletConfig.getInitParameter("log-full-response"));
        TimeLogger.setLogFullResponse(logFullResponse);
    } catch (Exception ex) {

    }

    String basePath = servletConfig.getServletContext().getRealPath("/");
    dispatcher = new MapDispatcher(sc);

}