camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [11/11] git commit: CAMEL-5771 IOHelper.getCharsetName() should lookup CHARSET_NAME in headers if exchange property is not set
Date Sat, 28 Sep 2013 11:45:54 GMT
CAMEL-5771 IOHelper.getCharsetName() should lookup CHARSET_NAME in headers if exchange property
is not set

Conflicts:
	camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java


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

Branch: refs/heads/camel-2.11.x
Commit: 499fb031966edc69ad1e1c5b5344c1188534873d
Parents: 8f8f2e9
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Sep 28 12:46:29 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Sep 28 13:44:58 2013 +0200

----------------------------------------------------------------------
 .../org/apache/camel/converter/IOConverter.java    |  2 +-
 .../main/java/org/apache/camel/util/IOHelper.java  | 12 ++++++++----
 .../java/org/apache/camel/util/IOHelperTest.java   | 17 +++++++++++++++++
 3 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/499fb031/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
index 269b948..2c12d11 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -428,7 +428,7 @@ public final class IOConverter {
     }
 
     /**
-     * Gets the charset name if set as property {@link Exchange#CHARSET_NAME}.
+     * Gets the charset name if set as header or property {@link Exchange#CHARSET_NAME}.
      *
      * @param exchange  the exchange
      * @param useDefault should we fallback and use JVM default charset if no property existed?

http://git-wip-us.apache.org/repos/asf/camel/blob/499fb031/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
index 179d526..e2fdfaf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
@@ -385,13 +385,16 @@ public final class IOHelper {
         }
     }
 
+    /**
+     * @see #getCharsetName(org.apache.camel.Exchange, boolean)
+     */
     public static String getCharsetName(Exchange exchange) {
         return getCharsetName(exchange, true);
     }
 
     /**
-     * Gets the charset name if set as property or header {@link Exchange#CHARSET_NAME}.
-     * Notice: The lookup from the property has priority over the header
+     * Gets the charset name if set as header or property {@link Exchange#CHARSET_NAME}.
+     * <b>Notice:</b> The lookup from the header has priority over the property.
      *
      * @param exchange  the exchange
      * @param useDefault should we fallback and use JVM default charset if no property existed?
@@ -399,9 +402,10 @@ public final class IOHelper {
      */
     public static String getCharsetName(Exchange exchange, boolean useDefault) {
         if (exchange != null) {
-            String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+            // header takes precedence
+            String charsetName = exchange.getIn().getHeader(Exchange.CHARSET_NAME, String.class);
             if (charsetName == null) {
-                charsetName = exchange.getIn().getHeader(Exchange.CHARSET_NAME, String.class);
+                charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
             }
             if (charsetName != null) {
                 return IOHelper.normalizeCharset(charsetName);

http://git-wip-us.apache.org/repos/asf/camel/blob/499fb031/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
index 0e2231f..a980cbd 100644
--- a/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
@@ -23,6 +23,9 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
 
 /**
  * @version 
@@ -63,4 +66,18 @@ public class IOHelperTest extends TestCase {
         assertEquals("UTF-8", IOHelper.normalizeCharset("\"UTF-8 \""));
         assertEquals("UTF-8", IOHelper.normalizeCharset("\' UTF-8\'"));
     }
+
+    public void testCharsetName() throws Exception {
+        Exchange exchange = new DefaultExchange((CamelContext) null);
+
+        assertNull(IOHelper.getCharsetName(exchange, false));
+
+        exchange.getIn().setHeader(Exchange.CHARSET_NAME, "iso-8859-1");
+        assertEquals("iso-8859-1", IOHelper.getCharsetName(exchange, false));
+
+        exchange.getIn().removeHeader(Exchange.CHARSET_NAME);
+        exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");
+        assertEquals("iso-8859-1", IOHelper.getCharsetName(exchange, false));
+    }
+
 }


Mime
View raw message