Repository: camel
Updated Branches:
  refs/heads/master 23b13a1e1 -> 920a88d2c


CAMEL-10147: MesssageHistory will take very long time for large expressions

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

Branch: refs/heads/master
Commit: 920a88d2ce75bf5d7204d0984c9eed5136bb60d2
Parents: 23b13a1
Author: Stephan Siano <stephan.si...@sap.com>
Authored: Thu Jul 14 14:23:59 2016 +0200
Committer: Stephan Siano <stephan.si...@sap.com>
Committed: Fri Jul 15 08:51:34 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/util/MessageHelper.java     |  5 ++++-
 .../main/java/org/apache/camel/util/StringHelper.java | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/920a88d2/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
index 2eeac61..524d246 100644
--- a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
@@ -570,7 +570,10 @@ public final class MessageHelper {
             routeId = history.getRouteId() != null ? history.getRouteId() : "";
             id = history.getNode().getId();
             // we need to avoid leak the sensible information here
-            label =  URISupport.sanitizeUri(history.getNode().getLabel());
+            // the sanitizeUri takes a very long time for very long string and 
the format cuts this to
+            // 78 characters, anyway. Cut this to 100 characters. This will 
give enough space for removing
+            // characters in the sanitizeUri method and will be reasonably fast
+            label =  
URISupport.sanitizeUri(StringHelper.limitLenght(history.getNode().getLabel(), 
100));            
             elapsed = history.getElapsed();
 
             sb.append(String.format(MESSAGE_HISTORY_OUTPUT, routeId, id, 
label, elapsed));

http://git-wip-us.apache.org/repos/asf/camel/blob/920a88d2/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index c8f1000..1fa6852 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -68,6 +68,20 @@ public final class StringHelper {
         return matches;
     }
 
+    /**
+     * Limits the length of a string
+     * 
+     * @param s the string
+     * @param maxLength the maximum length of the returned string
+     * @return s if the length of s is less than maxLength or the first 
maxLength characters of s
+     */
+    public static String limitLenght(String s, int maxLength) {
+        if (ObjectHelper.isEmpty(s)) {
+            return s;
+        }
+        return s.length() <= maxLength ? s : s.substring(0, maxLength);
+    }
+
     public static String removeQuotes(String s) {
         if (ObjectHelper.isEmpty(s)) {
             return s;

Reply via email to