Exemplo n.º 1
0
  public String dumpRoutesAsXml() throws Exception {
    List<RouteDefinition> routes = context.getRouteDefinitions();
    if (routes.isEmpty()) {
      return null;
    }

    // use a routes definition to dump the routes
    RoutesDefinition def = new RoutesDefinition();
    def.setRoutes(routes);
    return ModelHelper.dumpModelAsXml(context, def);
  }
Exemplo n.º 2
0
  public void addOrUpdateRoutesFromXml(String xml, boolean urlDecode) throws Exception {
    // decode String as it may have been encoded, from its xml source
    if (urlDecode) {
      xml = URLDecoder.decode(xml, "UTF-8");
    }

    InputStream is = context.getTypeConverter().mandatoryConvertTo(InputStream.class, xml);
    RoutesDefinition def = context.loadRoutesDefinition(is);
    if (def == null) {
      return;
    }

    try {
      // add will remove existing route first
      context.addRouteDefinitions(def.getRoutes());
    } catch (Exception e) {
      // log the error as warn as the management api may be invoked remotely over JMX which does not
      // propagate such exception
      String msg = "Error updating routes from xml: " + xml + " due: " + e.getMessage();
      LOG.warn(msg, e);
      throw e;
    }
  }
Exemplo n.º 3
0
  @Override
  public void start(BundleContext bundleContext) throws Exception {
    try {
      this.bundleContext = bundleContext;
      log.debug("Initializing bundle {}.", bundleContext.getBundle().getBundleId());
      camelContext = createCamelContext();

      camelContext.addRoutes(this);
      ConfigurationAdmin configurationAdmin = requiredService(ConfigurationAdmin.class);
      Configuration camelKuraConfig = configurationAdmin.getConfiguration("kura.camel");
      if (camelKuraConfig != null && camelKuraConfig.getProperties() != null) {
        Object routePropertyValue = camelKuraConfig.getProperties().get(camelXmlRoutesProperty());
        if (routePropertyValue != null) {
          InputStream routesXml =
              new ByteArrayInputStream(routePropertyValue.toString().getBytes());
          RoutesDefinition loadedRoutes = camelContext.loadRoutesDefinition(routesXml);
          camelContext.addRouteDefinitions(loadedRoutes.getRoutes());
        }
      }

      beforeStart(camelContext);
      log.debug("About to start Camel Kura router: {}", getClass().getName());
      camelContext.start();
      producerTemplate = camelContext.createProducerTemplate();
      consumerTemplate = camelContext.createConsumerTemplate();
      log.debug("Bundle {} started.", bundleContext.getBundle().getBundleId());
    } catch (Throwable e) {
      String errorMessage = "Problem when starting Kura module " + getClass().getName() + ":";
      log.warn(errorMessage, e);

      // Print error to the Kura console.
      System.err.println(errorMessage);
      e.printStackTrace();

      throw e;
    }
  }