Example #1
0
  public String dumpRoutesCoverageAsXml() throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("<camelContextRouteCoverage")
        .append(
            String.format(
                " id=\"%s\" exchangesTotal=\"%s\" totalProcessingTime=\"%s\"",
                getCamelId(), getExchangesTotal(), getTotalProcessingTime()))
        .append(">\n");

    String xml = dumpRoutesAsXml();
    if (xml != null) {
      // use the coverage xml parser to dump the routes and enrich with coverage stats
      Document dom =
          RouteCoverageXmlParser.parseXml(context, new ByteArrayInputStream(xml.getBytes()));
      // convert dom back to xml
      String converted = context.getTypeConverter().convertTo(String.class, dom);
      sb.append(converted);
    }

    sb.append("\n</camelContextRouteCoverage>");
    return sb.toString();
  }
Example #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;
    }
  }