Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x e11056e84 -> fead65afd


CAMEL-9933: Camel-CSV marshalling breaks characters not in default charset

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

Branch: refs/heads/camel-2.17.x
Commit: fead65afdefdb85a3e49e6ba191050749afec9cb
Parents: e11056e
Author: Stephan Siano <[email protected]>
Authored: Mon May 2 07:18:19 2016 +0200
Committer: Stephan Siano <[email protected]>
Committed: Mon May 2 11:19:49 2016 +0200

----------------------------------------------------------------------
 .../camel/dataformat/csv/CsvMarshaller.java     |  2 +-
 .../dataformat/csv/CsvMarshalCharsetTest.java   | 74 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fead65af/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
----------------------------------------------------------------------
diff --git 
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
 
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
index 2764d5e..2d80616 100644
--- 
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
+++ 
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
@@ -73,7 +73,7 @@ abstract class CsvMarshaller {
      * @throws IOException                        if we cannot write into the 
given stream
      */
     public void marshal(Exchange exchange, Object object, OutputStream 
outputStream) throws NoTypeConversionAvailableException, IOException {
-        CSVPrinter printer = new CSVPrinter(new 
OutputStreamWriter(outputStream), format);
+        CSVPrinter printer = new CSVPrinter(new 
OutputStreamWriter(outputStream, IOHelper.getCharsetName(exchange)), format);
         try {
             Iterator it = ObjectHelper.createIterator(object);
             while (it.hasNext()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/fead65af/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalCharsetTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalCharsetTest.java
 
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalCharsetTest.java
new file mode 100644
index 0000000..3e23e66
--- /dev/null
+++ 
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalCharsetTest.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.csv;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.hamcrest.core.StringStartsWith.startsWith;
+
+public class CsvMarshalCharsetTest extends CamelTestSupport {
+
+    @Test
+    public void testMarshal() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint("mock:daltons");
+        endpoint.expectedMessageCount(1);
+
+        List<List<String>> data = new ArrayList<List<String>>();
+        data.add(0, new ArrayList<String>());
+        data.get(0).add(0, "L\u00fccky Luke");
+        Exchange in = createExchangeWithBody(data);
+        in.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
+        template.send("direct:start", in);
+
+        endpoint.assertIsSatisfied();
+
+        Exchange exchange = endpoint.getExchanges().get(0);
+        String body = exchange.getIn().getBody(String.class);
+        assertThat(body, startsWith("L\u00fccky Luke"));
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").marshal().csv().to("mock:daltons");
+            }
+        };
+    }
+}

Reply via email to