You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/08/30 19:21:23 UTC

[camel-quarkus] branch master updated: CSV Extension

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ee298c0  CSV Extension
     new 37eba37  Merge pull request #167 from ppalaga/190828-csv
ee298c0 is described below

commit ee298c02ba22dfa4d8276aa32eabdb4fd4fc4fa1
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Fri Aug 30 20:31:50 2019 +0200

    CSV Extension
---
 .../ROOT/pages/_partials/component-extensions.adoc |   1 +
 extensions/csv/deployment/pom.xml                  |  57 ++++++++++
 .../component/csv/deployment/CsvProcessor.java     |  15 +++
 extensions/csv/pom.xml                             |  21 ++++
 extensions/csv/runtime/pom.xml                     |  60 +++++++++++
 extensions/pom.xml                                 |   1 +
 integration-tests/csv/pom.xml                      | 118 +++++++++++++++++++++
 .../quarkus/component/csv/it/CsvResource.java      |  66 ++++++++++++
 .../quarkus/component/csv/it/CsvRouteBuilder.java  |  28 +++++
 .../camel/quarkus/component/csv/it/CsvIT.java      |   8 ++
 .../camel/quarkus/component/csv/it/CsvTest.java    |  38 +++++++
 integration-tests/pom.xml                          |   1 +
 poms/bom-deployment/pom.xml                        |   5 +
 poms/bom/pom.xml                                   |  20 +++-
 14 files changed, 434 insertions(+), 5 deletions(-)

diff --git a/docs/modules/ROOT/pages/_partials/component-extensions.adoc b/docs/modules/ROOT/pages/_partials/component-extensions.adoc
index d0c8f42..7698774 100644
--- a/docs/modules/ROOT/pages/_partials/component-extensions.adoc
+++ b/docs/modules/ROOT/pages/_partials/component-extensions.adoc
@@ -4,6 +4,7 @@
 * `camel-quarkus-aws-sns`
 * `camel-quarkus-aws-sqs`
 * `camel-quarkus-bean`
+* `camel-quarkus-csv`
 * `camel-quarkus-direct`
 * `camel-quarkus-infinispan`
 * `camel-quarkus-jdbc`
diff --git a/extensions/csv/deployment/pom.xml b/extensions/csv/deployment/pom.xml
new file mode 100644
index 0000000..8150e21
--- /dev/null
+++ b/extensions/csv/deployment/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-csv-parent</artifactId>
+        <version>0.1.1-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-csv-deployment</artifactId>
+    <name>Camel Quarkus :: CSV :: Deployment</name>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-bom-deployment</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-core-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-csv</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            <artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/extensions/csv/deployment/src/main/java/org/apache/camel/quarkus/component/csv/deployment/CsvProcessor.java b/extensions/csv/deployment/src/main/java/org/apache/camel/quarkus/component/csv/deployment/CsvProcessor.java
new file mode 100644
index 0000000..50600bf
--- /dev/null
+++ b/extensions/csv/deployment/src/main/java/org/apache/camel/quarkus/component/csv/deployment/CsvProcessor.java
@@ -0,0 +1,15 @@
+package org.apache.camel.quarkus.component.csv.deployment;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+
+class CsvProcessor {
+
+    private static final String FEATURE = "camel-csv";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+}
diff --git a/extensions/csv/pom.xml b/extensions/csv/pom.xml
new file mode 100644
index 0000000..8e14837
--- /dev/null
+++ b/extensions/csv/pom.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-build-parent</artifactId>
+        <version>0.1.1-SNAPSHOT</version>
+        <relativePath>../../poms/build-parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-csv-parent</artifactId>
+    <name>Camel Quarkus :: CSV</name>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>deployment</module>
+        <module>runtime</module>
+    </modules>
+</project>
diff --git a/extensions/csv/runtime/pom.xml b/extensions/csv/runtime/pom.xml
new file mode 100644
index 0000000..bf10408
--- /dev/null
+++ b/extensions/csv/runtime/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-csv-parent</artifactId>
+        <version>0.1.1-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-csv</artifactId>
+    <name>Camel Quarkus :: CSV :: Runtime</name>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-bom</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-csv</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            <artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/extensions/pom.xml b/extensions/pom.xml
index a8129bf..f0f802c 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -57,6 +57,7 @@
         <module>twitter</module>
         <module>bean</module>
         <module>zipfile</module>
+        <module>csv</module>
     </modules>
 
     <build>
