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.wso2.carbon.sequences.ui.client.SequenceAdminClient.java

public SequenceAdminClient(ServletConfig config, HttpSession session) throws AxisFault {

    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String serviceURL = backendServerURL + "SequenceAdminService";
    sequenceAdminStub = new SequenceAdminServiceStub(configContext, serviceURL);
    ServiceClient client = sequenceAdminStub._getServiceClient();
    Options option = client.getOptions();
    option.setManageSession(true);/*  ww  w  . ja va  2s.c  o  m*/
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}

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

@Override
protected void loadBus(ServletConfig servletConfig) {
    super.loadBus(servletConfig);

    CmisServiceFactory factory = CmisRepositoryContextListener
            .getServiceFactory(servletConfig.getServletContext());

    if (factory == null) {
        throw new CmisRuntimeException("Service factory not available! Configuration problem?");
    }/* w  ww  .j  av  a  2s .  c  o m*/

    Bus bus = getBus();
    BusFactory.setDefaultBus(bus);

    if (factory.getTempDirectory() != null) {
        bus.setProperty("bus.io.CachedOutputStream.OutputDirectory",
                factory.getTempDirectory().getAbsolutePath());
    }
    if (factory.getMemoryThreshold() >= 0) {
        bus.setProperty("bus.io.CachedOutputStream.Threshold", String.valueOf(factory.getMemoryThreshold()));
    }
    bus.setProperty("bus.io.CachedOutputStream.MaxSize", "-1");
    if (factory.encryptTempFiles()) {
        bus.setProperty("bus.io.CachedOutputStream.CipherTransformation", "AES/CTR/PKCS5Padding");
    }

    configureInterceptors(bus);

    if (cmisVersion == CmisVersion.CMIS_1_0) {
        publish("/RepositoryService", new RepositoryService10());
        publish("/NavigationService", new NavigationService());
        publish("/ObjectService", new ObjectService10());
        publish("/VersioningService", new VersioningService());
        publish("/RelationshipService", new RelationshipService());
        publish("/DiscoveryService", new DiscoveryService());
        publish("/MultiFilingService", new MultiFilingService());
        publish("/ACLService", new AclService());
        publish("/PolicyService", new PolicyService());
    } else {
        publish("/RepositoryService", new RepositoryService());
        publish("/NavigationService", new NavigationService());
        publish("/ObjectService", new ObjectService());
        publish("/VersioningService", new VersioningService());
        publish("/RelationshipService", new RelationshipService());
        publish("/DiscoveryService", new DiscoveryService());
        publish("/MultiFilingService", new MultiFilingService());
        publish("/ACLService", new AclService());
        publish("/PolicyService", new PolicyService());
    }
}

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

/**
 * Retrieves role name and monitor server reference from servlet context.
 *
 * @param servletConfig//from ww w.  j  a  v  a 2 s. co m
 * @throws ServletException
 */
@Override
public synchronized void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig); // Overridden method
    final ServletContext servletContext = servletConfig.getServletContext();
    moniServer = (GroovyMoniServer) servletContext.getAttribute(GroovyMoniServer.ATTR_MONITOR_SERVER);
    roleName = (String) servletContext.getAttribute(GroovyMoniServer.ATTR_ROLE_NAME);
}

From source file:org.glom.web.server.OnlineGlomServlet.java

protected UserStore getUserStore() {
    //See if there is already a shared userstore
    final ServletConfig config = this.getServletConfig();
    if (config == null) {
        Log.error("getServletConfig() return null");
        return null;
    }//w  ww  .  j  a v  a2 s. c  o m

    final ServletContext context = config.getServletContext();
    if (context == null) {
        Log.error("getServletContext() return null");
        return null;
    }

    //Use the existing shared document set, if any:
    final Object object = context.getAttribute(USER_STORE);
    if ((object != null) && !(object instanceof UserStore)) {
        Log.error("The configuredDocumentSet attribute is not of the expected type.");
        return null;
    }

    UserStore userStore = (UserStore) object;
    if (userStore != null) {
        return userStore;
    }

    //Create the shared userstore
    //TODO: Possible race condition between checking and creating+setting:
    userStore = new UserStore();

    //Store it in the Servlet Context,
    //so it is available to all servlets:
    context.setAttribute(USER_STORE, userStore);

    return userStore;
}

From source file:org.hippoecm.repository.PingServlet.java

private String getParameter(ServletConfig config, String paramName, String defaultValue) {
    String initValue = config.getInitParameter(paramName);
    String contextValue = config.getServletContext().getInitParameter(paramName);
    if (isNotNullAndNotEmpty(initValue)) {
        return initValue;
    } else if (isNotNullAndNotEmpty(contextValue)) {
        return contextValue;
    } else {//from   w w w  . ja  v a 2s  . c o  m
        return defaultValue;
    }
}

From source file:org.glom.web.server.OnlineGlomServlet.java

