/** * Get a processing configuration or null if not set * @param pConfigKey configuration key to fetch * @return string value or <code>null</code> if not set */ public String getParameter(ConfigKey pConfigKey) { return processingConfig.get(pConfigKey); }
private void initContext() { context = jolokiaConfig.get(ConfigKey.AGENT_CONTEXT); if (context == null) { context = ConfigKey.AGENT_CONTEXT.getDefaultValue(); } if (!context.endsWith("/")) { context += "/"; } }
private JSONObject configToJSONObject() { JSONObject info = new JSONObject(); if (config != null) { for (ConfigKey key : ConfigKey.values()) { if (key.isGlobalConfig()) { String value = config.get(key); if (value != null) { info.put(key.getKeyValue(), value); } } } } return info; }
private String findAgentUrl(Configuration pConfig) { // System property has precedence String url = System.getProperty("jolokia." + ConfigKey.DISCOVERY_AGENT_URL.getKeyValue()); if (url == null) { url = System.getenv("JOLOKIA_DISCOVERY_AGENT_URL"); if (url == null) { url = pConfig.get(ConfigKey.DISCOVERY_AGENT_URL); } } return NetworkUtil.replaceExpression(url); }
/** * Update this global configuration from a string-string. Only the known keys are taken * from this map * * @param pConfig config map from where to take the configuration */ public void updateGlobalConfiguration(Map<String, String> pConfig) { for (ConfigKey c : ConfigKey.values()) { if (c.isGlobalConfig()) { String value = pConfig.get(c.getKeyValue()); if (value != null) { globalConfig.put(c,value); } } } }
private boolean listenForDiscoveryMcRequests(Configuration pConfig) { // Check for system props, system env and agent config boolean sysProp = System.getProperty("jolokia." + ConfigKey.DISCOVERY_ENABLED.getKeyValue()) != null; boolean env = System.getenv("JOLOKIA_DISCOVERY") != null; boolean config = pConfig.getAsBoolean(ConfigKey.DISCOVERY_ENABLED); return sysProp || env || config; } /**
private String getConfiguration(ConfigKey pKey) { // TODO: Use fragments if available. String value = getConfigurationFromConfigAdmin(pKey); if (value == null) { value = bundleContext.getProperty(CONFIG_PREFIX + "." + pKey.getKeyValue()); } if (value == null) { value = pKey.getDefaultValue(); } return value; }
/** * Update the configuration hold by this object * * @param pExtractor an extractor for retrieving the configuration from some external object */ public void updateGlobalConfiguration(ConfigExtractor pExtractor) { Enumeration e = pExtractor.getNames(); while (e.hasMoreElements()) { String keyS = (String) e.nextElement(); ConfigKey key = ConfigKey.getGlobalConfigKey(keyS); if (key != null) { globalConfig.put(key,pExtractor.getParameter(keyS)); } } }
/** * Get processing parameters from a string-string map * * @param pParams params to extra. A parameter "p" is used as extra path info * @return the processing parameters */ public ProcessingParameters getProcessingParameters(Map<String,String> pParams) { Map<ConfigKey,String> procParams = ProcessingParameters.convertToConfigMap(pParams); for (Map.Entry<ConfigKey,String> entry : globalConfig.entrySet()) { ConfigKey key = entry.getKey(); if (key.isRequestConfig() && !procParams.containsKey(key)) { procParams.put(key,entry.getValue()); } } return new ProcessingParameters(procParams,pParams.get(PATH_QUERY_PARAM)); }
private String getHostName(InetSocketAddress address) { return configuration.getAsBoolean(ConfigKey.ALLOW_DNS_REVERSE_LOOKUP) ? address.getHostName() : null; }
/** * Get a processing parameter * * @param pKey key to lookup * @return the value or the default value from the key if no config value is set */ public String get(ConfigKey pKey) { String value = params.get(pKey); if (value != null) { return value; } else { return pKey.getDefaultValue(); } }
private String getMimeType(ParsedUri pParsedUri) { return MimeTypeUtil.getResponseMimeType( pParsedUri.getParameter(ConfigKey.MIME_TYPE.getKeyValue()), configuration.get(ConfigKey.MIME_TYPE), pParsedUri.getParameter(ConfigKey.CALLBACK.getKeyValue())); }
/** * Get an configuration value as int value * @param pKey the configuration key * @return the value set or, if not, the default value */ public int getAsInt(ConfigKey pKey) { int ret; try { ret = Integer.parseInt(get(pKey)); } catch (NumberFormatException exp) { ret = Integer.parseInt(pKey.getDefaultValue()); } return ret; }
/** * Get an configuration value as boolean value. The value must * be configured as 'true' for this method to return true * * @param pKey the configuration key for which a boolean config value is requested * @return true if the configuration (or the default value, if the configuration is not set) * is "true" for this key, false otherwise. */ public boolean getAsBoolean(ConfigKey pKey) { return Boolean.valueOf(get(pKey)); }
private void sendResponse(HttpExchange pExchange, ParsedUri pParsedUri, JSONAware pJson) throws IOException { boolean streaming = configuration.getAsBoolean(ConfigKey.STREAMING); if (streaming) { JSONStreamAware jsonStream = (JSONStreamAware)pJson; sendStreamingResponse(pExchange, pParsedUri, jsonStream); } else { // Fallback, send as one object // TODO: Remove for 2.0 sendAllJSON(pExchange, pParsedUri, pJson); } }
/** * Get a configuration value if set as configuration or the default * value if not * * @param pKey the configuration key to lookup * @return the configuration value or the default value if no configuration * was given. */ public String get(ConfigKey pKey) { String value = globalConfig.get(pKey); if (value == null) { value = pKey.getDefaultValue(); } return value; }
private void initParameters(ProcessingParameters pParams) { processingConfig = pParams; String ignoreErrors = processingConfig.get(ConfigKey.IGNORE_ERRORS); if (ignoreErrors != null && ignoreErrors.matches("^(true|yes|on|1)$")) { valueFaultHandler = ValueFaultHandler.IGNORING_VALUE_FAULT_HANDLER; } else { valueFaultHandler = ValueFaultHandler.THROWING_VALUE_FAULT_HANDLER; } }
/** * Get a processing configuration as integer or null * if not set * * @param pConfigKey configuration to lookup * @return integer value of configuration or 0 if not set. */ public int getParameterAsInt(ConfigKey pConfigKey) { String intValueS = processingConfig.get(pConfigKey); if (intValueS != null) { return Integer.parseInt(intValueS); } else { return 0; } }