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.identity.saml2.utils.Util.java

/**
 * reads configurations from web.xml//from   ww w . ja v  a2  s  . c  o  m
 * @param servletConfig
 * @param configuration
 * @return
 */
public static String getConfiguration(ServletConfig servletConfig, String configuration) {
    return servletConfig.getInitParameter(configuration);

}

From source file:com.commercehub.dropwizard.BuildInfoServlet.java

private static ImmutableSet<String> getAttributeBlacklist(ServletConfig config) {
    String attributeBlacklistParam = config.getInitParameter(ATTRIBUTE_BLACKLIST_INIT_PARAM);
    if (StringUtils.isNotBlank(attributeBlacklistParam)) {
        Set<String> blacklist = Sets.newHashSet();
        for (String attribute : StringUtils.split(attributeBlacklistParam, ATTRIBUTE_BLACKLIST_SEPARATOR)) {
            blacklist.add(StringUtils.strip(attribute));
        }/* w  w  w  .  ja  v  a 2s.  com*/
        return ImmutableSet.copyOf(blacklist);
    }
    return ImmutableSet.of();
}

From source file:at.gv.egiz.bku.online.webapp.MoccaParameterBean.java

public static String getInitParameter(String name, ServletConfig config, ServletContext context) {
    String initVal = config.getInitParameter(name);
    String contextVal = context.getInitParameter(config.getServletName() + "." + name);
    log.debug("Reading init param " + name + ": " + initVal + " - context param "
            + (config.getServletName() + "." + name) + ": " + contextVal);
    if (contextVal != null)
        return contextVal;
    return initVal;
}

From source file:org.apache.openaz.xacml.rest.XACMLRest.java

/**
 * This must be called during servlet initialization. It sets up the xacml.?.properties file as a system
 * property. If the System property is already set, then it does not do anything. This allows the
 * developer to specify their own xacml.properties file to be used. They can 1) modify the default
 * properties that comes with the project, or 2) change the WebInitParam annotation, or 3) specify an
 * alternative path in the web.xml, or 4) set the Java System property to point to their xacml.properties
 * file. The recommended way of overriding the default xacml.properties file is using a Java System
 * property: -Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties This way one does not change any
 * actual code or files in the project and can leave the defaults alone.
 *
 * @param config - The servlet config file passed from the javax servlet init() function
 *///ww w.java  2s . c om
public static void xacmlInit(ServletConfig config) {
    //
    // Get the XACML Properties File parameter first
    //
    String propFile = config.getInitParameter("XACML_PROPERTIES_NAME");
    if (propFile != null) {
        //
        // Look for system override
        //
        String xacmlPropertiesName = System.getProperty(XACMLProperties.XACML_PROPERTIES_NAME);
        if (xacmlPropertiesName == null) {
            //
            // Set it to our servlet default
            //
            if (logger.isDebugEnabled()) {
                logger.debug("Using Servlet Config Property for XACML_PROPERTIES_NAME:" + propFile);
            }
            System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, propFile);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Using System Property for XACML_PROPERTIES_NAME:" + xacmlPropertiesName);
            }
        }
    }
    //
    // Setup the remaining properties
    //
    Enumeration<String> params = config.getInitParameterNames();
    while (params.hasMoreElements()) {
        String param = params.nextElement();
        if (!param.equals("XACML_PROPERTIES_NAME")) {
            String value = config.getInitParameter(param);
            logger.info(param + "=" + config.getInitParameter(param));
            restProperties.setProperty(param, value);
        }
    }
}

From source file:org.codice.admin.router.SparkServlet.java

private static String getConfigPath(String filterMappingPattern, ServletConfig config) {
    String result = Optional.ofNullable(filterMappingPattern)
            .orElse(config.getInitParameter(FILTER_MAPPING_PARAM));
    if (result == null || result.equals(SLASH_WILDCARD)) {
        return "";
    } else if (!result.startsWith(SLASH) || !result.endsWith(SLASH_WILDCARD)) {
        throw new RuntimeException(
                String.format("The %s must start with '/' and end with '/*'. Instead it is: %s",
                        FILTER_MAPPING_PARAM, result));
    }/*from   w w w. j  a  v a 2  s .  co m*/
    return result.substring(1, result.length() - 1);
}

From source file:org.codice.ddf.catalog.ui.SparkServlet.java

private static String getConfigPath(String filterMappingPattern, ServletConfig config) {
    String result = Optional.ofNullable(filterMappingPattern)
            .orElse(config.getInitParameter(FILTER_MAPPING_PARAM));
    if (result == null || result.equals(SLASH_WILDCARD)) {
        return "";
    } else if (!result.startsWith(SLASH) || !result.endsWith(SLASH_WILDCARD)) {
        throw new IllegalArgumentException(
                String.format("The %s must start with '/' and end with '/*'. Instead it is: %s",
                        FILTER_MAPPING_PARAM, result));
    }//  w  ww  . j  a  v a 2  s  .  c o  m
    return result.substring(1, result.length() - 1);
}