protected ConfiguredDocumentSet getConfiguredDocumentSet() {
    //See if there is already a shared documentSet:
    final ServletConfig config = this.getServletConfig();
    if (config == null) {
        Log.error("getServletConfig() return null");
        return null;
    }/*w w  w .  j  av  a 2s .  com*/

    final ServletContext context = config.getServletContext();
    if (context == null) {
        Log.error("getServletContext() return null");
        return null;
    }

    //Use the existing shared document set, if any:
    final Object object = context.getAttribute(CONFIGURED_DOCUMENT_SET);
    if ((object != null) && !(object instanceof ConfiguredDocumentSet)) {
        Log.error("The configuredDocumentSet attribute is not of the expected type.");
        return null;
    }

    ConfiguredDocumentSet configuredDocumentSet = (ConfiguredDocumentSet) object;
    if (configuredDocumentSet != null) {
        return configuredDocumentSet;
    }

    //Create the shared document set:
    //TODO: Possible race condition between checking and creating+setting:
    configuredDocumentSet = new ConfiguredDocumentSet();
    try {
        configuredDocumentSet.readConfiguration();
    } catch (ServletException e) {
        Log.error("Configuration error", e);
        return null;
    }

    //Store it in the Servlet Context,
    //so it is available to all servlets:
    context.setAttribute(CONFIGURED_DOCUMENT_SET, configuredDocumentSet);

    return configuredDocumentSet;
}

From source file:org.ireland.jnetty.jsp.JspServletComposite.java

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

    super.init(config);
    this.config = config;
    this.context = config.getServletContext();

    //JSPServletContext
    Thread.currentThread().setContextClassLoader(context.getClassLoader());

    // Initialize the JSP Runtime Context
    // Check for a custom Options implementation
    String engineOptionsName = config.getInitParameter("engineOptionsClass"); //
    if (engineOptionsName != null) {
        // Instantiate the indicated Options implementation
        try {/*  ww  w  .  java  2s .  c o  m*/
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class<?> engineOptionsClass = loader.loadClass(engineOptionsName);
            Class<?>[] ctorSig = { ServletConfig.class, ServletContext.class };
            Constructor<?> ctor = engineOptionsClass.getConstructor(ctorSig);
            Object[] args = { config, context };
            options = (Options) ctor.newInstance(args);
        } catch (Throwable e) {
            e = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(e);
            // Need to localize this.
            log.warn("Failed to load engineOptionsClass", e);
            // Use the default Options implementation
            options = new EmbeddedServletOptions(config, context);
        }
    } else {
        // Use the default Options implementation
        options = new EmbeddedServletOptions(config, context);
    }

    rctxt = new JspRuntimeContext(context, options);

    if (debug) {
        log.debug(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString()));
        log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
    }
}

From source file:org.apache.stratos.theme.mgt.ui.clients.ThemeMgtServiceClient.java

public ThemeMgtServiceClient(String cookie, ServletConfig config, HttpSession session)
        throws RegistryException {

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

    try {//from www .  j  a va  2 s . c o  m
        stub = new ThemeMgtServiceStub(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:org.wso2.carbon.registry.security.vault.ui.PropertiesServiceClient.java

public PropertiesServiceClient(ServletConfig config, HttpSession session) throws RegistryException {
    this.session = session;
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), this.session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String propertyEPR = backendServerURL + "PropertiesAdminService";
    String registrySecurityEPR = backendServerURL + "RegistrySecurityAdminService";

    try {//from   w  ww  . j  a  v a2 s  .co m
        propertAdminServicestub = new PropertiesAdminServiceStub(configContext, propertyEPR);

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

        //
        securityAdminServiceStub = new RegistrySecurityAdminServiceStub(configContext, registrySecurityEPR);

        ServiceClient securityclient = propertAdminServicestub._getServiceClient();
        Options securityoption = securityclient.getOptions();
        securityoption.setManageSession(true);
        securityoption.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

        cipherTool = new CipherTool(securityAdminServiceStub);
    } 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:de.micromata.genome.gwiki.web.GWikiServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    servletPath = config.getInitParameter("servletPath");
    contextPath = config.getInitParameter("contextPath");
    if (contextPath == null) {
        contextPath = config.getServletContext().getContextPath();
    }//from  ww w . j  a v  a 2s  .com
    if (daoContext == null) {
        String className = config.getInitParameter(
                "de.micromata.genome.gwiki.model.config.GWikiBootstrapConfigLoader.className");
        if (StringUtils.isBlank(className) == true) {
            throw new ServletException(
                    "de.micromata.genome.gwiki.model.config.GWikiBootstrapConfigLoader.className is not set in ServletConfig for GWikiServlet");
        }
        GWikiBootstrapConfigLoader loader = ClassUtils.createDefaultInstance(className,
                GWikiBootstrapConfigLoader.class);
        daoContext = loader.loadConfig(config);
    }
}