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:be.fedict.eid.dss.webapp.AbstractProtocolServiceServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    /*/* w  ww .  java2  s  .  c om*/
     * We align the life-cycle of a DSSProtocolService and
     * DSSDocumentService with the life-cycle of this servlet.
     */
    ServletContext servletContext = config.getServletContext();

    initializeProtocolServices(servletContext);

    initializeDocumentServices(servletContext);
}

From source file:net.unicon.academus.spell.SpellCheckerServlet.java

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

    ctx = config.getServletContext();

    lang = getParam(config, "lang", lang);
    aspell_loc = getParam(config, "aspell", aspell_loc);
    known_good = getParam(config, "known-good", known_good);

    try {/*from w  w  w  .j  a  v  a2  s  .co  m*/
        hasHTMLFilter = checkHTMLFilter();
    } catch (Exception ex) {
        log.warn("Unable to verify Aspell HTML Filter support", ex);
        hasHTMLFilter = false;
    }

    header_resource = getParam(config, "header", header_resource);
    footer_resource = getParam(config, "footer", footer_resource);

    log.info("SpellCheckerServlet initialized.");
}

From source file:org.apereo.portal.portlet.container.services.LocalPortletContextManager.java

/**
 * Retrieves the PortletContext associated with the given ServletContext.
 * If one does not exist, it is created.
 *
 * @param config the servlet config.//from ww  w. j  a  va  2s .c  o  m
 * @return the InternalPortletContext associated with the ServletContext.
 * @throws PortletContainerException
 */
@Override
public synchronized String register(ServletConfig config) throws PortletContainerException {
    ServletContext servletContext = config.getServletContext();
    String contextPath = servletContext.getContextPath();
    if (!portletContexts.containsKey(contextPath)) {

        PortletApplicationDefinition portletApp = this.getPortletAppDD(servletContext, contextPath,
                contextPath);

        DriverPortletContext portletContext = new DriverPortletContextImpl(servletContext, portletApp,
                requestDispatcherService);

        portletContext.setAttribute(PlatformApiBroker.PORTLET_CONTEXT_ATTRIBUTE_NAME, platformApiBroker);
        portletContexts.put(contextPath, portletContext);

        fireRegistered(portletContext);

        if (logger.isInfoEnabled()) {
            logger.info("Registered portlet application for context '" + contextPath + "'");

            logger.info("Registering " + portletApp.getPortlets().size() + " portlets for context "
                    + portletContext.getApplicationName());
        }

        //TODO have the portlet servlet provide the portlet's classloader as parameter to this method
        //This approach is needed as all pluto callbacks in uPortal have an aspect that switches the thread classloader back
        //to uPortal's classloader.
        ClassLoader classLoader = ThreadContextClassLoaderAspect.getPreviousClassLoader();
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        classLoaders.put(portletApp.getName(), classLoader);
        for (PortletDefinition portlet : portletApp.getPortlets()) {
            String appName = portletContext.getApplicationName();
            if (appName == null) {
                throw new PortletContainerException("Portlet application name should not be null.");
            }
            portletConfigs.put(portletContext.getApplicationName() + "/" + portlet.getPortletName(),
                    new DriverPortletConfigImpl(portletContext, portlet));
        }
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Portlet application for context '" + contextPath + "' already registered.");
        }
    }
    return contextPath;
}

From source file:com.qualogy.qafe.webservice.servlet.GenericWebServiceServlet.java

/**
 * Retrieves interface- and implementation class-names out of web.xml context parameter prefixed with "webservice." to add them as 
 * webservices to the the WebServiceServer
 * /*from   www.ja va  2  s .c o m*/
 * @param   servletConfig  The ServletConfig of the webapplication
 * @see      WebServiceServer
 */
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException {
    super.loadBus(servletConfig);

    // sets the busfactory needed to link the webapp url to the webservice
    System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, "org.apache.cxf.bus.CXFBusFactory");

    Map<String, String> webservices = extractWebservices(servletConfig.getServletContext());

    Bus bus = this.getBus();
    BusFactory.setDefaultBus(bus);
    try {
        GenericWebServiceServer webServiceServer = createNewWebServiceServer(bus);
        //           for(String serviceInterface : webservices.keySet()) {
        //               webServiceServer.addService(serviceInterface, webservices.get(serviceInterface));             
        //           }
        String webServiceInterface = webServiceServer.getInterface();
        String webServiceImplementation = webServiceServer.getImplementation();
        webServiceServer.addService(webServiceInterface, webServiceImplementation);
    } catch (Exception e) {
        logger.error("Error adding webservices", e);
        throw new ServletException("Error adding webservices", e);
    }
}

