Example usage for javax.servlet ServletConfig getInitParameter

List of usage examples for javax.servlet ServletConfig getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name.

Usage

From source file:org.wso2.carbon.identity.entitlement.filter.EntitlementCacheUpdateServlet.java

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

    EntitlementCacheUpdateServletDataHolder.getInstance().setServletConfig(config);
    try {//w  w w.  ja  va  2  s.co m
        EntitlementCacheUpdateServletDataHolder.getInstance()
                .setConfigCtx(ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null));
    } catch (AxisFault e) {
        log.error("Error while initializing Configuration Context", e);
        throw new EntitlementCacheUpdateServletException("Error while initializing Configuration Context", e);

    }

    EntitlementCacheUpdateServletDataHolder.getInstance()
            .setHttpsPort(config.getInitParameter(EntitlementConstants.HTTPS_PORT));
    EntitlementCacheUpdateServletDataHolder.getInstance()
            .setAuthentication(config.getInitParameter(EntitlementConstants.AUTHENTICATION));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServiceUrl(
            config.getServletContext().getInitParameter(EntitlementConstants.REMOTE_SERVICE_URL));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServiceUserName(
            config.getServletContext().getInitParameter(EntitlementConstants.USERNAME));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServicePassword(
            config.getServletContext().getInitParameter(EntitlementConstants.PASSWORD));
    EntitlementCacheUpdateServletDataHolder.getInstance()
            .setAuthenticationPage(config.getInitParameter(EntitlementConstants.AUTHENTICATION_PAGE));
    EntitlementCacheUpdateServletDataHolder.getInstance()
            .setAuthenticationPageURL(config.getInitParameter(EntitlementConstants.AUTHENTICATION_PAGE_URL));

}

From source file:org.wrml.server.WrmlServletTest.java

@Test(expected = ServletException.class)
public void createAndInitBadLocation() throws ServletException {

    ServletConfig servletConfig = mock(ServletConfig.class);
    Enumeration<String> eStrings = new TestEmptyEnum();
    when(servletConfig.getInitParameterNames()).thenReturn(eStrings);
    String configLocation = "abcdefg";
    when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME))
            .thenReturn(configLocation);
    _Servlet.init(servletConfig);//from www.ja  va 2 s.co m
}

From source file:org.wrml.server.WrmlServletTest.java

@Test
public void createAndInit() throws ServletException {

    ServletConfig servletConfig = mock(ServletConfig.class);
    Enumeration<String> eStrings = new TestEmptyEnum();
    when(servletConfig.getInitParameterNames()).thenReturn(eStrings);
    String configLocation = "wrml.json";
    when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_RESOURCE_PATH_INIT_PARAM_NAME))
            .thenReturn(configLocation);
    _Servlet.init(servletConfig);//  w  w w.j  ava 2  s  .  c o  m
}

From source file:org.wrml.server.WrmlServletTest.java

@Test(expected = ServletException.class)
public void createAndInitMalformedFile() throws ServletException {

    ServletConfig servletConfig = mock(ServletConfig.class);
    Enumeration<String> eStrings = new TestEmptyEnum();
    when(servletConfig.getInitParameterNames()).thenReturn(eStrings);
    String configLocation = "wrmlbad.json";
    when(servletConfig.getInitParameter(WrmlServlet.WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME))
            .thenReturn(configLocation);
    _Servlet.init(servletConfig);/*from ww w  . ja  v  a2s .com*/
}

From source file:org.ms123.common.rpc.JsonRpcServlet.java

