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.mobicents.servlet.sip.restcomm.callmanager.gateway.SipGatewayManager.java

@Override
public void init(ServletConfig config) throws ServletException {
    logger.info("initializing ServletConfig:" + config + " ServletName:" + config.getServletName()
            + " InitParameterNames:" + config.getInitParameterNames());
    this.config = config;
    final ServletContext context = config.getServletContext();
    final ServiceLocator services = ServiceLocator.getInstance();
    //      daos = services.get(DaoManager.class);
    //                logger.info("getGatewaysDao:"+daos.getGatewaysDao());
    //      gateways = daos.getGatewaysDao().getGateways();
    clock = (TimerService) config.getServletContext().getAttribute(TIMER_SERVICE);
    sipFactory = (SipFactory) context.getAttribute(SIP_FACTORY);
    final TimerManager timers = services.get(TimerManager.class);
    try {/*from   ww  w  .ja va 2 s .c  om*/
        final SipGatewayManagerTimerListener listener = new SipGatewayManagerTimerListener();
        if (!timers.isRegistered("REGISTER")) {
            timers.register("REGISTER", listener);
        }
    } catch (final TooManyListenersException ignored) {
    }
}

From source file:gov.nih.nci.system.web.HTTPQuery.java

/**
 * Initialize the servlet//from w w w  . j  a  va  2s .  com
 */
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ServletContext context = config.getServletContext();

    ctx = WebApplicationContextUtils.getWebApplicationContext(context);
    Properties systemProperties = (Properties) ctx.getBean("WebSystemProperties");

    cacoreStyleSheet = systemProperties.getProperty("resultOutputFormatter");
    jsonStyleSheet = systemProperties.getProperty("jsonOutputFormatter");
    log.debug("cacoreStylesheet: " + cacoreStyleSheet);
    log.debug("jsonStyleSheet: " + jsonStyleSheet);

    try {
        String pageCount = systemProperties.getProperty("rowCounter");
        log.debug("rowCounter: " + pageCount);
        if (pageCount != null) {
            pageSize = Integer.parseInt(pageCount);
        }
    } catch (Exception ex) {
        log.error("Exception: ", ex);
    }
}

From source file:org.wso2.carbon.mediation.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 mediationSecurityEPR = backendServerURL + "MediationSecurityAdminService";

    try {//from   w  ww. j  av a 2 s  . c om
        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 MediationSecurityAdminServiceStub(configContext, mediationSecurityEPR);

        ServiceClient securityclient = securityAdminServiceStub._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:ume.pareva.it.servlets.TerminateBulkIT.java

/**
 * This method is needed to support Autowired Spring beans
 *///from w  w  w  . java2s  . c o m
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
}

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

/**
 * Initializarea contextului. Aici se preiau nomenclatoarele ce se vor
 * pastra pe sesiune//from  w w w .j  a  v a2  s  .  com
 */
public void init(ServletConfig conf) throws ServletException {
    logger.info("Initializare aplicatie...");
    try {

        ServletContext sc = conf.getServletContext();
        logger.info("*******************************************************");
        logger.info("*                                                     *");
        logger.info("*    INITIATING APPLICATION CLIENT MANAGEMENT->       *");
        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);

        //Nomenclators 
        ListLoader.getInstance().load_nom_resultsPerPage();

        // PROJECT
        ListLoader.getInstance().load_nom_projectStatus();

        // PROJECT TEAM
        ListLoader.getInstance().load_nom_projectTeamStatus();

        // TEAM MEMBER
        ListLoader.getInstance().load_nom_teamMemberStatus();

        // CLIENT
        ListLoader.getInstance().load_nom_clientType();
        ListLoader.getInstance().load_nom_clientStatus();

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

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

        // initialize scheduler
        initScheduler(true);

        // job for deleting project details
        deleteProjectDetailJob();

        // job for finishing project details
        finishProjectDetailJob();

        // job for aborting project details
        abortProjectDetailJob();

        // open for opening project details
        openProjectDetailJob();

        // job for deleting team member details
        deleteTeamMemberDetailJob();

        logger.info("Role Prefix: \"" + rv.getRolePrefix() + "\"");
        logger.info("*******************************************************");
        logger.info("*                                                     *");
        logger.info("*   INITIATING APPLICATION END CLIENT MANAGEMENT<-    *");
        logger.info("*                                                     *");
        logger.info("*******************************************************");

    } catch (Exception ex) {
        logger.info("*******************************************************");
        logger.info("*                                                     *");
        logger.info("*        ERROR INITIATING APPLICATION!!!              *");
        logger.info("*                                                     *");
        logger.info("*******************************************************");
        logger.error("", ex);
    }
    logger.info("The application was initiated!");
}