From source file:ro.cs.om.start.InitApplication.java

/**
 * Initializarea contextului. Aici se preiau nomenclatoarele ce se vor
 * pastra in OMContext// w ww. ja v a 2  s.  co m
 */
public void init(ServletConfig conf) throws ServletException {
    logger.info("Initializare aplicatie...");
    try {

        ServletContext sc = conf.getServletContext();
        logger.info("*******************************************************");
        logger.info("*                                                     *");
        logger.info("*    ORGANISATION MANAGEMENT INITIALISATION: BEGIN    *");
        logger.info("*                                                     *");
        logger.info("*******************************************************");
        logger.info(IConstant.APP_VERSION.concat("/").concat(IConstant.APP_RELEASE_DATE));
        sc.setAttribute("VERSION", IConstant.APP_VERSION);
        sc.setAttribute("RELEASE_DATE", IConstant.APP_RELEASE_DATE);
        sc.setAttribute("RELEASE_YEAR", IConstant.APP_RELEASE_YEAR);

        //CLASSIFIED LISTS
        ListLoader.getInstance().load_nom_module();
        ListLoader.getInstance().load_nom_resultsPerPage();
        ListLoader.getInstance().load_nom_organisationType();
        ListLoader.getInstance().load_nom_group_companies_Type();

        RoleVoter rv = (RoleVoter) OMContext.getApplicationContext().getBean("roleVoter");

        // put permissionConstant bean on servletContext
        sc.setAttribute(IConstant.PERMISSION_CONSTANT, PermissionConstant.getInstance());

        // put exceptionContant bean on servletContect
        sc.setAttribute(IConstant.EXCEPTION_CONSTANT, ExceptionConstant.getInstance());

        // put backConstant on bean on servletContext
        sc.setAttribute(IConstant.BACK_CONSTANT, BackConstant.getInstance());

        // Set on App Context all Organizations' trees
        OMContext.storeOnContext(IConstant.ORGANISATION_TREES,
                BLOrganisationStructure.getInstance().getAllOrganisationTrees());

        //Set on App Context a map specifying which organisation has the audit module
        OMContext.storeOnContext(IConstant.HAS_AUDIT_CONTEXT_MAP, composeHasAuditContextMap());

        // Set up the security context for cross modules authentication and authorization
        OMContext.storeOnContext(IConstant.SECURITY_TOKEN_REPOSITORY, new ConcurrentHashMap<String, Token>());
        SecurityTokenMonitor.getInstance().start();
        logger.debug("Cross modules security context initialized!");

        // initialize scheduler
        initScheduler(true);

        if (isTrialVersion) {
            // manage the trial version timing
            manageTrial();
        }

        // manage the ooo profiles
        manageOOO();

        logger.info("Role Prefix: \"" + rv.getRolePrefix() + "\"");
        logger.info("*******************************************************");
        logger.info("*                                                     *");
        logger.info("*    ORGANISATION MANAGEMENT INITIALISATION: END      *");
        logger.info("*                                                     *");
        logger.info("*******************************************************");

    } catch (Exception ex) {
        logger.info("*******************************************************");
        logger.info("*     EROARE LA INTIALIZAREA APLICATIEI !!!           *");
        logger.info("*******************************************************");
        logger.error("", ex);
    }
    logger.info("Aplicatia a fost initializata...");
}

From source file:org.amplafi.jawr.maven.JawrMojo.java

