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


The following commit(s) were added to refs/heads/master by this push:
     new 4918944  [CAMEL-16270] Vertx: refactor Buffer converter for sharing 
across vertx components. (#5144)
4918944 is described below

commit 4918944d22209dcd43d7c5a98b81845f46fbd731
Author: James Hilliard <james.hillia...@gmail.com>
AuthorDate: Sun Feb 28 06:01:31 2021 -0700

    [CAMEL-16270] Vertx: refactor Buffer converter for sharing across vertx 
components. (#5144)
    
    Currently the Vertx buffer converter is tied to the camel-vertx-http
    component even though Vertx Buffers are part of vertx-core, lets
    split it into a shared camel-vertx-common component and have all
    components that require it depend on that.
    
    Signed-off-by: James Hilliard <james.hillia...@gmail.com>
---
 bom/camel-bom/pom.xml                              |  5 ++
 .../org/apache/camel/catalog/others.properties     |  1 +
 .../apache/camel/catalog/others/vertx-common.json  | 15 ++++
 components/camel-platform-http-vertx/pom.xml       |  4 +
 .../http/vertx/VertxPlatformHttpConsumer.java      |  2 +-
 .../VertxPlatformHttpBufferConverterTest.java      | 86 ++++++++++++++++++++++
 .../{camel-vertx => camel-vertx-common}/pom.xml    | 21 ++----
 .../vertx/common}/VertxBufferConverterLoader.java  | 16 ++--
 .../services/org/apache/camel/TypeConverterLoader  |  2 +
 .../services/org/apache/camel/other.properties     |  7 ++
 .../src/generated/resources/vertx-common.json      | 15 ++++
 .../vertx/common}/VertxBufferConverter.java        | 24 +++++-
 components/camel-vertx-http/pom.xml                |  4 +
 .../services/org/apache/camel/TypeConverterLoader  |  2 -
 .../component/vertx/http/VertxHttpProducer.java    |  1 +
 .../vertx/kafka/VertxKafkaTypeConverterLoader.java | 36 ---------
 .../services/org/apache/camel/TypeConverterLoader  |  2 -
 .../vertx/kafka/VertxKafkaTypeConverter.java       | 32 --------
 .../vertx/kafka/VertxKafkaBufferConverterTest.java | 86 ++++++++++++++++++++++
 components/camel-vertx-kafka/pom.xml               |  5 ++
 components/camel-vertx/pom.xml                     |  4 +
 .../component/vertx/VertxBufferConverterTest.java  | 86 ++++++++++++++++++++++
 components/pom.xml                                 |  1 +
 core/camel-allcomponents/pom.xml                   |  4 +
 parent/pom.xml                                     |  5 ++
 25 files changed, 366 insertions(+), 100 deletions(-)

diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 536bbff..bcbe59c 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1920,6 +1920,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-vertx-common</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-vertx-http</artifactId>
         <version>${project.version}</version>
       </dependency>
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties
index aa9f1a3..7f215b0 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties
@@ -45,4 +45,5 @@ testcontainers-spring-junit5
 threadpoolfactory-vertx
 tracing
 undertow-spring-security
+vertx-common
 zipkin
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/vertx-common.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/vertx-common.json
new file mode 100644
index 0000000..cac85d1
--- /dev/null
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/vertx-common.json
@@ -0,0 +1,15 @@
+{
+  "other": {
+    "kind": "other",
+    "name": "vertx-common",
+    "title": "Vertx Common",
+    "description": "Camel Vert.x Common support",
+    "deprecated": false,
+    "firstVersion": "3.9.0",
+    "label": "eventbus,reactive",
+    "supportLevel": "Preview",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-vertx-common",
+    "version": "3.9.0-SNAPSHOT"
+  }
+}
diff --git a/components/camel-platform-http-vertx/pom.xml 
b/components/camel-platform-http-vertx/pom.xml
index 3c655e5..19ded9f 100644
--- a/components/camel-platform-http-vertx/pom.xml
+++ b/components/camel-platform-http-vertx/pom.xml
@@ -47,6 +47,10 @@
             <artifactId>camel-attachments</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-vertx-common</artifactId>
+        </dependency>
+        <dependency>
             <groupId>io.vertx</groupId>
             <artifactId>vertx-web</artifactId>
             <version>${vertx-version}</version>