From source file:org.apache.synapse.ServerConfigurationInformationFactory.java

/**
 * Load synapse initialization parameters from servlet configuration
 *
 * @param servletConfig Servlet configuration with the init parameters
 * @param name name of the init parameter to be loaded
 * @param required whether this parameter is a required one or not
 * @return value of the loaded parameter
 *///from  ww  w.  ja v a 2 s  .  c  o m
private static String loadParameter(ServletConfig servletConfig, String name, boolean required) {

    if (System.getProperty(name) == null) {

        String value = servletConfig.getInitParameter(name);
        if (log.isDebugEnabled()) {
            log.debug("Init parameter '" + name + "' : " + value);
        }

        if ((value == null || value.trim().length() == 0) && required) {
            handleFatal("A valid system property or init parameter '" + name + "' is required");
        } else {
            return value;
        }
    } else {
        return System.getProperty(name);
    }
    return null;
}

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

private static String getParam(ServletConfig config, String name, String def) {
    String ret = config.getInitParameter(name);

    if (ret == null)
        ret = def;//from   www  .j a  v a 2s  .  c om

    return ret;
}

From source file:org.apache.axis.configuration.EngineConfigurationFactoryServlet.java

/**
 * Get a default server engine configuration in a servlet environment.
 *
 * @param ctx a ServletContext/*from w  ww  .ja  va 2 s. c  om*/
 * @return a server EngineConfiguration
 */
private static EngineConfiguration getServerEngineConfig(ServletConfig cfg) {

    ServletContext ctx = cfg.getServletContext();

    // Respect the system property setting for a different config file
    String configFile = cfg.getInitParameter(OPTION_SERVER_CONFIG_FILE);
    if (configFile == null)
        configFile = AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE);
    if (configFile == null) {
        configFile = SERVER_CONFIG_FILE;
    }

    /**
     * Flow can be confusing.  Here is the logic:
     * 1) Make all attempts to open resource IF it exists
     *    - If it exists as a file, open as file (r/w)
     *    - If not a file, it may still be accessable as a stream (r)
     *    (env will handle security checks).
     * 2) If it doesn't exist, allow it to be opened/created
     * 
     * Now, the way this is done below is:
     * a) If the file does NOT exist, attempt to open as a stream (r)
     * b) Open named file (opens existing file, creates if not avail).
     */

    /*
     * Use the WEB-INF directory
     * (so the config files can't get snooped by a browser)
     */
    String appWebInfPath = "/WEB-INF";

    FileProvider config = null;

    String realWebInfPath = ctx.getRealPath(appWebInfPath);

    /**
     * If path/file doesn't exist, it may still be accessible
     * as a resource-stream (i.e. it may be packaged in a JAR
     * or WAR file).
     */
    if (realWebInfPath == null || !(new File(realWebInfPath, configFile)).exists()) {
        String name = appWebInfPath + "/" + configFile;
        InputStream is = ctx.getResourceAsStream(name);
        if (is != null) {
            // FileProvider assumes responsibility for 'is':
            // do NOT call is.close().
            config = new FileProvider(is);
        }

        if (config == null) {
            log.error(Messages.getMessage("servletEngineWebInfError03", name));
        }
    }

    /**
     * Couldn't get data  OR  file does exist.
     * If we have a path, then attempt to either open
     * the existing file, or create an (empty) file.
     */
    if (config == null && realWebInfPath != null) {
        try {
            config = new FileProvider(realWebInfPath, configFile);
        } catch (ConfigurationException e) {
            log.error(Messages.getMessage("servletEngineWebInfError00"), e);
        }
    }

    /**
     * Fall back to config file packaged with AxisEngine
     */
    if (config == null) {
        log.warn(Messages.getMessage("servletEngineWebInfWarn00"));
        try {
            InputStream is = ClassUtils.getResourceAsStream(AxisServer.class, SERVER_CONFIG_FILE);
            config = new FileProvider(is);
        } catch (Exception e) {
            log.error(Messages.getMessage("servletEngineWebInfError02"), e);
        }
    }

    return config;
}

From source file:mondrian.xmla.impl.Olap4jXmlaServlet.java

private static void foo(Map<String, Object> map, String targetProp, ServletConfig servletConfig,
        String sourceProp) {/*from ww  w .j  a  v  a 2  s . co m*/
    final String value = servletConfig
            .getInitParameter(OLAP_DRIVER_PRECONFIGURED_DISCOVER_DATASOURCES_PREFIX + sourceProp);
    map.put(targetProp, value);
}