private void setupJawrConfig(ServletConfig config, ServletContext context, final Map<String, Object> attributes,
        final Response respData) {
    expect(config.getServletContext()).andReturn(context).anyTimes();
    expect(config.getServletName()).andReturn("maven-jawr-plugin").anyTimes();

    context.log(isA(String.class));
    expectLastCall().anyTimes();/*from  www. ja va  2  s .  c  o m*/

    expect(context.getResourcePaths(isA(String.class))).andAnswer(new IAnswer<Set>() {

        public Set<String> answer() throws Throwable {
            final Set<String> set = new HashSet<String>();

            // hack to disallow orphan bundles
            Exception e = new Exception();
            for (StackTraceElement trace : e.getStackTrace()) {
                if (trace.getClassName().endsWith("OrphanResourceBundlesMapper")) {
                    return set;
                }
            }

            String path = (String) EasyMock.getCurrentArguments()[0];
            File file = new File(getRootPath() + path);

            if (file.exists() && file.isDirectory()) {
                for (String one : file.list()) {
                    set.add(path + one);
                }
            }

            return set;
        }

    }).anyTimes();

    expect(context.getResourceAsStream(isA(String.class))).andAnswer(new IAnswer<InputStream>() {

        public InputStream answer() throws Throwable {
            String path = (String) EasyMock.getCurrentArguments()[0];
            File file = new File(getRootPath(), path);
            return new FileInputStream(file);
        }

    }).anyTimes();

    expect(context.getAttribute(isA(String.class))).andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            return attributes.get(EasyMock.getCurrentArguments()[0]);
        }

    }).anyTimes();

    context.setAttribute(isA(String.class), isA(Object.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            String key = (String) EasyMock.getCurrentArguments()[0];
            Object value = EasyMock.getCurrentArguments()[1];
            attributes.put(key, value);
            return null;
        }

    }).anyTimes();

    expect(config.getInitParameterNames()).andReturn(new Enumeration<String>() {

        public boolean hasMoreElements() {
            return false;
        }

        public String nextElement() {
            return null;
        }

    }).anyTimes();

    expect(config.getInitParameter(JawrConstant.TYPE_INIT_PARAMETER)).andAnswer(new IAnswer<String>() {
        public String answer() throws Throwable {
            return respData == null ? null : respData.getType();
        }
    }).anyTimes();

    expect(config.getInitParameter("configLocation")).andReturn(getConfigLocation()).anyTimes();
    expect(config.getInitParameter("configPropertiesSourceClass")).andReturn(null).anyTimes();
}

From source file:org.fusesource.cloudmix.agent.webapp.GridAgentWebapp.java

public void init(ServletConfig config) throws ServletException {

    LOGGER.debug("---------------------------------------------");
    LOGGER.debug("Initializing Grid Agent");

    LOGGER.info("initialising agent");
    try {/*from  ww  w .ja v  a 2 s. c  o m*/

        servletName = config.getServletContext().getServletContextName();
        serverName = config.getServletContext().getServerInfo();

        LOGGER.debug("\nConfiguration:\n");
        LOGGER.debug("  Name:              " + agent.getAgentName());
        LOGGER.debug("  ID:                " + agent.getAgentId());
        LOGGER.debug("  Profile:           " + agent.getProfile());
        LOGGER.debug("  Properties File:   " + agent.getDetailsPropertyFilePath());
        LOGGER.debug("  Max Features:      " + agent.getMaxFeatures());
        LOGGER.debug("  Link:              " + agent.getAgentLink());
        LOGGER.debug("  Package Types:     " + getAgentPackageTypes());
        LOGGER.debug("  Type:              " + agent.getContainerType());
        LOGGER.debug("  Install Directory: " + agent.getInstallDirectory());
        LOGGER.debug("  Repository URI:    " + gridClient.getRootUri());
        LOGGER.debug("  Agent Username:    " + gridClient.getUsername());
        LOGGER.debug("  Password Provider: " + gridClient.getPasswordProvider().getClass().getSimpleName());
        LOGGER.debug("  Polling Dealay:    " + poller.getInitialPollingDelay());
        LOGGER.debug("  Polling Period:    " + poller.getPollingPeriod());

        LOGGER.debug("\nGrid Agent Ready");
        LOGGER.debug("---------------------------------------------");
        LOGGER.debug("\n");
        //poller.start();

    } catch (Exception e) {
        LOGGER.error("Excepton " + e, e);
    }

}

From source file:org.wso2.carbon.governance.gadgets.ui.ProjectDataProcessor.java

public ProjectDataProcessor(HttpServletRequest request, ServletConfig config) {
    HttpSession session = request.getSession();
    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);
    try {/*w  w  w.ja  va 2s.  com*/
        this.registry = GovernanceUtils.getGovernanceUserRegistry(
                new WSRegistryServiceClient(backendServerURL, cookie),
                (String) session.getAttribute("logged-user"));
    } catch (RegistryException e) {
        log.error("Unable to obtain an instance of the registry.", e);
    }
    try {
        this.userManager = new UserAdminClient(cookie, backendServerURL, configContext);
    } catch (Exception e) {
        log.error("Unable to create connection to User Manager", e);
    }
}

From source file:org.wso2.carbon.governance.samples.shutterbug.ui.ShutterbugAdminClient.java

public ShutterbugAdminClient(ServletConfig config, HttpSession session) throws RegistryException {
    this.config = config;
    this.session = session;
    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);
    String epr = backendServerURL + "ShutterbugAdminService";

    try {//from   w  ww . jav  a2  s. co m
        stub = new ShutterbugAdminServiceStub(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);
    }
}