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.sakaiproject.signup.tool.SignupServlet.java

/**
 * Initialize the Servlet class.//from  w  w  w .ja  va 2  s  . com
 */
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    // headerPreContent =
    // servletConfig.getInitParameter("headerPreContent");
    this.servletContext = servletConfig.getServletContext();
}

From source file:net.solarnetwork.web.gemini.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * {@inheritDoc}// ww  w  . j  a  v  a2  s .  c o  m
 */
@Override
public void setServletConfig(ServletConfig servletConfig) {
    this.servletConfig = servletConfig;
    if (servletConfig != null) {
        if (getServletContext() == null) {
            setServletContext(servletConfig.getServletContext());
        }
        if (getNamespace() == null) {
            setNamespace(servletConfig.getServletName() + DEFAULT_NAMESPACE_SUFFIX);
        }
    }
}

From source file:com.kdab.daytona.Logger.java

@Override
public void init(ServletConfig cfg) {
    m_logger = new Logger(cfg);
    Configuration config = null;/*from ww  w .j  ava  2  s  .  c  om*/
    try {
        Properties props = new Properties();
        props.load(new FileInputStream("/Users/frank/daytona-config.xml")); //TODO where to put the file?
        config = new Configuration(props);
    } catch (IOException e) {
        System.err.println(e.getMessage());
        cfg.getServletContext().log("Could not load Daytona configuration file", e);
        m_error = true;
        return;
    } catch (InvalidConfigurationException e) {
        cfg.getServletContext().log("Could not parse Daytona configuration file", e);
        m_error = true;
        return;
    }
    BlockingQueue<byte[]> rawXml = new ArrayBlockingQueue<byte[]>(1000);
    BlockingQueue<byte[]> rawJson = new ArrayBlockingQueue<byte[]>(1000);
    m_queuesByFormat.put("xml", rawXml);
    m_queuesByFormat.put("json", rawJson);
    BlockingQueue<Message> parsed = new ArrayBlockingQueue<Message>(1000);
    BlockingQueue<Message> routed = new ArrayBlockingQueue<Message>(5000);
    ParserRunnable xp = new ParserRunnable(new XmlParser(), rawXml, parsed, m_logger);
    ParserRunnable jp = new ParserRunnable(new JsonParser(), rawJson, parsed, m_logger);
    Router r = new Router(parsed, routed, config.routingRules());
    JabberBot b = new JabberBot(routed, config.account(), config.nick(), config.admins(), config.roomsToJoin(),
            m_logger);
    m_workers = new Vector<Thread>();
    m_workers.add(new Thread(xp));
    m_workers.add(new Thread(jp));
    m_workers.add(new Thread(r));
    m_workers.add(new Thread(b));
    for (Thread i : m_workers)
        i.start();
}

From source file:org.springframework.faces.mvc.servlet.FacesHandlerAdapterTests.java

public void testDelegatingServletConfig() throws Exception {
    Properties initParameters = new Properties();
    initParameters.setProperty("testkey", "testvalue");
    ServletContext servletContext = (ServletContext) EasyMock.createMock(ServletContext.class);
    adapter.setInitParameters(initParameters);
    adapter.setServletContext(servletContext);
    adapter.setOverrideInitParameters(false);
    adapter.setFacesServletClass(MockServlet.class);
    adapter.afterPropertiesSet();/*  ww w.ja va2s . c o  m*/
    MockServlet servlet = (MockServlet) adapter.getFacesServlet();
    ServletConfig config = servlet.getServletConfig();
    assertTrue(EnumerationUtils.toList(config.getInitParameterNames()).contains("testkey"));
    assertEquals("testvalue", config.getInitParameter("testkey"));
    assertEquals("testAdapterBean", config.getServletName());
    assertSame(servletContext, config.getServletContext());
}

From source file:org.apache.nutch.searcher.OpenSearchServlet.java

public void init(ServletConfig config) throws ServletException {
    try {/*ww  w.j  av a 2 s  .  co m*/
        this.conf = NutchConfiguration.get(config.getServletContext());
        bean = NutchBean.get(config.getServletContext(), this.conf);

        functions = PwaFunctionsWritable.parse(this.conf.get(Global.RANKING_FUNCTIONS));
        nQueryMatches = Integer.parseInt(this.conf.get(Global.MAX_FULLTEXT_MATCHES_RANKED));

        collectionsHost = this.conf.get("wax.host", "examples.com");
    } catch (IOException e) {
        throw new ServletException(e);
    }
}

