servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r648484 - /servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java
Date Wed, 16 Apr 2008 02:48:05 GMT
Author: bsnyder
Date: Tue Apr 15 19:48:01 2008
New Revision: 648484

URL: http://svn.apache.org/viewvc?rev=648484&view=rev
Log:
SM-1315 - Enhance logging inside TraceComponent.java to log NormalizedMassage properties

Modified:
    servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java

Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java?rev=648484&r1=648483&r2=648484&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java
Tue Apr 15 19:48:01 2008
@@ -19,6 +19,7 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 
 import org.apache.commons.logging.Log;
@@ -54,8 +55,14 @@
         this.sourceTransformer = sourceTransformer;
     }
 
+    /** 
+     * Intercepts the {@link MessageExchange} to output the message and its 
+     * properties for debugging purposes. 
+     * 
+     * @param exchange A JBI {@link MessageExchange} between two endpoints
+     */
     public void onMessageExchange(MessageExchange exchange) throws MessagingException {
-        // lets dump the incoming message
+        // lets dump the incoming message  
         NormalizedMessage message = exchange.getMessage("in");
         if (message == null) {
             log.warn("Received null message from exchange: " + exchange);
@@ -66,7 +73,40 @@
             } catch (TransformerException e) {
                 log.error("Failed to turn message body into text: " + e, e);
             }
+            outputProperties(message);
         }
         done(exchange);
+    }
+    
+    /**
+     * 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);
+            }
+        }
     }
 }



Mime
View raw message