You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by si...@apache.org on 2016/05/02 09:08:24 UTC
camel git commit: CAMEL-9933: Camel-CSV marshalling breaks characters
not in default charset
Repository: camel
Updated Branches:
refs/heads/master 802c3dbb5 -> 0149a2239
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/0149a223
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0149a223
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0149a223
Branch: refs/heads/master
Commit: 0149a2239ea30a31b87d6c49bae994a8ef2e7978
Parents: 802c3db
Author: Stephan Siano <st...@sap.com>
Authored: Mon May 2 07:18:19 2016 +0200
Committer: Stephan Siano <st...@sap.com>
Committed: Mon May 2 09:07:50 2016 +0200
----------------------------------------------------------------------
.../camel/dataformat/csv/CsvMarshaller.java | 3 +-
.../dataformat/csv/CsvMarshalCharsetTest.java | 74 ++++++++++++++++++++
2 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0149a223/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..58c82c8 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
@@ -29,6 +29,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.MessageHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
@@ -73,7 +74,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/0149a223/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");
+ }
+ };
+ }
+}