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 2017/12/15 09:37:22 UTC

[camel] branch master updated (958ff11 -> fd42ef2)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 958ff11  A component must have default no-arg constructor. This fixes issue with the camel-kafka-starter module.
     new 7bb1a66  CAMEL-12080: allow creating csvcontent without last eol
     new 55b0699  CAMEL-12080: documentation fix
     new fd42ef2  CAMEL-12080: removing trailing slashs

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/docs/bindy-dataformat.adoc            |  9 ++-
 .../camel/dataformat/bindy/BindyCsvFactory.java    |  9 +++
 .../dataformat/bindy/annotation/CsvRecord.java     |  5 ++
 .../dataformat/bindy/csv/BindyCsvDataFormat.java   | 14 ++--
 .../csv/BindyMarshalEndWithLineBreakTest.java      | 87 ++++++++++++++++++++++
 .../csv/{MyCsvRecord.java => MyCsvRecord2.java}    |  6 +-
 6 files changed, 119 insertions(+), 11 deletions(-)
 create mode 100644 components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
 copy components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/{MyCsvRecord.java => MyCsvRecord2.java} (91%)

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].

[camel] 01/03: CAMEL-12080: allow creating csvcontent without last eol

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7bb1a667fed9e521735091e64c4eb24a1e76d7d0
Author: Ricardo Zanini <ri...@gmail.com>
AuthorDate: Thu Dec 14 23:28:29 2017 -0200

    CAMEL-12080: allow creating csvcontent without last eol
---
 .../camel/dataformat/bindy/BindyCsvFactory.java    |   9 ++
 .../dataformat/bindy/annotation/CsvRecord.java     |   5 +
 .../dataformat/bindy/csv/BindyCsvDataFormat.java   |  14 ++-
 .../csv/BindyMarshalEndWithLineBreakTest.java      |  87 ++++++++++++++
 .../dataformat/bindy/model/csv/MyCsvRecord2.java   | 130 +++++++++++++++++++++
 5 files changed, 239 insertions(+), 6 deletions(-)

diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
index 994bed0..9906402 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
@@ -74,6 +74,7 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
     private boolean autospanLine;
     private boolean allowEmptyStream;
     private boolean quotingEscaped;
+    private boolean endWithLineBreak;
 
     public BindyCsvFactory(Class<?> type) throws Exception {
         super(type);
@@ -624,6 +625,10 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
                     // Get quotingEscaped parameter
                     quotingEscaped = record.quotingEscaped();
                     LOG.debug("Escape quote character flag of the CSV: {}" + quotingEscaped);
+                    
+                    // Get endWithLineBreak parameter
+                    endWithLineBreak = record.endWithLineBreak();
+                    LOG.debug("End with line break: {}" + endWithLineBreak);
                 }
 
                 if (section != null) {
@@ -710,4 +715,8 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor
     public boolean isAllowEmptyStream() {
         return allowEmptyStream;
     }
+    
+    public boolean isEndWithLineBreak() {
+        return endWithLineBreak;
+    }
 }
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
index 63f1d11..dd7bd18 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
@@ -95,5 +95,10 @@ public @interface CsvRecord {
      * the unavaiable stream for CSV file.
      */
     boolean allowEmptyStream() default false;
+    
+    /**
+     * The endWithLineBreak parameter flags if the CSV file should end with a line break or not (optional)
+     */
+    boolean endWithLineBreak() default true;
 
 }
diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
index ad24a99..00ea809 100755
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
@@ -94,16 +94,18 @@ public class BindyCsvDataFormat extends BindyAbstractDataFormat {
                 models.add(row);
             }
         }