/**
 * Initializes this servlet.//from  w  w  w. jav a 2 s  . c om
 *
 * @param config the servlet config.
 */
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    this.m_jsonSerializer = doGetJsonSerializer();
    this.m_javaSerializer = doGetJavaSerializer();
    this.remoteCallUtils = new RemoteCallUtils(m_javaSerializer);
    final String referrerCheckName = config.getInitParameter("referrerCheck");
    if ("strict".equals(referrerCheckName)) {
        referrerCheck = REFERRER_CHECK_STRICT;
    } else if ("domain".equals(referrerCheckName)) {
        referrerCheck = REFERRER_CHECK_DOMAIN;
    } else if ("session".equals(referrerCheckName)) {
        referrerCheck = REFERRER_CHECK_SESSION;
    } else if ("public".equals(referrerCheckName)) {
        referrerCheck = REFERRER_CHECK_PUBLIC;
    } else if ("fail".equals(referrerCheckName)) {
        referrerCheck = REFERRER_CHECK_FAIL;
    } else {
        referrerCheck = REFERRER_CHECK_PUBLIC;
        // @@@MS
        log("No referrer checking configuration found. Using strict checking as the default.");
    }
}

From source file:org.jbpm.designer.server.EditorHandler.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    DroolsFactoryImpl.init();/*from  w w  w. ja  v a 2  s  . c o m*/
    BpsimFactoryImpl.init();
    _profileService.init(config.getServletContext());
    _pluginService = PluginServiceImpl.getInstance(config.getServletContext());
    _preProcessingService = PreprocessingServiceImpl.INSTANCE;
    _preProcessingService.init(config.getServletContext(), vfsServices);

    _devMode = Boolean.parseBoolean(
            System.getProperty(DEV) == null ? config.getInitParameter(DEV) : System.getProperty(DEV));
    _useOldDataAssignments = Boolean.parseBoolean(
            System.getProperty(USEOLDDATAASSIGNMENTS) == null ? config.getInitParameter(USEOLDDATAASSIGNMENTS)
                    : System.getProperty(USEOLDDATAASSIGNMENTS));
    _preProcess = Boolean
            .parseBoolean(System.getProperty(PREPROCESS) == null ? config.getInitParameter(PREPROCESS)
                    : System.getProperty(PREPROCESS));
    _skin = System.getProperty(SKIN) == null ? config.getInitParameter(SKIN) : System.getProperty(SKIN);
    _designerVersion = readDesignerVersion(config.getServletContext());
    showPDFDoc = doShowPDFDoc(config);

    String editor_file = config.getServletContext().getRealPath(designer_path + "editor.st");
    try {
        _doc = readFile(editor_file);
    } catch (Exception e) {
        throw new ServletException("Error while parsing editor.st", e);
    }
    if (_doc == null) {
        _logger.error("Invalid editor.st, " + "could not be read as a document.");
        throw new ServletException("Invalid editor.st, " + "could not be read as a document.");
    }
}

From source file:org.iterx.miru.support.servlet.HttpDispatcherServlet.java

public void init(ServletConfig servletConfig) throws ServletException {

    try {//ww w . j  a  v a2 s .c o  m
        DispatcherApplicationContext applicationContext;
        ApplicationContext parentApplicationContext;
        HandlerChainFactory handlerChainFactory;
        ServletContext servletContext;
        String parameter;

        servletContext = servletConfig.getServletContext();

        parentApplicationContext = (ApplicationContext) servletContext
                .getAttribute((DispatcherApplicationContext.class).getName());
        applicationContext = ((parentApplicationContext != null)
                ? new ServletDispatcherApplicationContext(parentApplicationContext, servletContext)
                : new ServletDispatcherApplicationContext(servletContext));

        if ((parameter = servletConfig.getInitParameter(ServletDispatcherApplicationContext.BEANS)) != null
                && applicationContext instanceof Loadable) {
            URL url;

            if ((url = (servletContext.getResource(parameter))) != null)
                ((Loadable) applicationContext).load(new UriStreamResource(url.toURI()));
            else
                throw new IOException("Invalid stream [" + parameter + "]");
        }

        handlerChainFactory = applicationContext.getHandlerChainFactory();
        if ((parameter = servletConfig.getInitParameter(ServletDispatcherApplicationContext.CHAINS)) != null
                && handlerChainFactory instanceof Loadable) {
            URL url;

            if ((url = (servletContext.getResource(parameter))) != null)
                ((Loadable) handlerChainFactory).load(new UriStreamResource(url.toURI()));
            else
                throw new IOException("Invalid stream [" + parameter + "]");
        }

        if (dispatcher == null
                && (dispatcher = (Dispatcher<HttpServletRequestContext, HttpServletResponseContext>) applicationContext
                        .getBeanOfType(Dispatcher.class)) == null)
            dispatcher = new Dispatcher<HttpServletRequestContext, HttpServletResponseContext>();

        dispatcher.setHandlerChainMap(handlerChainFactory.getHandlerChains());
        processingContextFactory = applicationContext.getProcessingContextFactory();
    } catch (Exception e) {
        LOGGER.error("Initialisation failed.", e);
        throw new ServletException("Initialisation failed.", e);
    }
}

