Java Code Examples for javax.servlet.ServletContext#getInitParameterNames()

The following examples show how to use javax.servlet.ServletContext#getInitParameterNames() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private synchronized void initCoreSettings(ServletContext context) {
    if (coreSettings != null) {
        return;
    }
    Properties properties = new Properties();
    Enumeration<String> names = context.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String targetName = name.replace("_", ".");
        properties.put(targetName, context.getInitParameter(name));
    }
    if (!properties.containsKey(CoreSettings.TAG_TEMP_PATH)) {
        properties.setProperty(CoreSettings.TAG_TEMP_PATH, String.valueOf(context.getAttribute(ServletContext.TEMPDIR)));
    }
    coreSettings = new CoreSettings(properties);
}
 
Example 2
/**
 * Utility method for setting this thread configuration context with ServletContext parameters who's keys are prefixed with "apiml."
 *
 * @param servletContext
 */
public Map<String, String> setApiMlServiceContext(ServletContext servletContext) {
    Map<String, String> threadContextMap = ObjectUtil.getThreadContextMap(threadConfigurationContext);

    Enumeration<String> paramNames = servletContext.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String param = paramNames.nextElement();
        String value = servletContext.getInitParameter(param);
        if (param.startsWith("apiml.")) {
            threadContextMap.put(param, value);
        }
    }
    return threadContextMap;
}
 
Example 3
Source Project: netbeans   File: MonitorFilter.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * Creates an instance of ContextData based on the request
    */
   private void recordContextData(ContextData cd, 
			   HttpServletRequest request) 
   {
ServletContext context = filterConfig.getServletContext();

if(debug) log(" Getting servlet context props"); //NOI18N
cd.setAttributeValue("absPath", context.getRealPath("/")); //NOI18N
cd.setAttributeValue("contextName", //NOI18N
		     context.getServletContextName()); //NOI18N

if(debug)  log(" context attributes"); //NOI18N
ContextAttributes ctxtattr = new ContextAttributes();
ctxtattr.setParam(recordContextAttributes(context));
cd.setContextAttributes(ctxtattr);

if(debug) log(" Getting context init parameters"); //NOI18N
Enumeration e = context.getInitParameterNames(); 
Vector v = new Vector();

while (e.hasMoreElements()) {
    String name = (String)e.nextElement();
    String value = context.getInitParameter(name);
    Param p = new Param();
    p.setAttributeValue("name", name); //NOI18N
    p.setAttributeValue("value", value); //NOI18N
    v.add(p);
}

int size = v.size();
Param[] params = new Param[size];
for(int i=0; i< size; ++i) 
    params[i] = (Param)v.elementAt(i);
cd.setParam(params);
   }
 
Example 4
/**
 *
 * Creates the Map that maps init parameter name to single init
 * parameter value.
 **/
