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.rabidgremlin.onepagewebstarter.guice.CxfGuiceServlet.java

@Override
protected List<Object> getProviders(ServletConfig servletConfig, String splitChar) throws ServletException {
    List<Object> providers = new ArrayList<Object>();

    String providersList = servletConfig.getInitParameter("jaxrs.providers");
    if (providersList == null) {
        return providers;
    }/*w  ww  .ja v  a  2  s. c o m*/

    Injector injector = (Injector) servletConfig.getServletContext().getAttribute(Injector.class.getName());

    String[] classNames = StringUtils.split(providersList, splitChar);
    for (String cName : classNames) {
        Class<?> cls = loadClass(StringUtils.strip(cName));
        providers.add(injector.getInstance(cls));
    }

    return providers;
}

From source file:org.apache.stratos.account.mgt.ui.clients.AccountMgtClient.java

public AccountMgtClient(ServletConfig config, HttpSession session) throws RegistryException {

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    epr = backendServerURL + "AccountMgtService";

    try {/*from w w w .jav  a  2s.c o  m*/
        stub = new AccountMgtServiceStub(configContext, epr);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    } catch (AxisFault axisFault) {
        String msg = "Failed to initiate AccountMgt service client.";
        log.error(msg, axisFault);
        throw new RegistryException(msg, axisFault);
    }
}

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

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    if (LOG.isInfoEnabled()) {
        LOG.info(">> Messenger Servlet init()");
    }/* ww  w  . j  a  va 2s .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);

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

}

From source file:org.codemine.smartgarden.controller.SmartGardenServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    try {// w  ww .j av  a2 s .c  om
        super.init(config); //To change body of generated methods, choose Tools | Templates.           
        config.getServletContext().setAttribute(SERVICE_KEY, new SmartGardenService(this.getDataSource()));
    } catch (Throwable t) {
        logger.log(Level.FATAL, "init", t);
    }
}

From source file:nijhof2axon.ui.AutowiringApplicationServlet.java

/**
 * Initialize this servlet./*from   w  w  w.  jav  a2  s  .  co m*/
 *
 * @throws ServletException if there is no {@link WebApplicationContext} associated with this servlet's context
 */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    log.debug("finding containing WebApplicationContext");
    try {
        this.webApplicationContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(config.getServletContext());
    } catch (IllegalStateException e) {
        throw new ServletException("could not locate containing WebApplicationContext");
    }
}

From source file:org.pentaho.platform.web.servlet.PentahoXmlaServlet.java

@Override
protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) {
    return new ServletContextCatalogLocator(servletConfig.getServletContext()) {
        @Override/*from  w  ww . j a  v  a 2s  . c o  m*/
        public String locate(String catalogPath) {
            if (catalogPath.startsWith("mondrian:")) { //$NON-NLS-1$
                try {
                    FileSystemManager fsManager = VFS.getManager();
                    SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager
                            .resolveFile(catalogPath);
                    catalogPath = "solution:" + catalog.getFileRef();
                } catch (FileSystemException e) {
                    logger.error(e.getMessage());
                }
            } else {
                catalogPath = super.locate(catalogPath);
            }
            return catalogPath;
        }
    };
}

From source file:org.accada.epcis.repository.capture.CaptureOperationsServlet.java

/**
 * Loads the application properties and populates a java.util.Properties
 * instance.//from w ww. j  av a  2 s  .c  o  m
 * 
 * @param servletConfig
 *            The ServletConfig used to locate the application property
 *            file.
 * @return The application properties.
 */
private Properties loadApplicationProperties(ServletConfig servletConfig) {
    // read application properties from servlet context
    ServletContext ctx = servletConfig.getServletContext();
    String path = ctx.getRealPath("/");
    String appConfigFile = ctx.getInitParameter(APP_CONFIG_LOCATION);
    Properties properties = new Properties();
    try {
        InputStream is = new FileInputStream(path + appConfigFile);
        properties.load(is);
        is.close();
        LOG.info("Loaded application properties from " + path + appConfigFile);
    } catch (IOException e) {
        LOG.error("Unable to load application properties from " + path + appConfigFile, e);
    }
    return properties;
}

From source file:org.wso2.carbon.registry.properties.ui.clients.PropertiesServiceClient.java

public PropertiesServiceClient(ServletConfig config, HttpSession session) throws RegistryException {

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    epr = backendServerURL + "PropertiesAdminService";

    try {/* w w  w.j av  a  2  s.  c o m*/
        stub = new PropertiesAdminServiceStub(configContext, epr);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    } catch (AxisFault axisFault) {
        String msg = "Failed to initiate resource service client. " + axisFault.getMessage();
        log.error(msg, axisFault);
        throw new RegistryException(msg, axisFault);
    }
}

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

public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    try {/*from   w  w w. j  a  v  a 2 s  . co m*/
        servletPath = new File(servletConfig.getServletContext().getResource("/").getPath());
        logger.info("servletPath = {}", servletPath);
    } catch (MalformedURLException e) {
        logger.error("Can't init servlet", e);
    }
}