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:org.openhab.ui.cometvisu.internal.servlet.CometVisuServlet.java

/**
 * initialize the script manager.//ww  w  .  j  av a 2 s. com
 */
@Override
public final void init(ServletConfig config) throws ServletException {
    super.init(config);
    _config = config;
    _servletContext = config.getServletContext();

    // init php service if available
    if (this.engine != null) {
        this.engine.init(rootFolder.getAbsolutePath(), defaultUserDir, _servletContext);
        phpEnabled = true;
    }
}

From source file:org.lockss.servlet.LockssServlet.java

/** Run once when servlet loaded. */
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    context = config.getServletContext();
    theApp = (LockssApp) context.getAttribute(ServletManager.CONTEXT_ATTR_LOCKSS_APP);
    servletMgr = (ServletManager) context.getAttribute(ServletManager.CONTEXT_ATTR_SERVLET_MGR);
    if (theApp instanceof LockssDaemon) {
        acctMgr = getLockssDaemon().getAccountManager();
        alertMgr = getLockssDaemon().getAlertManager();
    }//w  ww . j ava  2  s.co  m
}

From source file:org.apache.axis2.soapmonitor.servlet.SOAPMonitorService.java

/**
 * Servlet initialiation/* w w  w .j  a  v  a2  s . com*/
 */
public void init() throws ServletException {
    if (connections == null) {
        // Create vector to hold connection information
        connections = new Vector();
    }
    if (serverSocket == null) {
        // Get the server socket port from the init params
        ServletConfig config = super.getServletConfig();
        String hostName = config.getInitParameter(SOAPMonitorConstants.SOAP_MONITOR_HOST_NAME);
        String port = config.getInitParameter(SOAPMonitorConstants.SOAP_MONITOR_PORT);
        if (port == null) {
            log.error("SOAPMonitorService can't find ServletConfig init parameter 'port'");
            port = "0";
        }
        try {
            if (hostName != null) {
                serverSocket = new ServerSocket(Integer.parseInt(port), 50, InetAddress.getByName(hostName));
            } else {
                serverSocket = new ServerSocket(Integer.parseInt(port));
            }
        } catch (Exception ex) {
            // Let someone know we could not open the socket
            log.error("Unable to open server socket using port: " + port);
            log.error(ex.getMessage(), ex);
            // Fail as loudly as possible for those without logging configured
            config.getServletContext().log("Unable to open server socket using port " + port + ":", ex);
            serverSocket = null;
        }
        if (serverSocket != null) {
            // Start the server socket thread
            new Thread(new ServerSocketThread()).start();
        }
    }
}

From source file:org.apache.axis2.transport.http.AxisServlet.java

/**
 * Main init method// w w w.  java2  s.com
 *
 * @param config The ServletConfig
 * @throws ServletException
 */