public static Map createInitParamMap (PageContext pContext)
{
  final ServletContext context = pContext.getServletContext ();
  return new EnumeratedMap ()
    {
      public Enumeration enumerateKeys () 
      {
        return context.getInitParameterNames ();
      }

      public Object getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          return context.getInitParameter ((String) pKey);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
Example 5
Source Project: scipio-erp   File: ServletUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets map of context-params from servlet context
 * Fill-in for missing java servlet API method.
 */
public static Map<String, String> getContextParams(ServletContext servletContext) {
    Map<String, String> initParams = new HashMap<>();
    Enumeration<String> names = servletContext.getInitParameterNames();
    while(names.hasMoreElements()) {
        String name = names.nextElement();
        initParams.put(name, servletContext.getInitParameter(name));
    }
    return initParams;
}
 
Example 6
Source Project: JAADAS   File: Basic42.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {        
    ServletContext context = getServletConfig().getServletContext();
    Enumeration e = context.getInitParameterNames();
    while(e.hasMoreElements()) {
        String name = (String) e.nextElement();
        Object value = context.getInitParameter(name); 
        PrintWriter writer = resp.getWriter();
        writer.println(value.toString());          					 /* BAD */
    }
}
 
Example 7
@Override
public void setServletContext(final ServletContext servletContext) {

    final Map<String, String> configuration = new HashMap<>();

    final Enumeration parameters = servletContext.getInitParameterNames();
    while (parameters.hasMoreElements()) {

        final String key = String.valueOf(parameters.nextElement());
        final String value = servletContext.getInitParameter(key);

        configuration.put(key, value);

    }

    final NodeImpl node = new NodeImpl(true,
            configuration.get(NodeService.NODE_ID),
            configuration.get(NodeService.NODE_TYPE),
            configuration.get(NodeService.NODE_CONFIG),
            configuration.get(NodeService.CLUSTER_ID),
            configuration.get(NodeService.VERSION),
            configuration.get(NodeService.BUILD_NO),
            true
    );
    node.setChannel(configuration.get(NodeService.CHANNEL));

    this.systemName = node.getId().concat("_").concat(node.getFullVersion());

    super.setServletContext(servletContext);
}
 
Example 8
/**
 * {@inheritDoc}
 * 
 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
 */
public void contextInitialized(ServletContextEvent event) {
    ServletContext ctx = event.getServletContext();

    /*
     * Note: logging is initialized automatically by reading
     * logging.properties and log4j.properties from the classpath.
     * logging.properties is used to tell commons-logging to use LOG4J as
     * its underlying logging toolkit; log4j.properties is used to configure
     * LOG4J. To initialize LOG4J manually from LOG4J_CONFIG_LOCATION,
     * un-comment the following code (LOG4J_CONFIG_LOCATION =
     * "log4jConfigLocation") ...
     */
    // "log4jConfigLocation";
    // String path = ctx.getRealPath("/");
    // String log4jCfg = ctx.getInitParameter(LOG4J_CONFIG_LOCATION);
    // // initialize Log4j
    // if (log4jCfg != null) {
    // // if no log4j properties file found, then do not try
    // // to load it (the application runs without logging)
    // PropertyConfigurator.configure(path + log4jCfg);
    // }
    // log = LogFactory.getLog(this.getClass());

    // set a system property to configure CXF to use LOG4J
    System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger");

    LOG.info("Starting Fosstrak EPCIS Repository application");

    if (LOG.isDebugEnabled()) {
        LOG.debug("Logging application context init-parameters:");
        Enumeration<?> e = ctx.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            LOG.debug(param + "=" + ctx.getInitParameter(param));
        }
    }
}
 
Example 9
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
  ServletContext context = servletContextEvent.getServletContext();

  Enumeration<String> parameters = context.getInitParameterNames();
  Map<String, String> configMap = Maps.newHashMap();
  while (parameters.hasMoreElements()) {
    String key = parameters.nextElement();
    configMap.put(key, context.getInitParameter(key));
  }
  initialize(ConfigFactory.parseMap(configMap));

  super.contextInitialized(servletContextEvent);
}
 
Example 10
/**
 * Translates context parameters from the web.xml into entries in a Properties file.
 */
protected Properties getContextParameters(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;
}
 
Example 11
/**
 * Convert {@code ServletContext} init parameters into a {@code Properties} object.
 */
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;
}
 
Example 12
private KernelConfiguration buildKernelConfiguration(ServletContext servletContext) {
    KernelConfiguration kernelConfiguration = NuunCore.newKernelConfiguration();

    Enumeration<?> initParameterNames = servletContext.getInitParameterNames();
    while (initParameterNames.hasMoreElements()) {
        String parameterName = (String) initParameterNames.nextElement();
        if (parameterName != null && !parameterName.isEmpty()) {
            String parameterValue = servletContext.getInitParameter(parameterName);
            kernelConfiguration.param(parameterName, parameterValue);
        }
    }

    return kernelConfiguration;
}
 
Example 13
Source Project: greenmail   File: GreenMailListener.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, String> extractParameters(ServletContext pServletContext) {
    Enumeration<?> names = pServletContext.getInitParameterNames();
    Map<String, String> parameterMap = new HashMap<>();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        parameterMap.put(name, pServletContext.getInitParameter(name));
    }
    return parameterMap;
}
 
Example 14
Source Project: ldp4j   File: BootstrapUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static void addInitParameterMessages(ServletContext context, Map<String, Object> messages) {
	Enumeration<String> initParameterNames = context.getInitParameterNames();
	if(initParameterNames!=null && initParameterNames.hasMoreElements()) {
		StringBuilder builder=new StringBuilder();
		while(initParameterNames.hasMoreElements()) {
			String name = initParameterNames.nextElement();
			String value = context.getInitParameter(name);
			builder.append(NEW_LINE).append(VALUE_PREFIX).append(name).append(VALUE_SEPARATOR).append(value);
		}
		addMessage(messages,"Init parameters",builder.toString());
	}
}
 
Example 15
Source Project: oodt   File: CurationServiceConfig.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void readContextParams(ServletContext context) {
  for (Enumeration<String> names = context.getInitParameterNames(); names
      .hasMoreElements();) {
    String name = names.nextElement();
    parameters.put(name, context.getInitParameter(name));
  }
  LOG.log(Level.INFO, "Init Parameters: " + parameters);
}
 
