camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1174692 - in /camel/branches/camel-2.7.x: ./ camel-core/src/main/java/org/apache/camel/util/MessageHelper.java camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
Date Fri, 23 Sep 2011 12:13:18 GMT
Author: davsclaus
Date: Fri Sep 23 12:13:17 2011
New Revision: 1174692

URL: http://svn.apache.org/viewvc?rev=1174692&view=rev
Log:
Merged revisions 1146608 via svnmerge from 
https://svn.apache.org/repos/asf/camel/branches/camel-2.8.x


Modified:
    camel/branches/camel-2.7.x/   (props changed)
    camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
    camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep 23 12:13:17 2011
@@ -1,2 +1,2 @@
 /camel/branches/camel-2.8.x:1174571
-/camel/trunk:1146903,1147216,1174565
+/camel/trunk:1146608,1146903,1147216,1174565

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Sep 23 12:13:17 2011
@@ -1 +1 @@
-/camel/branches/camel-2.8.x:1-1146127,1146653,1146771,1146903,1147216,1174571
+/camel/branches/camel-2.8.x:1-1146127,1146608,1146653,1146771,1146903,1147216,1174571

Modified: camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=1174692&r1=1174691&r2=1174692&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
(original)
+++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
Fri Sep 23 12:13:17 2011
@@ -182,4 +182,26 @@ public final class MessageHelper {
         return "Message: " + body;
     }
 
+    /**
+     * Copies the headers from the source to the target message.
+     *
+     * @param source the source message
+     * @param target the target message
+     * @param override whether to override existing headers
+     */
+    public static void copyHeaders(Message source, Message target, boolean override) {
+        if (!source.hasHeaders()) {
+            return;
+        }
+
+        for (Map.Entry<String, Object> entry : source.getHeaders().entrySet()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+
+            if (target.getHeader(key) == null || override) {
+                target.setHeader(key, value);
+            }
+        }
+    }
+
 }

Modified: camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java?rev=1174692&r1=1174691&r2=1174692&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
(original)
+++ camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
Fri Sep 23 12:13:17 2011
@@ -70,4 +70,32 @@ public class MessageHelperTest extends T
         assertEquals("iso-8859-1", MessageHelper.getContentEncoding(message));
     }
 
+    public void testCopyHeaders() throws Exception {
+        Message source = message;
+        Message target = new DefaultMessage();
+
+        source.setHeader("foo", 123);
+        source.setHeader("bar", 456);
+        target.setHeader("bar", "yes");
+
+        MessageHelper.copyHeaders(source, target, false);
+
+        assertEquals(123, target.getHeader("foo"));
+        assertEquals("yes", target.getHeader("bar"));
+    }
+
+    public void testCopyHeadersOverride() throws Exception {
+        Message source = message;
+        Message target = new DefaultMessage();
+
+        source.setHeader("foo", 123);
+        source.setHeader("bar", 456);
+        target.setHeader("bar", "yes");
+
+        MessageHelper.copyHeaders(source, target, true);
+
+        assertEquals(123, target.getHeader("foo"));
+        assertEquals(456, target.getHeader("bar"));
+    }
+
 }



Mime
View raw message