camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject camel git commit: CAMEL-9933: Camel-CSV marshalling breaks characters not in default charset
Date Mon, 02 May 2016 09:50:08 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 3971a368b -> d5197cc7d


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

Branch: refs/heads/camel-2.16.x
Commit: d5197cc7d2ca9cd6230854febe53590ad1a76bae
Parents: 3971a36
Author: Stephan Siano <stephan.siano@sap.com>
Authored: Mon May 2 07:18:19 2016 +0200
Committer: Stephan Siano <stephan.siano@sap.com>
Committed: Mon May 2 11:47:33 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/d5197cc7/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/d5197cc7/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");
+            }
+        };
+    }
+}


Mime
View raw message