-
-        for (Map<String, Object> model : models) {
-
-            String result = factory.unbind(getCamelContext(), model);
+        
+        Iterator<Map<String, Object>> modelsMap = models.iterator();
+        while (modelsMap.hasNext()) {
+            String result = factory.unbind(getCamelContext(), modelsMap.next());
 
             byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, result);
             outputStream.write(bytes);
 
-            // Add a carriage return
-            outputStream.write(bytesCRLF);
+            if (factory.isEndWithLineBreak() || modelsMap.hasNext()) {
+                // Add a carriage return
+                outputStream.write(bytesCRLF);
+            }
         }
     }
 
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
new file mode 100644
index 0000000..a404845
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.bindy.csv;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.model.csv.MyCsvRecord;
+import org.apache.camel.dataformat.bindy.model.csv.MyCsvRecord2;
+import org.apache.camel.dataformat.bindy.util.ConverterUtils;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BindyMarshalEndWithLineBreakTest extends CamelTestSupport {
+
+    @Test
+    public void testCsvWithEndingLineBreak() throws Exception {
+        final CsvRecord record = MyCsvRecord.class.getAnnotation(CsvRecord.class);
+        final MyCsvRecord csvRecord = new MyCsvRecord();
+        csvRecord.setAddressLine1("221b Baker Street");
+        csvRecord.setCity("London");
+        csvRecord.setCountry("England");
+        csvRecord.setAttention("1");
+        
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().convertToString().endsWith(ConverterUtils.getStringCarriageReturn(record.crlf()));
+        
+        template.sendBody("direct:withlb", csvRecord);
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Test
+    public void testCsvWithoutEndingLineBreak() throws Exception {
+        final CsvRecord record = MyCsvRecord2.class.getAnnotation(CsvRecord.class);
+        final MyCsvRecord2 csvRecord2 = new MyCsvRecord2();
+        csvRecord2.setAddressLine1("221b Baker Street");
+        csvRecord2.setCity("London");
+        csvRecord2.setCountry("England");
+        csvRecord2.setAttention("1");
+        
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().convertToString().endsWith(record.separator());
+        
+        template.sendBody("direct:withoutlb", csvRecord2);
+
+        assertMockEndpointsSatisfied();        
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:withoutlb") //
+                    .marshal().bindy(BindyType.Csv, MyCsvRecord2.class) //
+                    .to("log:after.unmarshal") //
+                    .to("mock:result"); //
+
+                from("direct:withlb") //
+                    .marshal().bindy(BindyType.Csv, MyCsvRecord.class) //
+                    .to("log:after.marshal") //
+                    .to("mock:result");
+            }
+        };
+    }
+}
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java
new file mode 100644
index 0000000..8b09765
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java
@@ -0,0 +1,130 @@
+/**
+ * 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.bindy.model.csv;
+
+import java.io.Serializable;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+
+@CsvRecord(separator = ",", skipFirstLine = false, endWithLineBreak = false)
+public class MyCsvRecord2 implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @DataField(pos = 1)
+    private String attention;
+    @DataField(pos = 2)
+    private String addressLine1;
+    @DataField(pos = 3)
+    private String addressLine2;
+    @DataField(pos = 4)
+    private String city;
+    @DataField(pos = 5)
+    private String state;
+    @DataField(pos = 6)
+    private String zip;
+    @DataField(pos = 7)
+    private String country;
+    @DataField(pos = 8)
+    private String dummy1;
+    @DataField(pos = 9)
+    private String dummy2;
+
+    public MyCsvRecord2() {
+    }
+
+    public String getAttention() {
+        return attention;
+    }
+
+    public void setAttention(String attention) {
+        this.attention = attention;
+    }
+
+    public String getAddressLine1() {
+        return addressLine1;
+    }
+
+    public void setAddressLine1(String addressLine1) {
+        this.addressLine1 = addressLine1;
+    }
+
+    public String getAddressLine2() {
+        return addressLine2;
+    }
+
+    public void setAddressLine2(String addressLine2) {
+        this.addressLine2 = addressLine2;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public String getDummy1() {
+        return dummy1;
+    }
+
+    public void setDummy1(String dummy1) {
+        this.dummy1 = dummy1;
+    }
+
+    public String getDummy2() {
+        return dummy2;
+    }
+
+    public void setDummy2(String dummy2) {
+        this.dummy2 = dummy2;
+    }
+
+    @Override
+    public String toString() {
+        return "Record [attention=" + attention + ", addressLine1=" + addressLine1 + ", addressLine2="
+               + addressLine2 + ", city=" + city + ", state=" + state + ", zip=" + zip + ", country="
+               + country + ", dummy1=" + dummy1 + ", dummy2=" + dummy2 + "]";
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.

[camel] 03/03: CAMEL-12080: removing trailing slashs

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fd42ef2450c2d2baae6ccdc85db0ca2d82b13355
Author: Ricardo Zanini <ri...@gmail.com>
AuthorDate: Fri Dec 15 07:21:54 2017 -0200

    CAMEL-12080: removing trailing slashs
---
 .../bindy/csv/BindyMarshalEndWithLineBreakTest.java        | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
index a404845..f8959e8 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalEndWithLineBreakTest.java
@@ -72,14 +72,14 @@ public class BindyMarshalEndWithLineBreakTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:withoutlb") //
-                    .marshal().bindy(BindyType.Csv, MyCsvRecord2.class) //
-                    .to("log:after.unmarshal") //
-                    .to("mock:result"); //
+                from("direct:withoutlb")
+                    .marshal().bindy(BindyType.Csv, MyCsvRecord2.class)
+                    .to("log:after.unmarshal")
+                    .to("mock:result");
 
-                from("direct:withlb") //
-                    .marshal().bindy(BindyType.Csv, MyCsvRecord.class) //
-                    .to("log:after.marshal") //
+                from("direct:withlb")
+                    .marshal().bindy(BindyType.Csv, MyCsvRecord.class)
+                    .to("log:after.marshal")
                     .to("mock:result");
             }
         };

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.

[camel] 02/03: CAMEL-12080: documentation fix

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 55b069935925e7aca5f2404663aebf52deda1caa
Author: Ricardo Zanini <ri...@gmail.com>
AuthorDate: Fri Dec 15 00:22:52 2017 -0200

    CAMEL-12080: documentation fix
---
 components/camel-bindy/src/main/docs/bindy-dataformat.adoc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/components/camel-bindy/src/main/docs/bindy-dataformat.adoc b/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
index aa34c70..3153fab 100644
--- a/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
+++ b/components/camel-bindy/src/main/docs/bindy-dataformat.adoc
@@ -108,8 +108,8 @@ to several children model classes.
 
 |separator |string |mandatory - can be ',' or ';' or 'anything'. This value is interpreted
 as a regular expression. If you want to use a sign which has a special
-meaning in regular expressions, e.g. the '|' sign, than you have to mask
-it, like '|'
+meaning in regular expressions, e.g. the '\|' sign, than you have to mask
+it, like '\|'
 
 |skipFirstLine |boolean |optional - default value = false - allow to skip the first line of the
 CSV file
@@ -136,6 +136,11 @@ declared one time.
 
 |quoting |boolean |*Camel 2.11:*optional - default value = false - Indicate if the values
 must be quoted when marshaling when CSV is generated.
+
+|endWithLineBreak |boolean |*Camel 2.21:* optional - default value = true - Indicate if the CSV generated file 
+should end with a line break.
+
+|
 |=======================================================================
 
 *case 1 : separator = ','*

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.