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.onebusaway.webapp.impl.WebappServiceServletImpl.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    WebApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    context.getAutowireCapableBeanFactory().autowireBean(this);
}

From source file:org.apache.jetspeed.services.resources.VariableResourcesService.java

/**
 * Initializer method that sets up the generic resources.
 *
 * @param confs A Configurations object.
 *//*from  w  w w. j  a va 2s  . c o  m*/
private void initVariables(ServletConfig config) {
    ServletContext ctxt = config.getServletContext();

    String path = ctxt.getRealPath("/");

    // define web app dir
    if (path != null) {
        variables.put(WEBAPP_DIR, normalizePath(path));
    }

    // FIXME. the following code blocks on Tomcat 
    // when loaded on startup
    /*
    path = ctxt.getContext("/").getRealPath("/");
    if (path != null ) {
    variables.put(WEB_DIR, normalizePath(path) );
    }
    */

    // define JVM app dir
    try {
        path = new File(".").getCanonicalPath();
        if (path != null) {
            variables.put(JVM_DIR, normalizePath(path));
        }
    } catch (IOException e) {
        //very unlikely that the JVM can't 
        //resolve its path
        //But logging it anyway...
        logger.error("Exception define JVM app dir", e);
    }

    // load servlet init parameters as variables, they may override
    // the previously defined variables. All param names are folded
    // to lower case

    Enumeration en = config.getInitParameterNames();
    while (en.hasMoreElements()) {
        String paramName = (String) en.nextElement();
        String paramValue = config.getInitParameter(paramName);
        variables.put(paramName.toLowerCase(), paramValue);
    }

}

From source file:org.apache.nifi.processors.standard.servlets.ListenHTTPServlet.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w.  j  av  a2s .c  om*/
public void init(final ServletConfig config) throws ServletException {
    final ServletContext context = config.getServletContext();
    this.logger = (ComponentLog) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_LOGGER);
    this.sessionFactoryHolder = (AtomicReference<ProcessSessionFactory>) context
            .getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_SESSION_FACTORY_HOLDER);
    this.processContext = (ProcessContext) context
            .getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_PROCESS_CONTEXT_HOLDER);
    this.authorizedPattern = (Pattern) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_AUTHORITY_PATTERN);
    this.headerPattern = (Pattern) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_HEADER_PATTERN);
    this.flowFileMap = (ConcurrentMap<String, FlowFileEntryTimeWrapper>) context
            .getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_FLOWFILE_MAP);
    this.streamThrottler = (StreamThrottler) context
            .getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_STREAM_THROTTLER);
    this.basePath = (String) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_BASE_PATH);
}

From source file:org.wso2.carbon.sts.ui.STSUtil.java

/**
 * Initializes STSUtil//  w w w.  ja v  a 2 s . c  o  m
 *
 * @param cookie Cookie string
 * @throws Exception
 */
public STSUtil(ServletConfig config, HttpSession session, String cookie) throws Exception {
    ServiceClient client = null;
    Options option = null;
    String serverUrl = null;

    // Obtaining the client-side ConfigurationContext instance.
    configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    // Server URL which is defined in the server.xml
    serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);

    this.serviceEndPoint = serverUrl + "STSAdminService";
    try {
        this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
    } catch (AxisFault e) {
        log.error("Error while creating STSAdminServiceStub", e);
        throw new Exception(e);
    }
    client = stub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}

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

public void init(ServletConfig config) throws ServletException {
    InputStream fis = config.getServletContext().getResourceAsStream("/WEB-INF/classes/properties.xml");
    ToolsProperties.readProperties(fis);
}

From source file:org.wso2.carbon.identity.sts.mgt.ui.client.CarbonSTSClient.java

/**
 * Initializes STSUtil//  w  ww . ja  v  a 2  s  . c  o m
 *
 * @param cookie Cookie string
 * @throws Exception
 */
public CarbonSTSClient(ServletConfig config, HttpSession session, String cookie) throws Exception {
    ServiceClient client = null;
    Options option = null;
    String serverUrl = null;

    // Obtaining the client-side ConfigurationContext instance.
    configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    // Server URL which is defined in the server.xml
    serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);

    this.serviceEndPoint = serverUrl + "STSAdminService";
    try {
        this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
    } catch (AxisFault e) {
        log.error("Error while creating STSAdminServiceStub", e);
        throw new Exception(e);
    }
    client = stub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}