@Override
public void init(ServletConfig config) throws ServletException {

    // prevent this method from being called more than once per instance
    initCalled = true;
    super.init(config);
    try {
        this.servletConfig = config;
        ServletContext servletContext = servletConfig.getServletContext();
        this.configContext = (ConfigurationContext) servletContext.getAttribute(CONFIGURATION_CONTEXT);
        if (configContext == null) {
            configContext = initConfigContext(config);
            config.getServletContext().setAttribute(CONFIGURATION_CONTEXT, configContext);
        }
        axisConfiguration = configContext.getAxisConfiguration();
        initTransports();
        initGetRequestProcessors(config);
        initParams();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:org.kurento.repository.internal.http.RepositoryHttpServlet.java

private String configureServletMapping(ServletConfig servletConfig) {
    Collection<String> mappings = servletConfig.getServletContext()
            .getServletRegistration(servletConfig.getServletName()).getMappings();

    if (mappings.isEmpty()) {
        throw new KurentoException("There is no mapping for servlet " + RepositoryHttpServlet.class.getName());
    }//from   www  .  java 2 s.c o  m

    String mapping = mappings.iterator().next();

    // TODO: Document this. We assume a mapping starting with / and ending
    // with /*
    mapping = mapping.substring(0, mapping.length() - 1);

    repoHttpManager.setServletPath(mapping);

    return mapping;
}

From source file:com.ibm.jaggr.service.impl.AggregatorImpl.java

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

    final ServletContext context = servletConfig.getServletContext();

    // Set servlet context attributes for access though the request
    context.setAttribute(IAggregator.AGGREGATOR_REQATTRNAME, this);
}

From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    // get init param
    servletConfig = config;//from   w  w w. j  a v  a2s.c o  m
    parameterName = config.getInitParameter("parameterName");
    forwardPathUpload = config.getInitParameter("forwardPathUpload");
    forwardPathDownload = config.getInitParameter("forwardPathDownload");
    forwardPathList = config.getInitParameter("forwardPathList");
    forwardPathRead = config.getInitParameter("forwardPathRead");
    forwardPathDelete = config.getInitParameter("forwardPathDelete");

    // set service
    WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());

    PropertiesService propertiesService = (PropertiesService) ctx.getBean("propertiesService");

    // overwrite configuration
    characterEncoding = propertiesService.getString("file.default.character.encoding", characterEncoding);
    sizeThreshold = propertiesService.getInt("file.default.file.size.threshold", sizeThreshold);
    fileSizeMax = propertiesService.getLong("file.default.file.size.max", fileSizeMax);
    requestSizeMax = propertiesService.getLong("file.default.request.size.max", requestSizeMax);
    realRepositoryPath = propertiesService.getString("file.default.real.repository.path", realRepositoryPath);
    tempRepositoryPath = propertiesService.getString("file.default.temp.repository.path", tempRepositoryPath);
    repositoryType = RepositoryType.valueOf(
            propertiesService.getString("file.default.real.repository.type", repositoryType.toString()));
    // mkdirs
    File file = new File(realRepositoryPath);
    if (!file.exists()) {
        try {
            FileUtils.forceMkdir(file);
        } catch (IOException e) {
            StringBuilder sb = new StringBuilder();
            sb.append("Cannot make directory: ");
            sb.append(file.toString());
            logger.error(sb.toString());
            throw new ServletException(sb.toString());
        }
    }
    file = new File(tempRepositoryPath);
    if (!file.exists()) {
        try {
            FileUtils.forceMkdir(file);
        } catch (IOException e) {
            StringBuilder sb = new StringBuilder();
            sb.append("Cannot make directory: ");
            sb.append(file.toString());
            logger.error(sb.toString());
            throw new ServletException(sb.toString());
        }
    }

}

From source file:org.openhab.ui.cometvisu.servlet.CometVisuServlet.java

/**
 * initialize the script manager./*from  w  w w .  ja  va2s.c  o m*/
 */
@Override
public final void init(ServletConfig config) throws ServletException {
    super.init(config);
    _config = config;
    _servletContext = config.getServletContext();

    checkServletAPIVersion();

    // Path pwd = new FilePath(_servletContext.getRealPath("/"));
    Path pwd = new FilePath(rootFolder.getAbsolutePath());
    Path webInfDir = pwd;

    logger.info("initial pwd " + pwd);
    logger.info("initial webinf " + webInfDir);
    engine.getQuercus().setPwd(pwd);
    engine.getQuercus().setWebInfDir(webInfDir);

    // need to set these for non-Resin containers
    if (!CurrentTime.isTest() && !engine.getQuercus().isResin()) {
        Vfs.setPwd(pwd);
        WorkDir.setLocalWorkDir(webInfDir.lookup("work"));
    }
    engine.getQuercus().init();
    engine.getQuercus().start();
}

From source file:dk.clarin.tools.create.java

public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException {
    logger.debug("init tools servlet");
    InputStream fis = config.getServletContext().getResourceAsStream("/WEB-INF/classes/properties.xml");
    ToolsProperties.readProperties(fis);
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    date = sdf.format(cal.getTime());/*from  w ww .ja va2  s.c o  m*/
    BracMat = new bracmat(ToolsProperties.bootBracmat);
    //toolsdataURL = ToolsProperties.baseUrlTools + ToolsProperties.stagingArea;
    super.init(config);
    destinationDir = new File(ToolsProperties.documentRoot /*+ ToolsProperties.stagingArea*/);
    if (!destinationDir.isDirectory()) {
        try {
            destinationDir.mkdir();
        } catch (Exception e) {
            throw new ServletException("Trying to create \""
                    + ToolsProperties.documentRoot /*+ ToolsProperties.stagingArea*/
                    + "\" as directory for temporary storing intermediate and final results, but this is not a valid directory. Error:"
                    + e.getMessage());
        }
    }
    if (!destinationDir.isDirectory()) {
        throw new ServletException("Trying to set \""
                + ToolsProperties.documentRoot /*+ ToolsProperties.stagingArea*/
                + "\" as directory for temporary storing intermediate and final results, but this is not a valid directory.");
    }
    // Ready the Document builder
    try {
        builder = factory.newDocumentBuilder();
    } catch (javax.xml.parsers.ParserConfigurationException e) {
        logger.error("ParserConfigurationException during creation of DocumentBuilder");
    }
}