Example usage for javax.servlet ServletContext getInitParameter

List of usage examples for javax.servlet ServletContext getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

Usage

From source file:gov.nih.nci.protexpress.util.ConfigurationHelper.java

/**
 * @return the ldap context parameters.//from ww  w .  j a  va2  s. co  m
 */
public static Hashtable<String, String> getLdapContextParameters() {
    if (ldapContextParams == null) {
        ldapContextParams = new Hashtable<String, String>();

        ServletContext context = ServletActionContext.getServletContext();
        Enumeration<String> e = context.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = e.nextElement();
            if (param.startsWith("ldap")) {
                ldapContextParams.put(param, context.getInitParameter(param));
            }
        }
    }
    return ldapContextParams;
}

From source file:com.shengpay.commons.bp.logback.LogbackWebConfigurer.java

/**
 * Initialize logback, including setting the web app root system property.
 * /*from ww  w  .ja va2s .c  o  m*/
 * @param servletContext
 *            the current ServletContext
 * @see WebUtils#setWebAppRootSystemProperty
 */
public static void initLogging(ServletContext servletContext) {
    // Expose the web app root system property.
    if (exposeWebAppRoot(servletContext)) {
        WebUtils.setWebAppRootSystemProperty(servletContext);
    }

    // Only perform custom logback initialization in case of a config file.
    String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    if (location != null) {
        // Perform actual logback initialization; else rely on logback's default initialization.
        try {
            // Return a URL (e.g. "classpath:" or "file:") as-is;
            // consider a plain file path as relative to the web application root directory.
            if (!ResourceUtils.isUrl(location)) {
                // Resolve system property placeholders before resolving real path.
                location = SystemPropertyUtils.resolvePlaceholders(location);
                location = WebUtils.getRealPath(servletContext, location);
            }

            // Write log message to server log.
            servletContext.log("Initializing logback from [" + location + "]");

            // Initialize without refresh check, i.e. without logback's watchdog thread.
            LogbackConfigurer.initLogging(location);

        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
        }
    }
}

From source file:org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil.java

public static void setResourceAuthTypes(ServletContext servletContext, APIConfig apiConfig) {
    List<String> resourcesList = null;
    String nonSecuredResources = servletContext.getInitParameter(NON_SECURED_RESOURCES);
    if (null != nonSecuredResources) {
        resourcesList = Arrays.asList(nonSecuredResources.split(","));
    }//from   w  w  w  .  j  a v a 2s .  c o  m
    Set<ApiUriTemplate> templates = apiConfig.getUriTemplates();
    if (null != resourcesList) {
        for (ApiUriTemplate template : templates) {
            String fullPaath = "";
            if (!template.getUriTemplate().equals(AnnotationProcessor.WILD_CARD)) {
                fullPaath = apiConfig.getContext() + template.getUriTemplate();
            } else {
                fullPaath = apiConfig.getContext();
            }
            for (String context : resourcesList) {
                if (context.trim().equals(fullPaath)) {
                    template.setAuthType(AUTH_TYPE_NON_SECURED);
                }
            }
        }
    }
    apiConfig.setUriTemplates(templates);
}

From source file:org.apache.isis.core.runtime.runner.opts.OptionHandlerInitParameters.java

private static Map<String, String> asMap(ServletContext servletContext) {
    Enumeration<String> initParameterNames = servletContext.getInitParameterNames();
    final Map<String, String> map = Maps.newTreeMap();
    while (initParameterNames.hasMoreElements()) {
        final String initParameterName = initParameterNames.nextElement();
        final String initParameterValue = servletContext.getInitParameter(initParameterName);
        if (initParameterName.startsWith("isis.")) {
            map.put(initParameterName, initParameterValue);
        }//from  ww  w.j  a v a2 s.c o m
    }
    return map;
}

From source file:org.apache.wiki.util.PropertyReader.java

/**
 *  Returns the ServletContext Init parameter if has been set, otherwise
 *  checks for a System property of the same name. If neither are defined,
 *  returns null. This permits both Servlet- and System-defined cascading
 *  properties./*  w  ww.  j a  v  a2s  .co m*/
 */
private static String getInitParameter(ServletContext context, String name) {
    String value = context.getInitParameter(name);
    return (value != null) ? value : System.getProperty(name);
}

From source file:org.apache.juddi.v3.client.config.WebHelper.java

/**
 * Checks the servlet context for the manager defined in the web context. Optionally, in your 
 * web.xml you can specify either the manager name if you want to use an existing manager 
 * called 'uddi-portlet-manager':// w w  w. ja  v a  2 s. c om
 * <pre>
 * &lt;context-param&gt;
 *   &lt;param-name&gt;uddi.client.manager.name&lt;/param-name&gt;
 *   &lt;param-value&gt;uddi-portlet-manager&lt;/param-value&gt;
 * &lt;/context-param&gt;
 * </pre>
 * or, if you don't want to use the default META-INF/uddi.xml file path, but 'META-INF/my-uddi.xml' instead,
 * then you can set:
 * <pre>
 * &lt;context-param&gt;
 *   &lt;param-name&gt;uddi.client.config.path&lt;/param-name&gt;
 *   &lt;param-value&gt;META-INF/my-uddi.xml&lt;/param-value&gt;
 * &lt;/context-param&gt;
 * </pre>
 * @param servletContext
 * @return a UDDI Client instance
 * @throws ConfigurationException
 */