From source file:org.sakaiproject.search.tool.ControllerServlet2.java

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

    ServletContext sc = servletConfig.getServletContext();

    wac = WebApplicationContextUtils.getWebApplicationContext(sc);
    if (wac == null) {
        throw new ServletException("Unable to get WebApplicationContext ");
    }//from www  . ja  v  a  2  s.c o m
    searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory");
    if (searchBeanFactory == null) {
        throw new ServletException("Unable to get search-searchBeanFactory ");
    }
    sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName());
    if (sessionManager == null) {
        throw new ServletException("Unable to get " + SessionManager.class.getName());
    }

    ServerConfigurationService serverConfigurationService = (ServerConfigurationService) wac
            .getBean(ServerConfigurationService.class.getName());
    if (serverConfigurationService == null) {
        throw new ServletException("Unable to get " + ServerConfigurationService.class.getName());
    }
    serverUrl = serverConfigurationService.getServerUrl();

    searchBeanFactory.setContext(sc);

    inlineMacros = MACROS;
    InputStream is = null;
    try {
        vengine = new VelocityEngine();

        vengine.setApplicationAttribute(ServletContext.class.getName(), sc);

        Properties p = new Properties();
        is = this.getClass().getResourceAsStream("searchvelocity.config");
        p.load(is);
        vengine.init(p);
        vengine.getTemplate(inlineMacros);

    } catch (Exception ex) {
        throw new ServletException(ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                log.debug("exception thrown in Finally block");
            }
        }
    }
    contentTypes.put("opensearch", "application/opensearchdescription+xml");
    contentTypes.put("sakai.src", "application/opensearchdescription+xml");
    contentTypes.put("rss20", "text/xml");
}

From source file:com.murrayc.murraycgwtpexample.server.ThingServiceImpl.java

private Things getThings() {
    if (things != null) {
        return things;
    }//ww  w  .j a  va  2 s  . c  om

    final ServletConfig config = this.getServletConfig();
    if (config == null) {
        Log.error("getServletConfig() return null");
        return null;
    }

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

    //Use the existing shared things if any:
    final Object object = context.getAttribute(LOADED_THINGS);
    if ((object != null) && !(object instanceof Things)) {
        Log.error("The loaded-things attribute is not of the expected type.");
        return null;
    }

    things = (Things) object;
    if (things != null) {
        return things;
    }

    //Load it for the first time:
    try {
        things = loadThings();
    } catch (final Exception e) {
        e.printStackTrace();
        return null;
    }

    context.setAttribute(LOADED_THINGS, things);

    return things;
}

From source file:org.displaytag.properties.DisplayPropertiesLoaderServlet.java

/**
 * Init: retrieve the confiuration parameter and set the user file name in
 * <code>org.displaytag.tags.TableProperties</code>.
 * @param servletConfig ServletConfig/*  www.  j  a  v a  2s  .  c  o  m*/
 * @throws ServletException generic exception
 * @see javax.servlet.Servlet#init(ServletConfig)
 */
public final void init(ServletConfig servletConfig) throws ServletException {

    super.init(servletConfig);

    // read the parameter
    String file = getInitParameter(PROPERTIES_PARAMETER);

    // debug parameter
    if (log.isDebugEnabled()) {
        log.debug(PROPERTIES_PARAMETER + '=' + file);
    }

    if (file != null) {
        InputStream propStream = servletConfig.getServletContext().getResourceAsStream(file);
        if (propStream == null) {
            log.warn("unable to find " + file);
            return;
        }
        Properties props = new Properties();
        try {
            props.load(propStream);
        } catch (IOException e) {
            throw new ServletException("Cannot load " + file + ": " + e.getMessage(), e);
        }

        // set the user properties
        TableProperties.setUserProperties(props);
    } else {
        log.warn(Messages.getString("DisplayPropertiesLoaderServlet.missingparameter", //$NON-NLS-1$
                new Object[] { PROPERTIES_PARAMETER }));
    }

}

From source file:com.adito.vfs.webdav.DAVServlet.java

public void init(ServletConfig config) throws ServletException {
    /* Remember the configuration instance */
    this.context = config.getServletContext();
    this.config = config;

}

From source file:com.sun.portal.portletcontainer.driver.admin.UploadServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
    super.init(config);
    maxUploadSize = config.getInitParameter("MAX_UPLOAD_SIZE") == null ? 10000000
            : Integer.parseInt(config.getInitParameter("MAX_UPLOAD_SIZE"));
    context = config.getServletContext();
}