From source file:se.tillvaxtverket.ttsigvalws.ttwebservice.TTSigValServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    this.context = config.getServletContext();
    // Remove any occurance of the BC provider
    Security.removeProvider("BC");
    // Insert the BC provider in a preferred position
    Security.insertProviderAt(new BouncyCastleProvider(), 1);
    try {//from  w ww  .  j a v a  2s . c  om
        SecurityManager secMan = new SecurityManager();
        secMan.checkSetFactory();
        HttpURLConnection.setContentHandlerFactory(new OCSPContentHandlerFactory());
        LOG.info("Setting URL Content handler factory to OCSPContentHandlerFactory");
    } catch (Exception ex) {
        LOG.warning("Error when setting URL content handler factory");
    }
    infoText = ResourceBundle.getBundle("infoText");
    LOG.info(currentDir);
    String dataDir = context.getInitParameter("DataDirectory");
    ConfigData conf = new ConfigData(dataDir);
    baseModel = new SigValidationBaseModel(conf);
    Locale.setDefault(new Locale(baseModel.getConf().getLanguageCode()));
}

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

public ThemeMgtServiceClient(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 + "ThemeMgtService";

    try {//from w ww .java  2 s. com
        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.accada.epcis.repository.query.QueryInitServlet.java

/**
 * Loads the application property file and populates a java.util.Properties
 * instance./*from   ww  w  . java  2 s . co m*/
 * 
 * @param servletConfig
 *            The ServletConfig used to locate the application property
 *            file.
 */
private void loadApplicationProperties(ServletConfig servletConfig) {
    properties = new Properties();

    // read application.properties from classpath
    String path = "/";
    String appConfigFile = "application.properties";
    InputStream is = QueryInitServlet.class.getResourceAsStream(path + appConfigFile);

    try {
        if (is == null) {
            // read properties from file specified in servlet context
            ServletContext ctx = servletConfig.getServletContext();
            path = ctx.getRealPath("/");
            appConfigFile = ctx.getInitParameter(APP_CONFIG_LOCATION);
            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);
    }
}

From source file:org.etudes.jforum.EtudesJForumBaseServlet.java

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

    //initialize configurations
    try {//from  w  ww  .  ja v a 2 s. c om
        String appPath = config.getServletContext().getRealPath("");
        debug = "true".equals(config.getInitParameter("development"));

        // Load system default values
        ConfigLoader.startSystemglobals(appPath);

        ConfigLoader.startCacheEngine();

        // Configure the template engine
        Configuration templateCfg = new Configuration();
        templateCfg.setDirectoryForTemplateLoading(new File(SystemGlobals.getApplicationPath() + "/templates"));
        templateCfg.setTemplateUpdateDelay(2);
        templateCfg.setSetting("number_format", "#");

        ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));

        SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
        SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));

        // Start the dao.driver implementation
        DataAccessDriver daoImpl = null;
        String vendor = SqlService.getVendor();
        if (vendor.equals("oracle")) {
            daoImpl = new OracleDataAccessDriver();
        } else if (vendor.equals("mysql")) {
            daoImpl = new MysqlDataAccessDriver();
        } else if (vendor.equals("hsqldb")) {
            daoImpl = new HsqldbDataAccessDriver();
        } else {
            logger.error("Unable to find an appropriate DataAccessDriver for DB vendor " + vendor);
        }
        DataAccessDriver.init(daoImpl);

        this.loadConfigStuff();

        if (!this.debug) {
            templateCfg.setTemplateUpdateDelay(3600);
        }

        ConfigLoader.listenForChanges();
        ConfigLoader.startSearchIndexer();

        Configuration.setDefaultConfiguration(templateCfg);
    } catch (Exception e) {
        throw new ForumStartupException("Error while starting jforum", e);
    }

    //create database tables
    boolean m_autoDdl = config.getInitParameter("autoddl").equals("true");

    try {
        // if autoDdl is true create the tables
        if (m_autoDdl) {
            Connection conn = null;

            //Start database
            boolean isDatabaseUp = ForumStartup.startDatabase();
            if (isDatabaseUp) {
                conn = DBConnection.getImplementation().getConnection();

                //create tables and data only one time
                if (!createTablesAndData(conn))
                    if (logger.isDebugEnabled())
                        logger.debug(this.getClass().getName()
                                + ".init() : JForum Table's and data already existing in the database");
                    else if (logger.isDebugEnabled())
                        logger.debug(this.getClass().getName()
                                + ".init() : JForum Table's and data created in the database");
            }

            //Finalize
            if (conn != null) {
                try {
                    DBConnection.getImplementation().releaseConnection(conn);
                } catch (Exception e) {
                    throw e;
                }
            }
        }
        //register sakai-JForum functions
        registerJForumFunctions();

    } catch (Exception e) {
        logger.error(this.getClass().getName() + ".init() : " + e.toString(), e);
    }
}