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/08/26 19:40:09 UTC

[2/2] git commit: CAMEL-6187: http producer should use charset from content-type as fallback. Thanks to Fried Hoeben for solution.

CAMEL-6187: http producer should use charset from content-type as fallback. Thanks to Fried Hoeben for solution.


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

Branch: refs/heads/camel-2.11.x
Commit: 7f149a59b450043cf463cc76452e26baf09b7e3c
Parents: a22ffb8
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Aug 26 19:39:23 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Aug 26 19:39:52 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/component/http4/HttpProducer.java  | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7f149a59/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index fb5489b..135c0ec 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -24,6 +24,7 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -422,6 +423,13 @@ public class HttpProducer extends DefaultProducer {
                         // do not fallback to use the default charset as it can influence the request
                         // (for example application/x-www-form-urlencoded forms being sent)
                         String charset = IOHelper.getCharsetName(exchange, false);
+                        if (charset == null && contentType != null) {
+                            // okay try to get the charset from the content-type
+                            Charset cs = contentType.getCharset();
+                            if (cs != null) {
+                                charset = cs.name();
+                            }
+                        }
                         StringEntity entity = new StringEntity((String) data, charset);
                         if (contentType != null) {
                             entity.setContentType(contentType.toString());