Beispiel #1
0
 @SuppressWarnings("PMD.SystemPrintln")
 private void logError(String message, Throwable throwable) {
   ServiceReference lRef = bundleContext.getServiceReference(LogService.class.getName());
   if (lRef != null) {
     try {
       LogService logService = (LogService) bundleContext.getService(lRef);
       if (logService != null) {
         logService.log(LogService.LOG_ERROR, message, throwable);
         return;
       }
     } finally {
       bundleContext.ungetService(lRef);
     }
   }
   System.err.println("Jolokia-Error: " + message + " : " + throwable.getMessage());
 }
Beispiel #2
0
 private String getConfiguration(ConfigKey pKey) {
   // TODO: Use fragments and/or configuration service if available.
   String value = bundleContext.getProperty(CONFIG_PREFIX + "." + pKey.getKeyValue());
   if (value == null) {
     value = pKey.getDefaultValue();
   }
   return value;
 }
Beispiel #3
0
 private Filter buildHttpServiceFilter(BundleContext pBundleContext) {
   String customFilter = getConfiguration(ConfigKey.HTTP_SERVICE_FILTER);
   String filter =
       customFilter.trim().length() > 0
           ? "(&" + HTTP_SERVICE_FILTER_BASE + customFilter + ")"
           : HTTP_SERVICE_FILTER_BASE;
   try {
     return pBundleContext.createFilter(filter);
   } catch (InvalidSyntaxException e) {
     throw new IllegalArgumentException("Unable to parse filter " + filter, e);
   }
 }
Beispiel #4
0
 /** {@inheritDoc} */
 public Object addingService(ServiceReference reference) {
   HttpService service = (HttpService) context.getService(reference);
   try {
     service.registerServlet(
         getServletAlias(),
         new JolokiaServlet(context, restrictor),
         getConfiguration(),
         getHttpContext());
   } catch (ServletException e) {
     logError("Servlet Exception: " + e, e);
   } catch (NamespaceException e) {
     logError("Namespace Exception: " + e, e);
   }
   return service;
 }
Beispiel #5
0
  /** {@inheritDoc} */
  public void stop(BundleContext pBundleContext) {
    assert pBundleContext.equals(bundleContext);

    if (httpServiceTracker != null) {
      // Closing the tracker will also call {@link HttpServiceCustomizer#removedService()}
      // for every active service which in turn unregisters the servlet
      httpServiceTracker.close();
      httpServiceTracker = null;
    }

    if (jolokiaServiceRegistration != null) {
      jolokiaServiceRegistration.unregister();
      jolokiaServiceRegistration = null;
    }

    restrictor = null;
    bundleContext = null;
  }
Beispiel #6
0
  /** {@inheritDoc} */
  public void start(BundleContext pBundleContext) {
    bundleContext = pBundleContext;

    if (Boolean.parseBoolean(getConfiguration(USE_RESTRICTOR_SERVICE))) {
      // If no restrictor is set in the constructor and we are enabled to listen for a restrictor
      // service, a delegating restrictor is installed
      restrictor = new DelegatingRestrictor(bundleContext);
    }

    // Track HttpService
    if (Boolean.parseBoolean(getConfiguration(LISTEN_FOR_HTTP_SERVICE))) {
      httpServiceTracker =
          new ServiceTracker(
              pBundleContext,
              buildHttpServiceFilter(pBundleContext),
              new HttpServiceCustomizer(pBundleContext));
      httpServiceTracker.open();

      // Register us as JolokiaContext
      jolokiaServiceRegistration =
          pBundleContext.registerService(JolokiaContext.class.getCanonicalName(), this, null);
    }
  }