Configuration initConfig(ServletConfig pConfig) { Configuration config = new Configuration( ConfigKey.AGENT_ID, NetworkUtil.getAgentId(hashCode(),"servlet")); // From ServletContext .... config.updateGlobalConfiguration(new ServletConfigFacade(pConfig)); // ... and ServletConfig config.updateGlobalConfiguration(new ServletContextFacade(getServletContext())); // Set type last and overwrite anything written config.updateGlobalConfiguration(Collections.singletonMap(ConfigKey.AGENT_TYPE.getKeyValue(),"servlet")); return config; }
private void initAuthenticatorFromAuthMode() { String user = jolokiaConfig.get(ConfigKey.USER); String password = jolokiaConfig.get(ConfigKey.PASSWORD); String authMode = jolokiaConfig.get(ConfigKey.AUTH_MODE); String realm = jolokiaConfig.get(ConfigKey.REALM); } else if ("delegate".equalsIgnoreCase(authMode)) { authenticators.add(new DelegatingAuthenticator(realm, jolokiaConfig.get(ConfigKey.AUTH_URL), jolokiaConfig.get(ConfigKey.AUTH_PRINCIPAL_SPEC), jolokiaConfig.getAsBoolean(ConfigKey.AUTH_IGNORE_CERTS))); } else { throw new IllegalArgumentException("No auth method '" + authMode + "' known. " + authenticator = new MultiAuthenticator(MultiAuthenticator.Mode.fromString(jolokiaConfig.get(ConfigKey.AUTH_MATCH)), authenticators);
String dispatchers = pConfig.get(ConfigKey.DISPATCHER_CLASSES); String jsr160DispatcherClass = "org.jolokia.jsr160.Jsr160RequestDispatcher"; if (param != null && (param.isEmpty() || Boolean.parseBoolean(param))) { pConfig.updateGlobalConfiguration( Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), pConfig.updateGlobalConfiguration(Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher.class.getCanonicalName()));
private void initMBeans(Configuration pConfig) { int maxEntries = pConfig.getAsInt(HISTORY_MAX_ENTRIES); int maxDebugEntries = pConfig.getAsInt(DEBUG_MAX_ENTRIES); historyStore = new HistoryStore(maxEntries); debugStore = new DebugStore(maxDebugEntries, pConfig.getAsBoolean(DEBUG)); try { localDispatcher.initMBeans(historyStore, debugStore); } catch (NotCompliantMBeanException e) { intError("Error registering config MBean: " + e, e); } catch (MBeanRegistrationException e) { intError("Cannot register MBean: " + e, e); } catch (MalformedObjectNameException e) { intError("Invalid name for config MBean: " + e, e); } }
private String getHostName(InetSocketAddress address) { return configuration.getAsBoolean(ConfigKey.ALLOW_DNS_REVERSE_LOOKUP) ? address.getHostName() : null; }
private ProcessingParameters getProcessingParameter(Map<String, String[]> pParameterMap) { Map<String,String> ret = new HashMap<String, String>(); if (pParameterMap != null) { for (Map.Entry<String,String[]> entry : pParameterMap.entrySet()) { String values[] = entry.getValue(); if (values != null && values.length > 0) { ret.put(entry.getKey(), values[0]); } } } return config.getProcessingParameters(ret); }
String dispatchers = pConfig.get(ConfigKey.DISPATCHER_CLASSES); String jsr160DispatcherClass = "org.jolokia.jsr160.Jsr160RequestDispatcher"; if (param != null && (param.isEmpty() || Boolean.parseBoolean(param))) { pConfig.updateGlobalConfiguration( Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), pConfig.updateGlobalConfiguration(Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher.class.getCanonicalName()));
private void initMBeans(Configuration pConfig) { int maxEntries = pConfig.getAsInt(HISTORY_MAX_ENTRIES); int maxDebugEntries = pConfig.getAsInt(DEBUG_MAX_ENTRIES); historyStore = new HistoryStore(maxEntries); debugStore = new DebugStore(maxDebugEntries, pConfig.getAsBoolean(DEBUG)); try { localDispatcher.initMBeans(historyStore, debugStore); } catch (NotCompliantMBeanException e) { intError("Error registering config MBean: " + e, e); } catch (MBeanRegistrationException e) { intError("Cannot register MBean: " + e, e); } catch (MalformedObjectNameException e) { intError("Invalid name for config MBean: " + e, e); } }
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 ProcessingParameters getProcessingParameter(Map<String, String[]> pParameterMap) { Map<String,String> ret = new HashMap<String, String>(); if (pParameterMap != null) { for (Map.Entry<String,String[]> entry : pParameterMap.entrySet()) { String values[] = entry.getValue(); if (values != null && values.length > 0) { ret.put(entry.getKey(), values[0]); } } } return config.getProcessingParameters(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)); }
String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS); logHandler = logHandlerClass != null ? (LogHandler) ClassUtil.newInstance(logHandlerClass) : createLogHandler(pServletConfig,Boolean.valueOf(config.get(ConfigKey.DEBUG))); logHandler.info("Using custom access restriction provided by " + restrictor); configMimeType = config.get(ConfigKey.MIME_TYPE); allowDnsReverseLookup = config.getAsBoolean(ConfigKey.ALLOW_DNS_REVERSE_LOOKUP); streamingEnabled = config.getAsBoolean(ConfigKey.STREAMING);
String dispatchers = pConfig.get(ConfigKey.DISPATCHER_CLASSES); String jsr160DispatcherClass = "org.jolokia.jsr160.Jsr160RequestDispatcher"; if (param != null && (param.isEmpty() || Boolean.parseBoolean(param))) { pConfig.updateGlobalConfiguration( Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), pConfig.updateGlobalConfiguration(Collections.singletonMap( ConfigKey.DISPATCHER_CLASSES.getKeyValue(), Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher.class.getCanonicalName()));
/** * Initialize the configuration with the given map * * @param pConfig map holding the configuration in string representation. A reference to the map will be kept */ protected void init(Map<String, String> pConfig) { Map<String, String> finalCfg = getDefaultConfig(pConfig); finalCfg.putAll(pConfig); prepareDetectorOptions(finalCfg); addJolokiaId(finalCfg); jolokiaConfig = new Configuration(); jolokiaConfig.updateGlobalConfiguration(finalCfg); initConfigAndValidate(finalCfg); }
private void initMBeans(Configuration pConfig) { int maxEntries = pConfig.getAsInt(HISTORY_MAX_ENTRIES); int maxDebugEntries = pConfig.getAsInt(DEBUG_MAX_ENTRIES); historyStore = new HistoryStore(maxEntries); debugStore = new DebugStore(maxDebugEntries, pConfig.getAsBoolean(DEBUG)); try { localDispatcher.initMBeans(historyStore, debugStore); } catch (NotCompliantMBeanException e) { intError("Error registering config MBean: " + e, e); } catch (MBeanRegistrationException e) { intError("Cannot register MBean: " + e, e); } catch (MalformedObjectNameException e) { intError("Invalid name for config MBean: " + e, e); } }
private void addErrorInfo(JSONObject pErrorResp, Throwable pExp, JmxRequest pJmxReq) { if (config.getAsBoolean(ConfigKey.ALLOW_ERROR_DETAILS)) { String includeStackTrace = pJmxReq != null ? pJmxReq.getParameter(ConfigKey.INCLUDE_STACKTRACE) : "true"; if (includeStackTrace.equalsIgnoreCase("true") || (includeStackTrace.equalsIgnoreCase("runtime") && pExp instanceof RuntimeException)) { StringWriter writer = new StringWriter(); pExp.printStackTrace(new PrintWriter(writer)); pErrorResp.put("stacktrace", writer.toString()); } if (pJmxReq != null && pJmxReq.getParameterAsBool(ConfigKey.SERIALIZE_EXCEPTION)) { pErrorResp.put("error_value", backendManager.convertExceptionToJson(pExp, pJmxReq)); } } }
private ProcessingParameters getProcessingParameter(Map<String, String[]> pParameterMap) { Map<String,String> ret = new HashMap<String, String>(); if (pParameterMap != null) { for (Map.Entry<String,String[]> entry : pParameterMap.entrySet()) { String values[] = entry.getValue(); if (values != null && values.length > 0) { ret.put(entry.getKey(), values[0]); } } } return config.getProcessingParameters(ret); }
/** * Create a new HttpHandler for processing HTTP request * * @param pConfig jolokia specific config tuning the processing behaviour * @param pLogHandler log-handler the log handler to use for jolokia */ public JolokiaHttpHandler(Configuration pConfig, LogHandler pLogHandler) { configuration = pConfig; context = pConfig.get(ConfigKey.AGENT_CONTEXT); if (!context.endsWith("/")) { context += "/"; } logHandler = pLogHandler != null ? pLogHandler : createLogHandler(pConfig.get(ConfigKey.LOGHANDLER_CLASS), pConfig.get(ConfigKey.DEBUG)); }
String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS); logHandler = logHandlerClass != null ? (LogHandler) ClassUtil.newInstance(logHandlerClass) : createLogHandler(pServletConfig,Boolean.valueOf(config.get(ConfigKey.DEBUG))); logHandler.info("Using custom access restriction provided by " + restrictor); configMimeType = config.get(ConfigKey.MIME_TYPE); allowDnsReverseLookup = config.getAsBoolean(ConfigKey.ALLOW_DNS_REVERSE_LOOKUP); streamingEnabled = config.getAsBoolean(ConfigKey.STREAMING);