diff --git a/integration-tests/csv/pom.xml b/integration-tests/csv/pom.xml
new file mode 100644
index 0000000..001d6dd
--- /dev/null
+++ b/integration-tests/csv/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-integration-tests</artifactId>
+        <version>0.1.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-quarkus-integration-test-csv</artifactId>
+    <name>Camel Quarkus :: Integration Tests :: CSV</name>
+    <description>Integration tests for Camel Quarkus CSV extension</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-csv</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy-jackson</artifactId>
+        </dependency>
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.rest-assured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>build</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>native-image</id>
+            <activation>
+                <property>
+                    <name>native</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <systemProperties>
+                                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
+                                    </systemProperties>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>io.quarkus</groupId>
+                        <artifactId>quarkus-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>native-image</id>
+                                <goals>
+                                    <goal>native-image</goal>
+                                </goals>
+                                <configuration>
+                                    <reportErrorsAtRuntime>false</reportErrorsAtRuntime>
+                                    <cleanupServer>true</cleanupServer>
+                                    <enableHttpsUrlHandler>true</enableHttpsUrlHandler>
+                                    <enableServer>false</enableServer>
+                                    <dumpProxies>false</dumpProxies>
+                                    <graalvmHome>${graalvmHome}</graalvmHome>
+                                    <enableJni>true</enableJni>
+                                    <enableAllSecurityServices>true</enableAllSecurityServices>
+                                    <disableReports>true</disableReports>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
diff --git a/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvResource.java b/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvResource.java
new file mode 100644
index 0000000..c0cb703
--- /dev/null
+++ b/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvResource.java
@@ -0,0 +1,66 @@
+/*
+ * 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.quarkus.component.csv.it;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.camel.ProducerTemplate;
+import org.jboss.logging.Logger;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@Path("/csv")
+@ApplicationScoped
+public class CsvResource {
+
+    private static final Logger log = Logger.getLogger(CsvResource.class);
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Path("/json-to-csv")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String json2csv(String json) throws Exception {
+        log.infof("Transforming json %s", json);
+        final List<Map<String, Object>> objects = new ObjectMapper().readValue(json,  new TypeReference<List<Map<String, Object>>>() {});
+        return producerTemplate.requestBody(
+                "direct:json-to-csv",
+                objects,
+                String.class);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Path("/csv-to-json")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<List<Object>> csv2json(String csv) throws Exception {
+        return producerTemplate.requestBody("direct:csv-to-json", csv, List.class);
+    }
+}
diff --git a/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvRouteBuilder.java b/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvRouteBuilder.java
new file mode 100644
index 0000000..6b5ecdf
--- /dev/null
+++ b/integration-tests/csv/src/main/java/org/apache/camel/quarkus/component/csv/it/CsvRouteBuilder.java
@@ -0,0 +1,28 @@
+/*
+ * 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.quarkus.component.csv.it;
+
+import org.apache.camel.builder.RouteBuilder;
+
+
+public class CsvRouteBuilder extends RouteBuilder {
+    @Override
+    public void configure() {
+        from("direct:json-to-csv").marshal().csv();
+        from("direct:csv-to-json").unmarshal().csv();
+    }
+}
diff --git a/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvIT.java b/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvIT.java
new file mode 100644
index 0000000..615ec63
--- /dev/null
+++ b/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvIT.java
@@ -0,0 +1,8 @@
+package org.apache.camel.quarkus.component.csv.it;
+
+import io.quarkus.test.junit.SubstrateTest;
+
+@SubstrateTest
+class CsvIT extends CsvTest {
+
+}
diff --git a/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvTest.java b/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvTest.java
new file mode 100644
index 0000000..da4016e
--- /dev/null
+++ b/integration-tests/csv/src/test/java/org/apache/camel/quarkus/component/csv/it/CsvTest.java
@@ -0,0 +1,38 @@
+package org.apache.camel.quarkus.component.csv.it;
+
+import static org.hamcrest.Matchers.is;
+
+import org.junit.jupiter.api.Test;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+
+@QuarkusTest
+class CsvTest {
+
+    @Test
+    public void json2csv() {
+        RestAssured.given() //
+            .contentType(ContentType.JSON)
+            .accept(ContentType.TEXT)
+            .body("[{\"name\":\"Melwah\", \"species\":\"Camelus Dromedarius\"},{\"name\":\"Al Hamra\", \"species\":\"Camelus Dromedarius\"}]")
+            .post("/csv/json-to-csv")
+            .then()
+            .statusCode(200)
+            .body(is("Melwah,Camelus Dromedarius\r\nAl Hamra,Camelus Dromedarius\r\n"));
+    }
+
+    @Test
+    public void csv2json() {
+        RestAssured.given() //
+            .contentType(ContentType.TEXT)
+            .accept(ContentType.JSON)
+            .body("Melwah,Camelus Dromedarius\r\nAl Hamra,Camelus Dromedarius\r\n")
+            .post("/csv/csv-to-json")
+            .then()
+            .statusCode(200)
+            .body(is("[[\"Melwah\",\"Camelus Dromedarius\"],[\"Al Hamra\",\"Camelus Dromedarius\"]]"));
+    }
+
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index f9765cc..b6c29f6 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -64,6 +64,7 @@
         <module>netty4-http</module>
         <module>aws</module>
         <module>bean</module>
+        <module>csv</module>
         <module>infinispan</module>
         <module>jdbc</module>
         <module>salesforce</module>
diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml
index e1488ee..4cc0223 100644
--- a/poms/bom-deployment/pom.xml
+++ b/poms/bom-deployment/pom.xml
@@ -101,6 +101,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-csv-deployment</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
                 <artifactId>camel-quarkus-direct-deployment</artifactId>
                 <version>${camel-quarkus.version}</version>
             </dependency>
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index 4081954..5aa405d 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -101,6 +101,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel</groupId>
+                <artifactId>camel-csv</artifactId>
+                <version>${camel.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel</groupId>
                 <artifactId>camel-direct</artifactId>
                 <version>${camel.version}</version>
             </dependency>
@@ -241,6 +246,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-csv</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
                 <artifactId>camel-quarkus-direct</artifactId>
                 <version>${camel-quarkus.version}</version>
             </dependency>
@@ -289,6 +299,11 @@
                 <artifactId>camel-quarkus-twitter</artifactId>
                 <version>${camel-quarkus.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-zipfile</artifactId>
+                <version>${project.version}</version>
+            </dependency>
 
             <!-- Other third party dependencies (in alphabetical order by groupId:artifactId) -->
             <dependency>
@@ -301,11 +316,6 @@
                 <artifactId>xstream</artifactId>
                 <version>${xstream.version}</version>
             </dependency>
-            <dependency>
-                <groupId>org.apache.camel.quarkus</groupId>
-                <artifactId>camel-quarkus-zipfile</artifactId>
-                <version>${project.version}</version>
-            </dependency>
 
         </dependencies>
     </dependencyManagement>