From source file:org.apache.archiva.web.rss.RssFeedServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
    userRepositories = wac.getBean(UserRepositories.class);
    servletAuth = wac.getBean(ServletAuthenticator.class);
    httpAuth = wac.getBean("httpAuthenticator#basic", HttpAuthenticator.class);
    // TODO: what if there are other types?
    repositorySessionFactory = wac.getBean("repositorySessionFactory", RepositorySessionFactory.class);

    newArtifactsprocessor = wac.getBean("rssFeedProcessor#new-artifacts", RssFeedProcessor.class);
    newVersionsprocessor = wac.getBean("rssFeedProcessor#new-versions", RssFeedProcessor.class);
}

From source file:com.future.pos.util.SystemInitializer.java

/**
 * Runs during initialization of the server.<br>
 * Loads on startup. Configured in web.xml.
 *//*ww w .j a v a2 s.  c  om*/
public void init(ServletConfig config) throws ServletException {
    try {
        initializeConfigVars(config.getServletContext());
        initializeLicenses();
        initializeSecurityGroups(config.getServletContext());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.restcomm.sbc.servlet.sip.SBCRegistrarServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    if (LOG.isTraceEnabled()) {
        LOG.trace(">> init()");
    }/*from   w w w .j a va  2  s .c om*/
    super.init(servletConfig);
    sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY);
    final ServletContext context = servletConfig.getServletContext();
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    ConfigurationCache.build(sipFactory, configuration);

    mzIface = ConfigurationCache.getMzIface();
    mzIPAddress = ConfigurationCache.getMzIPAddress();
    mzTransport = ConfigurationCache.getMzTransport();
    mzPort = ConfigurationCache.getMzPort();

    dmzIface = ConfigurationCache.getDmzIface();
    dmzIPAddress = ConfigurationCache.getDmzIPAddress();
    dmzTransport = ConfigurationCache.getDmzTransport();
    dmzPort = ConfigurationCache.getDmzPort();

    routeMZIPAddress = ConfigurationCache.getRouteMZIPAddress();
    routeMZTransport = ConfigurationCache.getRouteMZTransport();
    routeMZPort = ConfigurationCache.getRouteMZPort();

    if (LOG.isDebugEnabled()) {
        LOG.debug("MZ :" + mzIface + ", " + mzIPAddress + ":" + mzPort + ", " + mzTransport);
        LOG.debug("DMZ:" + dmzIface + ", " + dmzIPAddress + ":" + dmzPort + ", " + dmzTransport);
        LOG.debug("Route MZ Target:" + routeMZIPAddress + ":" + routeMZPort + ", " + routeMZTransport);
        LOG.debug("Registration Throttling enabled:" + ConfigurationCache.isRegThrottleEnabled());
        LOG.debug("MaxUATTL:" + ConfigurationCache.getRegThrottleMaxUATTL());
        LOG.debug("MinRETTL:" + ConfigurationCache.getRegThrottleMinRegistartTTL());
    }

    upChain = new UpstreamRegistrarProcessorChain();
    LOG.info("Loading (v. " + upChain.getVersion() + ") " + upChain.getName());
    dwChain = new DownstreamRegistrarProcessorChain();
    LOG.info("Loading (v. " + dwChain.getVersion() + ") " + dwChain.getName());

}

From source file:com.alfaariss.oa.sso.web.WebSSOServlet.java

/**
 * Starts SSO profiles./*  www  .ja  v  a2s .c  om*/
 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
 */
@Override
public void init(ServletConfig oServletConfig) throws ServletException {
    try {
        _context = oServletConfig.getServletContext();

        //Retrieve configuration manager            
        IConfigurationManager config = _engine.getConfigurationManager();

        //Start profiles and helpers
        start(config, null);

        //Add as listener           
        _engine.addComponent(this);
    } catch (OAException e) {
        _logger.fatal("Error starting WebSSO", e);
        stop(); //Stop started profiles and helpers
        throw new ServletException(SystemErrors.toHexString(e.getCode()));
    } catch (Exception e) {
        _logger.fatal("Error starting WebSSO", e);
        stop(); //Stop started profiles and helpers
        throw new ServletException(SystemErrors.toHexString(SystemErrors.ERROR_INTERNAL));
    }

}