Example #1
0
  /**
   * Initialize the backend systems, the log handler and the restrictor. A subclass can tune this
   * step by overriding {@link #createRestrictor(String)} and {@link
   * #createLogHandler(ServletConfig, boolean)}
   *
   * @param pServletConfig servlet configuration
   */
  @Override
  public void init(ServletConfig pServletConfig) throws ServletException {
    super.init(pServletConfig);

    Configuration config = initConfig(pServletConfig);

    // Create a log handler early in the lifecycle, but not too early
    String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS);
    logHandler =
        logHandlerClass != null
            ? (LogHandler) ClassUtil.newInstance(logHandlerClass)
            : createLogHandler(pServletConfig, Boolean.valueOf(config.get(ConfigKey.DEBUG)));

    // Different HTTP request handlers
    httpGetHandler = newGetHttpRequestHandler();
    httpPostHandler = newPostHttpRequestHandler();

    if (restrictor == null) {
      restrictor =
          createRestrictor(NetworkUtil.replaceExpression(config.get(ConfigKey.POLICY_LOCATION)));
    } else {
      logHandler.info("Using custom access restriction provided by " + restrictor);
    }
    configMimeType = config.get(ConfigKey.MIME_TYPE);
    backendManager = new BackendManager(config, logHandler, restrictor);
    requestHandler = new HttpRequestHandler(config, backendManager, logHandler);

    initDiscoveryMulticast(config);
  }
 protected JolokiaHandler(Map<String, String> configParameters, Restrictor restrictor) {
   log = new JolokiaLogHandler(LoggerFactory.getLogger(JolokiaHandler.class));
   Configuration config = initConfig(configParameters);
   if (restrictor == null) {
     restrictor =
         createRestrictor(NetworkUtil.replaceExpression(config.get(ConfigKey.POLICY_LOCATION)));
   }
   log.info("Using restrictor " + restrictor);
   BackendManager backendManager = new BackendManager(config, log, restrictor);
   requestHandler = new HttpRequestHandler(config, backendManager, log);
 }
Example #3
0
 private void initLimits(Configuration pConfig) {
   // Max traversal depth
   if (pConfig != null) {
     convertOptionsBuilder =
         new JsonConvertOptions.Builder(
             getNullSaveIntLimit(pConfig.get(MAX_DEPTH)),
             getNullSaveIntLimit(pConfig.get(MAX_COLLECTION_SIZE)),
             getNullSaveIntLimit(pConfig.get(MAX_OBJECTS)));
   } else {
     convertOptionsBuilder = new JsonConvertOptions.Builder();
   }
 }
Example #4
0
  // Examines servlet config and servlet context for configuration parameters.
  // Configuration from the servlet context overrides servlet parameters defined in web.xml
  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;
  }
Example #5
0
  // init various application wide stores for handling history and debug output.
  private void initStores(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);
    }
  }
Example #6
0
 // For war agent needs to be switched on
 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;
 }
Example #7
0
 // Try to find an URL for system props or config
 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);
 }
Example #8
0
  // Initialize this object;
  private void init(Configuration pConfig) {
    // Central objects
    converters = new Converters();
    initLimits(pConfig);

    // Create and remember request dispatchers
    localDispatcher = new LocalRequestDispatcher(converters, restrictor, pConfig, logHandler);
    ServerHandle serverHandle = localDispatcher.getServerInfo();
    requestDispatchers =
        createRequestDispatchers(
            pConfig.get(DISPATCHER_CLASSES), converters, serverHandle, restrictor);
    requestDispatchers.add(localDispatcher);

    // Backendstore for remembering agent state
    initStores(pConfig);
  }
 protected Configuration initConfig(Map<String, String> params) {
   Configuration config =
       new Configuration(ConfigKey.AGENT_ID, NetworkUtil.getAgentId(hashCode(), "vertx"));
   config.updateGlobalConfiguration(params);
   return config;
 }