You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/09/28 13:45:50 UTC

[07/11] git commit: CAMEL-5771 IOHelper.getCharsetName() should lookup CHARSET_NAME in headers if exchange property is not set

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/93743f59
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/93743f59
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/93743f59

Branch: refs/heads/camel-2.12.x
Commit: 93743f597d52f238f21ef52772c60c155430c9fb
Parents: 3b03265
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Sep 28 12:46:29 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Sep 28 13:44:11 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/93743f59/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 8107b49..02995fa 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/93743f59/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 e7d9184..8a52b5b 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
@@ -412,13 +412,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?
@@ -426,9 +429,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/93743f59/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));
+    }
+
 }