Example 16
void initNodeFromServletContext(final ServletContext servletContext) {


        final Enumeration parameters = servletContext.getInitParameterNames();
        while (parameters.hasMoreElements()) {

            final String key = String.valueOf(parameters.nextElement());
            final String value = servletContext.getInitParameter(key);

            configuration.put(key, value);

        }

        final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED);
        final String luceneDisabledValue = luceneDisabled != null ?
                Boolean.valueOf(luceneDisabled).toString() : Boolean.FALSE.toString();
        configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue);

        NodeImpl node = new NodeImpl(true,
                configuration.get(NODE_ID),
                configuration.get(NODE_TYPE),
                configuration.get(NODE_CONFIG),
                configuration.get(CLUSTER_ID),
                configuration.get(VERSION),
                configuration.get(BUILD_NO),
                Boolean.valueOf(luceneDisabledValue)
        );
        node.setChannel(configuration.get(CHANNEL));
        this.node = node;
        this.cluster.add(node);

        log = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId());

        if (log.isInfoEnabled()) {

            log.info("== WS configurations ===========================================");
            log.info("");
            log.info("Node: {}", node);

            for (final Map.Entry<String, String> entry : configuration.entrySet()) {
                log.info("{}: {}", entry.getKey(), entry.getValue());
            }

            log.info("");
            log.info("================================================================");
            log.info("");

        }

    }
 
Example 17
void initNodeFromServletContext(final ServletContext servletContext) {


        final Enumeration parameters = servletContext.getInitParameterNames();
        while (parameters.hasMoreElements()) {

            final String key = String.valueOf(parameters.nextElement());
            final String value = servletContext.getInitParameter(key);

            configuration.put(key, value);

        }

        final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED);
        final String luceneDisabledValue = luceneDisabled != null ?
                Boolean.valueOf(luceneDisabled).toString() : Boolean.FALSE.toString();
        configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue);

        NodeImpl node = new NodeImpl(true,
                configuration.get(NODE_ID),
                configuration.get(NODE_TYPE),
                configuration.get(NODE_CONFIG),
                configuration.get(CLUSTER_ID),
                configuration.get(VERSION),
                configuration.get(BUILD_NO),
                Boolean.valueOf(luceneDisabledValue)
        );
        node.setChannel(configuration.get(CHANNEL));
        this.node = node;
        this.cluster.add(node);

        log = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId());

        if (log.isInfoEnabled()) {

            log.info("== REST configurations =========================================");
            log.info("");
            log.info("Node: {}", node);

            for (final Map.Entry<String, String> entry : configuration.entrySet()) {
                log.info("{}: {}", entry.getKey(), entry.getValue());
            }

            log.info("");
            log.info("================================================================");
            log.info("");

        }

    }
 
Example 18
Source Project: yes-cart   File: JGroupsNodeServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
void initNodeFromServletContext(final ServletContext servletContext) {


        final Enumeration parameters = servletContext.getInitParameterNames();
        while (parameters.hasMoreElements()) {

            final String key = String.valueOf(parameters.nextElement());
            final String value = servletContext.getInitParameter(key);

            configuration.put(key, value);

        }

        final String luceneDisabled = configuration.get(LUCENE_INDEX_DISABLED);
        final String luceneDisabledValue = luceneDisabled != null ?
                Boolean.valueOf(luceneDisabled).toString() : Boolean.FALSE.toString();
        configuration.put(LUCENE_INDEX_DISABLED, luceneDisabledValue);

        node = new NodeImpl(true,
                configuration.get(NODE_ID),
                configuration.get(NODE_TYPE),
                configuration.get(NODE_CONFIG),
                configuration.get(CLUSTER_ID),
                configuration.get(VERSION),
                configuration.get(BUILD_NO),
                Boolean.valueOf(luceneDisabledValue)
        );
        this.cluster.add(node);

        LOG = LoggerFactory.getLogger(node.getClusterId() + "." + node.getNodeId());

        if (LOG.isInfoEnabled()) {

            final StringBuilder stats = new StringBuilder();

            stats.append("\nLoading configuration for node...");
            stats.append("\nNode: ").append(node.getId());

            for (final Map.Entry<String, String> entry : configuration.entrySet()) {
                stats.append('\n').append(entry.getKey()).append(": ").append(entry.getValue());
            }

            LOG.info(stats.toString());
        }

    }