From source file:helma.servlet.AbstractServletClient.java

/**
 * Init this servlet.//from w ww . j a va2s. c  o m
 *
 * @param init the servlet configuration
 *
 * @throws ServletException ...
 */
public void init(ServletConfig init) throws ServletException {
    super.init(init);

    // get max size for file uploads per file
    String upstr = init.getInitParameter("uploadLimit");
    try {
        uploadLimit = (upstr == null) ? 1024 : Integer.parseInt(upstr);
    } catch (NumberFormatException x) {
        log("Bad number format for uploadLimit: " + upstr);
        uploadLimit = 1024;
    }
    // get max total upload size
    upstr = init.getInitParameter("totalUploadLimit");
    try {
        totalUploadLimit = (upstr == null) ? uploadLimit : Integer.parseInt(upstr);
    } catch (NumberFormatException x) {
        log("Bad number format for totalUploadLimit: " + upstr);
        totalUploadLimit = uploadLimit;
    }
    // soft fail mode for upload errors
    uploadSoftfail = ("true".equalsIgnoreCase(init.getInitParameter("uploadSoftfail")));

    // get cookie domain
    cookieDomain = init.getInitParameter("cookieDomain");
    if (cookieDomain != null) {
        cookieDomain = cookieDomain.toLowerCase();
    }

    // get session cookie name
    sessionCookieName = init.getInitParameter("sessionCookieName");
    if (sessionCookieName == null) {
        sessionCookieName = "HopSession";
    }

    // disable binding session cookie to ip address?
    protectedSessionCookie = !("false".equalsIgnoreCase(init.getInitParameter("protectedSessionCookie")));

    // debug mode for printing out detailed error messages
    debug = ("true".equalsIgnoreCase(init.getInitParameter("debug")));

    // generally disable response caching for clients?
    caching = !("false".equalsIgnoreCase(init.getInitParameter("caching")));

    // Get random number generator for session ids
    try {
        random = SecureRandom.getInstance("SHA1PRNG");
        secureRandom = true;
    } catch (NoSuchAlgorithmException nsa) {
        random = new Random();
        secureRandom = false;
    }
    random.setSeed(
            random.nextLong() ^ System.currentTimeMillis() ^ hashCode() ^ Runtime.getRuntime().freeMemory());
    random.nextLong();

}

From source file:org.openbravo.service.datasource.DataSourceServlet.java

@Override
public void init(ServletConfig config) {
    if (config.getInitParameter(DataSourceConstants.URL_NAME_PARAM) != null) {
        servletPathPart = config.getInitParameter(DataSourceConstants.URL_NAME_PARAM);
    }//from   www.j  ava  2s  .  c om

    super.init(config);
}

From source file:de.fuberlin.wiwiss.marbles.MarblesServlet.java