diff --git 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
index e49748f..cb0ad0f 100644
--- 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
+++ 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
@@ -257,7 +257,7 @@ public class VertxPlatformHttpConsumer extends 
DefaultConsumer {
             if (m.canHaveBody()) {
                 final Buffer body = ctx.getBody();
                 if (body != null) {
-                    result.setBody(body.getBytes());
+                    result.setBody(body);
                 } else {
                     result.setBody(null);
                 }
diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBufferConverterTest.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBufferConverterTest.java
new file mode 100644
index 0000000..a5a12b8
--- /dev/null
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBufferConverterTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.component.platform.http.vertx;
+
+import java.io.InputStream;
+
+import io.netty.buffer.Unpooled;
+import io.vertx.core.buffer.Buffer;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class VertxPlatformHttpBufferConverterTest extends CamelTestSupport {
+
+    private static final String BODY = "Hello World";
+
+    @Test
+    public void testStringToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testStringToBufferWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        context.getTypeConverter().convertTo(Buffer.class, exchange, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteArrayToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY.getBytes());
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteBufToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
Unpooled.wrappedBuffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testInputStreamToBuffer() {
+        InputStream inputStream = 
context.getTypeConverter().convertTo(InputStream.class, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
inputStream);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testBufferToString() {
+        String result = context.getTypeConverter().convertTo(String.class, 
Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToStringWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        String result = context.getTypeConverter().convertTo(String.class, 
exchange, Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToByteArray() {
+        byte[] result = context.getTypeConverter().convertTo(byte[].class, 
Buffer.buffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, new String(result));
+    }
+}
diff --git a/components/camel-vertx/pom.xml 
b/components/camel-vertx-common/pom.xml
similarity index 78%
copy from components/camel-vertx/pom.xml
copy to components/camel-vertx-common/pom.xml
index a66c29b..e0242a1 100644
--- a/components/camel-vertx/pom.xml
+++ b/components/camel-vertx-common/pom.xml
@@ -26,16 +26,17 @@
         <version>3.9.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>camel-vertx</artifactId>
+    <artifactId>camel-vertx-common</artifactId>
     <packaging>jar</packaging>
-    <name>Camel :: Vertx</name>
-    <description>Camel Vertx support</description>
+    <name>Camel :: Vert.x :: Common</name>
+    <description>Camel Vert.x Common support</description>
 
     <properties>
+        <firstVersion>3.9.0</firstVersion>
+        <label>eventbus,reactive</label>
     </properties>
 
     <dependencies>
-
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-support</artifactId>
@@ -51,17 +52,5 @@
                 </exclusion>
             </exclusions>
         </dependency>
-
-        <!-- testing -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test-junit5</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-slf4j-impl</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
diff --git 
a/components/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxBufferConverterLoader.java
 
b/components/camel-vertx-common/src/generated/java/org/apache/camel/component/vertx/common/VertxBufferConverterLoader.java
similarity index 79%
rename from 
components/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxBufferConverterLoader.java
rename to 
components/camel-vertx-common/src/generated/java/org/apache/camel/component/vertx/common/VertxBufferConverterLoader.java
index 9329a83..6298d9b 100644
--- 
a/components/camel-vertx-http/src/generated/java/org/apache/camel/component/vertx/http/VertxBufferConverterLoader.java
+++ 
b/components/camel-vertx-common/src/generated/java/org/apache/camel/component/vertx/common/VertxBufferConverterLoader.java
@@ -1,5 +1,5 @@
 /* Generated by camel build tools - do NOT edit this file! */
-package org.apache.camel.component.vertx.http;
+package org.apache.camel.component.vertx.common;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.TypeConversionException;
@@ -26,19 +26,19 @@ public final class VertxBufferConverterLoader implements 
TypeConverterLoader {
 
     private void registerConverters(TypeConverterRegistry registry) {
         addTypeConverter(registry, byte[].class, 
io.vertx.core.buffer.Buffer.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toBytes((io.vertx.core.buffer.Buffer)
 value));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toBytes((io.vertx.core.buffer.Buffer)
 value));
         addTypeConverter(registry, io.vertx.core.buffer.Buffer.class, 
byte[].class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toBuffer((byte[]) 
value));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toBuffer((byte[]) 
value));
         addTypeConverter(registry, io.vertx.core.buffer.Buffer.class, 
io.netty.buffer.ByteBuf.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toBuffer((io.netty.buffer.ByteBuf)
 value));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toBuffer((io.netty.buffer.ByteBuf)
 value));
         addTypeConverter(registry, io.vertx.core.buffer.Buffer.class, 
java.io.InputStream.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toBuffer((java.io.InputStream)
 value));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toBuffer((java.io.InputStream)
 value));
         addTypeConverter(registry, io.vertx.core.buffer.Buffer.class, 
java.lang.String.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toBuffer((java.lang.String)
 value, exchange));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toBuffer((java.lang.String)
 value, exchange));
         addTypeConverter(registry, java.io.InputStream.class, 
io.vertx.core.buffer.Buffer.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toInputStream((io.vertx.core.buffer.Buffer)
 value));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toInputStream((io.vertx.core.buffer.Buffer)
 value));
         addTypeConverter(registry, java.lang.String.class, 
io.vertx.core.buffer.Buffer.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.http.VertxBufferConverter.toString((io.vertx.core.buffer.Buffer)
 value, exchange));
+            (type, exchange, value) -> 
org.apache.camel.component.vertx.common.VertxBufferConverter.toString((io.vertx.core.buffer.Buffer)
 value, exchange));
     }
 
     private static void addTypeConverter(TypeConverterRegistry registry, 
Class<?> toType, Class<?> fromType, boolean allowNull, 
SimpleTypeConverter.ConversionMethod method) { 
diff --git 
a/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
 
b/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 0000000..ae9089b
--- /dev/null
+++ 
b/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.vertx.common.VertxBufferConverterLoader
diff --git 
a/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
 
b/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
new file mode 100644
index 0000000..75063df4
--- /dev/null
+++ 
b/components/camel-vertx-common/src/generated/resources/META-INF/services/org/apache/camel/other.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+name=vertx-common
+groupId=org.apache.camel
+artifactId=camel-vertx-common
+version=3.9.0-SNAPSHOT
+projectName=Camel :: Vert.x :: Common
+projectDescription=Camel Vert.x Common support
diff --git 
a/components/camel-vertx-common/src/generated/resources/vertx-common.json 
b/components/camel-vertx-common/src/generated/resources/vertx-common.json
new file mode 100644
index 0000000..cac85d1
--- /dev/null
+++ b/components/camel-vertx-common/src/generated/resources/vertx-common.json
@@ -0,0 +1,15 @@
+{
+  "other": {
+    "kind": "other",
+    "name": "vertx-common",
+    "title": "Vertx Common",
+    "description": "Camel Vert.x Common support",
+    "deprecated": false,
+    "firstVersion": "3.9.0",
+    "label": "eventbus,reactive",
+    "supportLevel": "Preview",
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-vertx-common",
+    "version": "3.9.0-SNAPSHOT"
+  }
+}
diff --git 
a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxBufferConverter.java
 
b/components/camel-vertx-common/src/main/java/org/apache/camel/component/vertx/common/VertxBufferConverter.java
similarity index 74%
rename from 
components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxBufferConverter.java
rename to 
components/camel-vertx-common/src/main/java/org/apache/camel/component/vertx/common/VertxBufferConverter.java
index e3e9413..b32acb5 100644
--- 
a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxBufferConverter.java
+++ 
b/components/camel-vertx-common/src/main/java/org/apache/camel/component/vertx/common/VertxBufferConverter.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.vertx.http;
+package org.apache.camel.component.vertx.common;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -39,7 +39,7 @@ public final class VertxBufferConverter {
 
     @Converter
     public static Buffer toBuffer(String string, Exchange exchange) {
-        String charset = VertxHttpHelper.getCharsetFromExchange(exchange);
+        String charset = getCharsetFromExchange(exchange);
         if (ObjectHelper.isNotEmpty(charset)) {
             Buffer.buffer(string, charset);
         }
@@ -69,7 +69,7 @@ public final class VertxBufferConverter {
 
     @Converter
     public static String toString(Buffer buffer, Exchange exchange) {
-        String charset = VertxHttpHelper.getCharsetFromExchange(exchange);
+        String charset = getCharsetFromExchange(exchange);
         if (ObjectHelper.isNotEmpty(charset)) {
             buffer.toString(charset);
         }
@@ -85,4 +85,22 @@ public final class VertxBufferConverter {
     public static InputStream toInputStream(Buffer buffer) {
         return new ByteArrayInputStream(buffer.getBytes());
     }
+
+    /**
+     * Retrieves the charset from the exchange Content-Type header, or falls 
back to the CamelCharsetName exchange
+     * property when not available
+     */
+    private static String getCharsetFromExchange(Exchange exchange) {
+        String charset = null;
+        if (exchange != null) {
+            String contentType = 
exchange.getMessage().getHeader(Exchange.CONTENT_TYPE, String.class);
+            if (contentType != null) {
+                charset = IOHelper.getCharsetNameFromContentType(contentType);
+            }
+            if (ObjectHelper.isEmpty(charset)) {
+                charset = exchange.getProperty(Exchange.CHARSET_NAME, 
String.class);
+            }
+        }
+        return charset;
+    }
 }
diff --git a/components/camel-vertx-http/pom.xml 
b/components/camel-vertx-http/pom.xml
index 2a59d5f..326c5db 100644
--- a/components/camel-vertx-http/pom.xml
+++ b/components/camel-vertx-http/pom.xml
@@ -40,6 +40,10 @@
             <artifactId>camel-http-base</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-vertx-common</artifactId>
+        </dependency>
+        <dependency>
             <groupId>io.vertx</groupId>
             <artifactId>vertx-web-client</artifactId>
             <version>${vertx-version}</version>
diff --git 
a/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
 
b/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
deleted file mode 100644
index c1eeca0..0000000
--- 
a/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
+++ /dev/null
@@ -1,2 +0,0 @@
-# Generated by camel build tools - do NOT edit this file!
-org.apache.camel.component.vertx.http.VertxBufferConverterLoader
diff --git 
a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpProducer.java
 
b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpProducer.java
index e5a7df4..2466659 100644
--- 
a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpProducer.java
+++ 
b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpProducer.java
@@ -32,6 +32,7 @@ import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.component.vertx.common.VertxBufferConverter;
 import org.apache.camel.support.DefaultAsyncProducer;
 import org.apache.camel.support.MessageHelper;
 import org.apache.camel.util.URISupport;
diff --git 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverterLoader.java
 
b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverterLoader.java
deleted file mode 100644
index 5c31566..0000000
--- 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverterLoader.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Generated by camel build tools - do NOT edit this file! */
-package org.apache.camel.component.vertx.kafka;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.TypeConversionException;
-import org.apache.camel.TypeConverterLoaderException;
-import org.apache.camel.spi.TypeConverterLoader;
-import org.apache.camel.spi.TypeConverterRegistry;
-import org.apache.camel.support.SimpleTypeConverter;
-import org.apache.camel.support.TypeConverterSupport;
-import org.apache.camel.util.DoubleMap;
-
-/**
- * Generated by camel build tools - do NOT edit this file!
- */
-@SuppressWarnings("unchecked")
-public final class VertxKafkaTypeConverterLoader implements 
TypeConverterLoader {
-
-    public VertxKafkaTypeConverterLoader() {
-    }
-
-    @Override
-    public void load(TypeConverterRegistry registry) throws 
TypeConverterLoaderException {
-        registerConverters(registry);
-    }
-
-    private void registerConverters(TypeConverterRegistry registry) {
-        addTypeConverter(registry, byte[].class, 
io.vertx.core.buffer.Buffer.class, false,
-            (type, exchange, value) -> 
org.apache.camel.component.vertx.kafka.VertxKafkaTypeConverter.toByte((io.vertx.core.buffer.Buffer)
 value));
-    }
-
-    private static void addTypeConverter(TypeConverterRegistry registry, 
Class<?> toType, Class<?> fromType, boolean allowNull, 
SimpleTypeConverter.ConversionMethod method) { 
-        registry.addTypeConverter(toType, fromType, new 
SimpleTypeConverter(allowNull, method));
-    }
-
-}
diff --git 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
 
b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
deleted file mode 100644
index a9b9229..0000000
--- 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
+++ /dev/null
@@ -1,2 +0,0 @@
-# Generated by camel build tools - do NOT edit this file!
-org.apache.camel.component.vertx.kafka.VertxKafkaTypeConverterLoader
diff --git 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverter.java
 
b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverter.java
deleted file mode 100644
index 41b2ff4..0000000
--- 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaTypeConverter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.vertx.kafka;
-
-import io.vertx.core.buffer.Buffer;
-import org.apache.camel.Converter;
-
-@Converter(generateLoader = true)
-public final class VertxKafkaTypeConverter {
-
-    private VertxKafkaTypeConverter() {
-    }
-
-    @Converter
-    public static byte[] toByte(final Buffer buffer) {
-        return buffer.getBytes();
-    }
-}
diff --git 
a/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaBufferConverterTest.java
 
b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaBufferConverterTest.java
new file mode 100644
index 0000000..351d681
--- /dev/null
+++ 
b/components/camel-vertx-kafka/camel-vertx-kafka-component/src/test/java/org/apache/camel/component/vertx/kafka/VertxKafkaBufferConverterTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.component.vertx.kafka;
+
+import java.io.InputStream;
+
+import io.netty.buffer.Unpooled;
+import io.vertx.core.buffer.Buffer;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class VertxKafkaBufferConverterTest extends CamelTestSupport {
+
+    private static final String BODY = "Hello World";
+
+    @Test
+    public void testStringToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testStringToBufferWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        context.getTypeConverter().convertTo(Buffer.class, exchange, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteArrayToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY.getBytes());
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteBufToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
Unpooled.wrappedBuffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testInputStreamToBuffer() {
+        InputStream inputStream = 
context.getTypeConverter().convertTo(InputStream.class, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
inputStream);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testBufferToString() {
+        String result = context.getTypeConverter().convertTo(String.class, 
Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToStringWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        String result = context.getTypeConverter().convertTo(String.class, 
exchange, Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToByteArray() {
+        byte[] result = context.getTypeConverter().convertTo(byte[].class, 
Buffer.buffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, new String(result));
+    }
+}
diff --git a/components/camel-vertx-kafka/pom.xml 
b/components/camel-vertx-kafka/pom.xml
index 011493d..f86ca65 100644
--- a/components/camel-vertx-kafka/pom.xml
+++ b/components/camel-vertx-kafka/pom.xml
@@ -46,6 +46,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-vertx-common</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>io.vertx</groupId>
             <artifactId>vertx-kafka-client</artifactId>
             <version>${vertx-version}</version>
diff --git a/components/camel-vertx/pom.xml b/components/camel-vertx/pom.xml
index a66c29b..9c41090 100644
--- a/components/camel-vertx/pom.xml
+++ b/components/camel-vertx/pom.xml
@@ -41,6 +41,10 @@
             <artifactId>camel-support</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-vertx-common</artifactId>
+        </dependency>
+        <dependency>
             <groupId>io.vertx</groupId>
             <artifactId>vertx-core</artifactId>
             <version>${vertx-version}</version>
diff --git 
a/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxBufferConverterTest.java
 
b/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxBufferConverterTest.java
new file mode 100644
index 0000000..2a61300
--- /dev/null
+++ 
b/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxBufferConverterTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.component.vertx;
+
+import java.io.InputStream;
+
+import io.netty.buffer.Unpooled;
+import io.vertx.core.buffer.Buffer;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class VertxBufferConverterTest extends CamelTestSupport {
+
+    private static final String BODY = "Hello World";
+
+    @Test
+    public void testStringToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testStringToBufferWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        context.getTypeConverter().convertTo(Buffer.class, exchange, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteArrayToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
BODY.getBytes());
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testByteBufToBuffer() {
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
Unpooled.wrappedBuffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testInputStreamToBuffer() {
+        InputStream inputStream = 
context.getTypeConverter().convertTo(InputStream.class, BODY);
+        Buffer buffer = context.getTypeConverter().convertTo(Buffer.class, 
inputStream);
+        Assertions.assertEquals(BODY, buffer.toString());
+    }
+
+    @Test
+    public void testBufferToString() {
+        String result = context.getTypeConverter().convertTo(String.class, 
Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToStringWithEncoding() {
+        Exchange exchange = ExchangeBuilder.anExchange(context)
+                .withHeader(Exchange.CONTENT_TYPE, "text/html; 
charset=iso-8859-4").build();
+        String result = context.getTypeConverter().convertTo(String.class, 
exchange, Buffer.buffer(BODY));
+        Assertions.assertEquals(BODY, result);
+    }
+
+    @Test
+    public void testBufferToByteArray() {
+        byte[] result = context.getTypeConverter().convertTo(byte[].class, 
Buffer.buffer(BODY.getBytes()));
+        Assertions.assertEquals(BODY, new String(result));
+    }
+}
diff --git a/components/pom.xml b/components/pom.xml
index 7103cbc..e2422b3 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -371,6 +371,7 @@
         <module>camel-univocity-parsers</module>
         <module>camel-velocity</module>
         <module>camel-vertx</module>
+        <module>camel-vertx-common</module>
         <module>camel-vertx-http</module>
         <module>camel-vertx-websocket</module>
         <module>camel-vertx-kafka</module>
diff --git a/core/camel-allcomponents/pom.xml b/core/camel-allcomponents/pom.xml
index 86cfa83..645fbfe 100644
--- a/core/camel-allcomponents/pom.xml
+++ b/core/camel-allcomponents/pom.xml
@@ -1367,6 +1367,10 @@
                </dependency>
                <dependency>
                        <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-vertx-common</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
                        <artifactId>camel-vertx-http</artifactId>
                </dependency>
                <dependency>
diff --git a/parent/pom.xml b/parent/pom.xml
index 6b307e5..da87e07 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -2485,6 +2485,11 @@
                        </dependency>
                        <dependency>
                                <groupId>org.apache.camel</groupId>
+                               <artifactId>camel-vertx-common</artifactId>
+                               <version>${project.version}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.apache.camel</groupId>
                                <artifactId>camel-vertx-http</artifactId>
                                <version>${project.version}</version>
                        </dependency>

Reply via email to