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:46 UTC
[03/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
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e73ed4ce
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e73ed4ce
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e73ed4ce
Branch: refs/heads/master
Commit: e73ed4ce0ef9a4b57a2cb8176f9dd6ea779b80cd
Parents: 48e3d8d
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 12:50:33 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 | 16 ++++++++++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e73ed4ce/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/e73ed4ce/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 78f75c9..efd8b56 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/e73ed4ce/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 9329ace..ac2e5ff 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
@@ -26,6 +26,9 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
/**
* @version
@@ -99,4 +102,17 @@ public class IOHelperTest extends TestCase {
out.print(text);
out.close();
}
+
+ 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));
+ }
}