This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 72e2d3c5a8798336b6de970e3286778c836d23d3 Author: Peter Palaga <[email protected]> AuthorDate: Fri Feb 28 15:34:43 2020 +0100 Fix #791 #783 Zip and Gzip Deflate Compression dataformat support --- .../pages/list-of-camel-quarkus-extensions.adoc | 4 +- extensions/pom.xml | 1 + extensions/readme.adoc | 4 +- extensions/zip-deflater/deployment/pom.xml | 75 +++++++++++++++++++ .../deflater/deployment/ZipDeflaterProcessor.java | 18 +++-- extensions/zip-deflater/pom.xml | 50 +++++++++++++ extensions/zip-deflater/runtime/pom.xml | 83 ++++++++++++++++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 29 ++++++++ integration-tests/compression/pom.xml | 6 +- .../compression/it/CompressionResource.java | 28 +++++--- .../compression/it/CompressionRouteBuilder.java | 9 ++- .../component/compression/it/CompressionTest.java | 47 ++++++------ poms/bom-deployment/pom.xml | 5 ++ poms/bom/pom.xml | 10 +++ 14 files changed, 326 insertions(+), 43 deletions(-) diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 9171db3..3e0fd72 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -307,7 +307,7 @@ Number of Camel languages: 10 in 4 JAR artifacts (0 deprecated) == Miscellaneous Extensions // others: START -Number of miscellaneous extensions: 9 in 9 JAR artifacts (0 deprecated) +Number of miscellaneous extensions: 10 in 10 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== @@ -330,5 +330,7 @@ Number of miscellaneous extensions: 9 in 9 JAR artifacts (0 deprecated) | xref:extensions/opentracing.adoc[camel-quarkus-opentracing] | 0.3.0 | Distributed tracing using OpenTracing | (camel-quarkus-reactive-executor) | 0.3.0 | Reactive Executor for camel-core using Vert.x + +| (camel-quarkus-zip-deflater) | 1.2.0 | Camel Zip deflater dataformat |=== // others: END diff --git a/extensions/pom.xml b/extensions/pom.xml index 2bb2d79..ad47205 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -118,6 +118,7 @@ <module>vm</module> <module>xpath</module> <module>xslt</module> + <module>zip-deflater</module> <module>zipfile</module> </modules> diff --git a/extensions/readme.adoc b/extensions/readme.adoc index b565346..26a7375 100644 --- a/extensions/readme.adoc +++ b/extensions/readme.adoc @@ -297,7 +297,7 @@ Number of Camel languages: 10 in 4 JAR artifacts (0 deprecated) == Miscellaneous Extensions // others: START -Number of miscellaneous extensions: 9 in 9 JAR artifacts (0 deprecated) +Number of miscellaneous extensions: 10 in 10 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== @@ -320,6 +320,8 @@ Number of miscellaneous extensions: 9 in 9 JAR artifacts (0 deprecated) | xref:extensions/opentracing.adoc[camel-quarkus-opentracing] | 0.3.0 | Distributed tracing using OpenTracing | (camel-quarkus-reactive-executor) | 0.3.0 | Reactive Executor for camel-core using Vert.x + +| (camel-quarkus-zip-deflater) | 1.2.0 | Camel Zip deflater dataformat |=== // others: END diff --git a/extensions/zip-deflater/deployment/pom.xml b/extensions/zip-deflater/deployment/pom.xml new file mode 100644 index 0000000..41cfd4a --- /dev/null +++ b/extensions/zip-deflater/deployment/pom.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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-zip-deflater-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-zip-deflater-deployment</artifactId> + <name>Camel Quarkus :: Zip Deflate Compression :: 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-zip-deflater</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/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java b/extensions/zip-deflater/deployment/src/main/java/org/apache/camel/quarkus/component/zip/deflater/deployment/ZipDeflaterProcessor.java similarity index 68% copy from integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java copy to extensions/zip-deflater/deployment/src/main/java/org/apache/camel/quarkus/component/zip/deflater/deployment/ZipDeflaterProcessor.java index 9937999..c16e928 100644 --- a/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java +++ b/extensions/zip-deflater/deployment/src/main/java/org/apache/camel/quarkus/component/zip/deflater/deployment/ZipDeflaterProcessor.java @@ -14,14 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.compression.it; +package org.apache.camel.quarkus.component.zip.deflater.deployment; -import org.apache.camel.builder.RouteBuilder; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; -public class CompressionRouteBuilder extends RouteBuilder { - @Override - public void configure() { - from("direct:start") - .marshal().zipFile(); +class ZipDeflaterProcessor { + + private static final String FEATURE = "camel-zip-deflater"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); } + } diff --git a/extensions/zip-deflater/pom.xml b/extensions/zip-deflater/pom.xml new file mode 100644 index 0000000..64c52c4 --- /dev/null +++ b/extensions/zip-deflater/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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>1.1.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-zip-deflater-parent</artifactId> + <name>Camel Quarkus :: Zip Deflate Compression</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bom-deployment</artifactId> + <version>${quarkus.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> +</project> diff --git a/extensions/zip-deflater/runtime/pom.xml b/extensions/zip-deflater/runtime/pom.xml new file mode 100644 index 0000000..47a5a28 --- /dev/null +++ b/extensions/zip-deflater/runtime/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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-zip-deflater-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-zip-deflater</artifactId> + <name>Camel Quarkus :: Zip Deflate Compression :: Runtime</name> + <description>Camel Zip deflater dataformat</description> + + <properties> + <firstVersion>1.2.0</firstVersion> + </properties> + + <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-zip-deflater</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/zip-deflater/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/zip-deflater/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..336c2d8 --- /dev/null +++ b/extensions/zip-deflater/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,29 @@ +# +# 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. +# + +--- +name: "Camel Quarkus Zipfile" +description: "Camel Zip file support" +metadata: + keywords: + - "camel" + - "zip" + - "gzip" + - "file" + guide: "https://quarkus.io/guides/camel" + categories: + - "integration" \ No newline at end of file diff --git a/integration-tests/compression/pom.xml b/integration-tests/compression/pom.xml index 3f3a295..780f8e0 100644 --- a/integration-tests/compression/pom.xml +++ b/integration-tests/compression/pom.xml @@ -36,7 +36,7 @@ <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. --> <!-- Please update rule whenever you change the dependencies of this module by running --> <!-- mvn process-resources -Pformat from the root directory --> - <mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-zipfile-deployment</mvnd.builder.rule> + <mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-zip-deflater-deployment,camel-quarkus-zipfile-deployment</mvnd.builder.rule> </properties> <dependencies> @@ -46,6 +46,10 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-zip-deflater</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-direct</artifactId> </dependency> <dependency> diff --git a/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionResource.java b/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionResource.java index 7907788..af8ae3a 100644 --- a/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionResource.java +++ b/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionResource.java @@ -23,34 +23,44 @@ import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.camel.ProducerTemplate; -import org.jboss.logging.Logger; @Path("/compression") @ApplicationScoped public class CompressionResource { - private static final Logger LOG = Logger.getLogger(CompressionResource.class); - @Inject ProducerTemplate producerTemplate; - @Path("/zipfile") + @Path("/compress/{format}") @POST - @Consumes(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) - public Response post(String message) throws Exception { - LOG.infof("Sending to zipfile: %s", message); - final byte[] response = producerTemplate.requestBody("direct:start", message, byte[].class); - LOG.infof("Got response from zipfile: %s", response); + public Response zipfileCompress(@PathParam("format") String format, byte[] message) throws Exception { + final byte[] response = producerTemplate.requestBody("direct:" + format + "-compress", message, byte[].class); return Response .created(new URI("https://camel.apache.org/")) .header("content-length", response.length) .entity(response) .build(); } + + @Path("/uncompress/{format}") + @POST + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response zipfileUncompress(@PathParam("format") String format, byte[] message) throws Exception { + final byte[] response = producerTemplate.requestBody("direct:" + format + "-uncompress", message, byte[].class); + return Response + .created(new URI("https://camel.apache.org/")) + .header("content-length", response.length) + .entity(response) + .build(); + } + } diff --git a/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java b/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java index 9937999..c14e665 100644 --- a/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java +++ b/integration-tests/compression/src/main/java/org/apache/camel/quarkus/component/compression/it/CompressionRouteBuilder.java @@ -21,7 +21,14 @@ import org.apache.camel.builder.RouteBuilder; public class CompressionRouteBuilder extends RouteBuilder { @Override public void configure() { - from("direct:start") + from("direct:zipfile-compress") .marshal().zipFile(); + from("direct:zipfile-uncompress") + .unmarshal().zipFile(); + + from("direct:zip-deflater-compress") + .marshal().zipDeflater(); + from("direct:zip-deflater-uncompress") + .unmarshal().zipDeflater(); } } diff --git a/integration-tests/compression/src/test/java/org/apache/camel/quarkus/component/compression/it/CompressionTest.java b/integration-tests/compression/src/test/java/org/apache/camel/quarkus/component/compression/it/CompressionTest.java index c30b279..94514da 100644 --- a/integration-tests/compression/src/test/java/org/apache/camel/quarkus/component/compression/it/CompressionTest.java +++ b/integration-tests/compression/src/test/java/org/apache/camel/quarkus/component/compression/it/CompressionTest.java @@ -16,42 +16,43 @@ */ package org.apache.camel.quarkus.component.compression.it; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import io.restassured.response.ExtractableResponse; -import org.apache.camel.util.IOHelper; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; @QuarkusTest class CompressionTest { + final byte[] UNCOMPRESSED = "Hello World!".getBytes(StandardCharsets.UTF_8); - @Test - public void test() throws Exception { - byte[] body; + private static Stream<String> listJsonDataFormatsToBeTested() { + return Stream.of("zipfile", "zip-deflater"); + } + + @ParameterizedTest + @MethodSource("listJsonDataFormatsToBeTested") + public void compressAndUncompress(String format) throws Exception { - ExtractableResponse response = RestAssured.given() // - .contentType(ContentType.TEXT).body("Hello World").post("/compression/zipfile") // - .then().extract(); + final byte[] compressed = RestAssured.given() + .contentType(ContentType.BINARY) + .body(UNCOMPRESSED) + .post("/compression/compress/" + format) // + .then().extract().body().asByteArray(); - body = response.body().asByteArray(); - Assertions.assertNotNull(body); + Assertions.assertNotNull(compressed); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(body)); - ZipEntry entry = zis.getNextEntry(); - if (entry != null) { - IOHelper.copy(zis, bos); - } + final byte[] uncompressed = RestAssured.given() + .contentType(ContentType.BINARY) + .body(compressed) + .post("/compression/uncompress/" + format) // + .then().extract().body().asByteArray(); - String str = bos.toString(); - Assertions.assertEquals("Hello World", str); + Assertions.assertArrayEquals(UNCOMPRESSED, uncompressed); } } diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml index ef93076..f8e14a6 100644 --- a/poms/bom-deployment/pom.xml +++ b/poms/bom-deployment/pom.xml @@ -526,6 +526,11 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-zip-deflater-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-zipfile-deployment</artifactId> <version>${camel-quarkus.version}</version> </dependency> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 94e9e3e..f93a590 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -607,6 +607,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-zip-deflater</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-zipfile</artifactId> <version>${camel.version}</version> </dependency> @@ -1089,6 +1094,11 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-zip-deflater</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-zipfile</artifactId> <version>${camel-quarkus.version}</version> </dependency>