public static UDDIClient getUDDIClient(ServletContext servletContext) throws ConfigurationException {
    if (servletContext.getAttribute(JUDDI_CLIENT_NAME) != null) {
        String clientName = String.valueOf(servletContext.getAttribute(JUDDI_CLIENT_NAME));
        return UDDIClientContainer.getUDDIClient(clientName);
    } else {
        String clientName = servletContext.getInitParameter(UDDI_CLIENT_NAME);
        if (clientName != null) {
            try {
                UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
                logger.info("Client " + clientName + " was already started.");
                servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName);
                return client;
            } catch (ConfigurationException ce) {
                logger.debug("Client " + clientName + " is not yet started.");
            }
        }
        String clientConfigFile = servletContext.getInitParameter(UDDI_CLIENT_CONFIG_FILE);
        if (clientConfigFile == null)
            clientConfigFile = ClientConfig.DEFAULT_UDDI_CONFIG;

        logger.info("Reading the clientName from the clientConfig file " + clientConfigFile);
        UDDIClient client = new UDDIClient(clientConfigFile);
        if (clientConfigFile == null && client.getName() == null) {
            logger.warn(
                    "Deprecated, client name set to 'default', however it should be provided in the uddi.xml");
            clientName = "default";
        }
        if (client.getName() != null) {
            logger.info("Starting Client " + client.getName() + "...");
        } else {
            throw new ConfigurationException("A client name needs to be specified in the client config file.");
        }

        client.start();
        servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName);
        return client;
    }
}

From source file:org.kuali.rice.core.web.util.PropertySources.java

/**
 * Convert {@code ServletContext} init parameters into a {@code Properties} object.
 *//*ww  w  . j a va2s.c o  m*/
public static Properties convert(ServletContext context) {
    Properties properties = new Properties();
    @SuppressWarnings("unchecked")
    Enumeration<String> paramNames = context.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        properties.put(paramName, context.getInitParameter(paramName));
    }
    return properties;
}

From source file:org.glite.security.voms.admin.core.VOMSService.java

protected static void configureLogging(ServletContext ctxt) {

    String confDir = ctxt.getInitParameter("CONF_DIR");
    String vo = ctxt.getInitParameter("VO_NAME");

    String loggingConf = String.format("%s/%s/%s", confDir, vo, "logback.xml");

    File f = new File(loggingConf);

    if (!f.exists())
        throw new VOMSFatalException(
                String.format("Logging configuration " + "not found at path '%s'", loggingConf));

    if (!f.canRead())
        throw new VOMSFatalException(
                String.format("Logging configuration " + "is not readable: %s", loggingConf));

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.setName(vo);/*from   ww w  .  j av a 2  s.c  om*/

    JoranConfigurator configurator = new JoranConfigurator();

    configurator.setContext(lc);

    lc.reset();

    // We leave this here to avoid runtime errors for people that
    // update the service, but not the logging configuration 
    // FIXME: to be removed at some point
    lc.putProperty(VOMSConfigurationConstants.VO_NAME, vo);

    try {
        configurator.doConfigure(f);

    } catch (JoranException e) {

        throw new VOMSFatalException("Error setting up the logging system", e);

    }

    StatusPrinter.printIfErrorsOccured(lc);
}

From source file:com.facetime.communication.activemq.AmqConsumer.java

public static void initContext(ServletContext context) {
    initConnectionFactory(context);/*from  w  w w.ja v  a 2 s.  c  om*/
    context.setAttribute("webClients", new HashMap<String, AmqConsumer>());
    if (selectorName == null) {
        selectorName = context.getInitParameter(SELECTOR_NAME);
    }
    if (selectorName == null) {
        selectorName = "selector";
    }
}

From source file:org.wings.session.WingServlet.java

public static void installSession(HttpServletRequest req, HttpServletResponse res) {
    ServletContext context = req.getSession().getServletContext();
    String lookupName = context.getInitParameter("wings.servlet.lookupname");

    if (lookupName == null || lookupName.trim().length() == 0) {
        lookupName = "SessionServlet:" + context.getInitParameter("wings.mainclass");
    }//from w ww. ja  va 2s  .c o m
    SessionServlet sessionServlet = (SessionServlet) req.getSession().getAttribute(lookupName);
    if (sessionServlet != null) {
        Session session = sessionServlet.getSession();
        session.setServletRequest(req);
        session.setServletResponse(res);
        SessionManager.setSession(session);
    }
}