/**
 * Reads servlet configuration, initializes Sesame repositories and loads ontologies
 *//*from w w w .  j  a v a 2  s  .c o m*/
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    ServletContext context = config.getServletContext();

    dataRoot = getAbsolutePath(config.getInitParameter("dataRoot"), context);

    if (!(dataRoot != null && new File(dataRoot).isDirectory()))
        throw new ServletException("Invalid dataRoot " + (dataRoot == null ? "(null)" : dataRoot));

    try {
        if (config.getInitParameter("assetsURL") != null)
            assetsURL = new URL(config.getInitParameter("assetsURL"));
    } catch (Exception e) {
        throw new ServletException("Invalid assetsURL " + config.getInitParameter("assetsURL"));
    }

    try {
        if (config.getInitParameter("serviceURL") != null)
            serviceURL = new URL(config.getInitParameter("serviceURL"));
    } catch (Exception e) {
        throw new ServletException("Invalid serviceURL " + config.getInitParameter("serviceURL"));
    }

    org.apache.log4j.BasicConfigurator.configure();

    boolean enableDebugging = (config.getInitParameter("enableDebugging") != null
            && config.getInitParameter("enableDebugging").equalsIgnoreCase("true"));

    Logger.getRootLogger().setLevel(enableDebugging ? Level.DEBUG : Level.WARN);

    /* Set up HTTP Client logging */
    // Commented out at this should be configured on the server level      
    //      System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
    //      System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    //      System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
    //      System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");      

    /* Set up Sesame MySQL RDBMS */
    try {
        confRepository = new SailRepository(new MemoryStore());
        confRepository.initialize();

        ontoRepository = new SailRepository(
                new NativeStore(new File(getAbsolutePath(config.getInitParameter("ontologyStore"), context))));
        ontoRepository.initialize();

        SailBase baseStore = null;

        if (config.getInitParameter("mysqlDb") != null && config.getInitParameter("mysqlServer") != null
                && config.getInitParameter("mysqlUser") != null
                && config.getInitParameter("mysqlPass") != null) {
            MySqlStore myStore = new MySqlStore(config.getInitParameter("mysqlDb"));
            myStore.setServerName(config.getInitParameter("mysqlServer"));
            myStore.setUser(config.getInitParameter("mysqlUser"));
            myStore.setPassword(config.getInitParameter("mysqlPass"));
            myStore.setMaxNumberOfTripleTables(16);
            //myStore.setIndexed(true);
            baseStore = myStore;
        } else {
            baseStore = new NativeStore(
                    new File(getAbsolutePath(config.getInitParameter("cacheStore"), context)));
        }

        /* SameAsInferencer requires an InferencerConnection, which is provided by the native store */
        sameAsInferencer = new SameAsInferencer(baseStore);
        sameAsInferencer.setAutoInference(false);

        dataRepository = new SailRepository(sameAsInferencer);
        dataRepository.initialize();

        metaDataRepository = new SailRepository(
                new NativeStore(new File(getAbsolutePath(config.getInitParameter("metadataStore"), context))));
        metaDataRepository.initialize();

        RepositoryConnection ontoConn = ontoRepository.getConnection();
        ValueFactory ontoValueFactory = ontoRepository.getValueFactory();

        /* Load ontologies */
        File ontoDir = new File(dataRoot + "/" + ontologiesDirectory);
        for (File f : ontoDir.listFiles(new RDFFilenameFilter())) {
            URI ontoResource = ontoValueFactory.createURI("file://" + f.getName());

            /* Only load new ontologies */
            if (!ontoConn.hasStatement(null, null, null, false, ontoResource)) {
                try {
                    loadTriples(ontoRepository, f, null /* parameters */, ontoResource);
                } catch (Exception e) {
                    System.err.println("Error loading " + f.getName());
                    e.printStackTrace();
                }
            }
        }
        ontoConn.close();

        valueFactory = dataRepository.getValueFactory();

        /* Set up external data providers */
        ArrayList<DataProvider> dataProviders = new ArrayList<DataProvider>();
        if (config.getInitParameter("dataProviders") != null) {
            String[] providers = config.getInitParameter("dataProviders").split(",");
            for (String dsName : providers) {
                try {
                    DataProvider d = (DataProvider) (this.getClass().getClassLoader().loadClass(dsName))
                            .newInstance();
                    dataProviders.add(d);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }

        /* Set up Virtuoso Sponger */
        SpongerProvider spongerProvider = null;
        if (config.getInitParameter("spongerServiceURL") != null) {
            spongerProvider = new SpongerProvider(config.getInitParameter("spongerServiceURL"));
        }

        cacheController = new CacheController(dataRepository, metaDataRepository);
        semwebClient = new SemanticWebClient(cacheController, spongerProvider, dataProviders);
    } catch (Exception e) {
        e.printStackTrace();
    }
}