camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7358 Fixed the OutOfMemoryError when enable the trace option
Date Sun, 20 Apr 2014 14:41:48 GMT
CAMEL-7358 Fixed the OutOfMemoryError when enable the trace option


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5b6fbf01
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5b6fbf01
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5b6fbf01

Branch: refs/heads/master
Commit: 5b6fbf0120671735435c9607687919f81f65a61d
Parents: 44b522a
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Apr 18 14:04:34 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Sun Apr 20 22:40:19 2014 +0800

----------------------------------------------------------------------
 .../interceptor/DefaultTraceEventMessage.java    |  3 ++-
 .../DefaultTraceEventMessageTest.java            | 19 +++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5b6fbf01/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessage.java
b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessage.java
index 28caffb..8b2d08a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessage.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessage.java
@@ -72,7 +72,8 @@ public final class DefaultTraceEventMessage implements Serializable, TraceEventM
         this.exchangePattern = exchange.getPattern().toString();
         this.properties = exchange.getProperties().isEmpty() ? null : exchange.getProperties().toString();
         this.headers = in.getHeaders().isEmpty() ? null : in.getHeaders().toString();
-        this.body = MessageHelper.extractBodyAsString(in);
+        // We should not turn the message body into String
+        this.body = MessageHelper.extractBodyForLogging(in, "");
         this.bodyType = MessageHelper.getBodyTypeName(in);
         if (exchange.hasOut()) {
             Message out = exchange.getOut();

http://git-wip-us.apache.org/repos/asf/camel/blob/5b6fbf01/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessageTest.java
b/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessageTest.java
index a021173..dd22be0 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceEventMessageTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.processor.interceptor;
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.util.Date;
 
 import org.apache.camel.ContextTestSupport;
@@ -68,11 +70,24 @@ public class DefaultTraceEventMessageTest extends ContextTestSupport {
         assertEquals("String", em.getOutBodyType());
         assertEquals("{cheese=789}", em.getOutHeaders());
     }
-
+    
+    public void testDefaultTraceEventMessageBody() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new File("target/test"));
+        DefaultTraceEventMessage em = new DefaultTraceEventMessage(new Date(), null, exchange);
+        
+        assertEquals("Get a wrong body string", "[Body is file based: target/test]", em.getBody());
+        
+        exchange.getIn().setBody(new ByteArrayInputStream("target/test".getBytes()));
+        em = new DefaultTraceEventMessage(new Date(), null, exchange);
+        
+        assertEquals("Get a wrong body string", "[Body is instance of java.io.InputStream]",
em.getBody());
+    }
+ 
     public void testDefaultTraceEventMessageOptions() throws Exception {
         Exchange exchange = new DefaultExchange(context);
         DefaultTraceEventMessage em = new DefaultTraceEventMessage(new Date(), null, exchange);
-
+        
         em.setBody("Hello World");
         assertEquals("Hello World", em.getBody());
 


Mime
View raw message