Uploaded image for project: 'ServiceMix'
  1. ServiceMix
  2. SM-1315

Enhance logging inside TraceComponent.java to log NormalizedMassage properties

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.2, 3.2.1
    • 3.2.2, 3.3
    • None
    • None
    • Patch Available

    Description

      Add more logging to TraceComponent.java, for the following:

      • NormalizedMassage.getPropertyNames(): get the objects in some string format.
      • If NormalizedMassage.getProperty() is of type javax.xml.transform.Source, convert the type of a String for logging

      See below code for possible example:

      /**
           * Outputs the properties on the {@link NormalizedMessage}. Properties of 
           * type {@link Source} are transformed to a {@link String} before 
           * being output.
           *
           * @param message The {@link NormalizedMessage} to be processed
           */
          @SuppressWarnings("unchecked")
          protected void outputProperties(NormalizedMessage message) {
              // Loop over all the properties on the normalized message 
              for (Object o : message.getPropertyNames()) {
                  // NormalizedMessage API does not use generics. This interface is
                  // written in Java older than 5.0. On the basis of other methods and
                  // the default implementation of this interface we can assume that
                  // only String keys are allowed.
                  String key = (String) o;
                  try {
                      Object contents = message.getProperty(key);
                      // Is this the only value type that we would like to treat
                      // differently? The default behavior is to invoke toString() on
                      // the object.
                      if (contents instanceof Source) {
                          contents = getSourceTransformer().toString((Source) contents);
                      }
      
                      log.info("Value for property '" + key + "' is: " + contents);
                  } catch (TransformerException e) {
                      log.error("Failed to turn property '" + key + "' value into text: " + e, e);
                  }
              }
          }
      

      Attachments

        Activity

          People

            bsnyder Bruce Snyder
            bsnyder Bruce Snyder
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: