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 2020/10/26 14:13:03 UTC
[camel-spring-boot-examples] branch master updated: Add Camel
Spring Boot custom Type Converter example
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-spring-boot-examples.git
The following commit(s) were added to refs/heads/master by this push:
new 6ed8e69 Add Camel Spring Boot custom Type Converter example
6ed8e69 is described below
commit 6ed8e69cddd84cb480410560f5e9478a4c1824c8
Author: Farid Guliyev <fg...@gmail.com>
AuthorDate: Sat Oct 24 07:52:23 2020 -0400
Add Camel Spring Boot custom Type Converter example
---
README.adoc | 4 +-
.../README.adoc | 28 +++++
camel-example-spring-boot-type-converter/pom.xml | 130 +++++++++++++++++++++
.../camel/CustomGeneratedConverterLoader.java | 43 +++++++
.../services/org/apache/camel/TypeConverterLoader | 2 +
.../src/main/java/sample/camel/Application.java | 29 +++++
.../sample/camel/CustomGeneratedConverter.java | 41 +++++++
.../java/sample/camel/CustomRuntimeConverter.java | 41 +++++++
.../java/sample/camel/DataTypeConverterRouter.java | 31 +++++
.../src/main/java/sample/camel/Person.java | 54 +++++++++
.../services/org/apache/camel/TypeConverter | 1 +
.../services/org/apache/camel/TypeConverterLoader | 1 +
.../src/main/resources/application.properties | 13 +++
.../sample/camel/CustomConverterGeneratedTest.java | 61 ++++++++++
.../sample/camel/CustomConverterRuntimeTest.java | 61 ++++++++++
pom.xml | 1 +
16 files changed, 540 insertions(+), 1 deletion(-)
diff --git a/README.adoc b/README.adoc
index de3698a..2fd91e4 100644
--- a/README.adoc
+++ b/README.adoc
@@ -27,7 +27,7 @@ readme's instructions.
== Examples
// examples: START
-Number of Examples: 44 (0 deprecated)
+Number of Examples: 45 (0 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -49,6 +49,8 @@ Number of Examples: 44 (0 deprecated)
| link:camel-example-spring-boot-rest-swagger-simple/README.adoc[REST Swagger] (camel-example-spring-boot-rest-swagger-simple) | Beginner | This example shows how to call a Rest service defined using Swagger specification
+| link:camel-example-spring-boot-type-converter/README.adoc[Spring Boot Type Converter] (camel-example-spring-boot-type-converter) | Beginner | An example showing how to create custom type converter with Camel and Spring Boot
+
| link:camel-example-spring-boot-xml/readme.adoc[Spring Boot XML] (camel-example-spring-boot-xml) | Beginner | An example showing how to work with Camel routes in XML files and Spring Boot
| link:camel-example-spring-boot-aws2-s3/README.adoc[Spring Boot Aws2 S3] (camel-example-spring-boot-aws2-s3) | Cloud | An example showing the Camel AWS2 S3 component with Spring Boot
diff --git a/camel-example-spring-boot-type-converter/README.adoc b/camel-example-spring-boot-type-converter/README.adoc
new file mode 100644
index 0000000..1ef87c0
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/README.adoc
@@ -0,0 +1,28 @@
+== Camel Example Spring Boot
+
+This example shows two options creating a custom Type Converter with Apache Camel application using Spring Boot.
+
+Option 1 (Camel 2.x) - Converter added to the registry and loaded at the runtime : CustomConverterRuntimeTest and CustomRuntimeConverter.
+
+Option 2 (Camel 3.x) - Converter source code generated during mvn package phase: CustomConverterGeneratedTest and CustomGeneratedConverter.
+Required Camel Maven Package Plugin and build helper plugin - see pom.xml for details.
+
+=== How to run
+
+You can run this example using
+
+ mvn test
+
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/support.html[let us know].
+
+We also love contributors, so
+https://camel.apache.org/contributing.html[get involved] :-)
+
+The Camel riders!
+
+
+
diff --git a/camel-example-spring-boot-type-converter/pom.xml b/camel-example-spring-boot-type-converter/pom.xml
new file mode 100644
index 0000000..cfa6744
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/pom.xml
@@ -0,0 +1,130 @@
+<?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">
+ <parent>
+ <artifactId>examples</artifactId>
+ <groupId>org.apache.camel.springboot.example</groupId>
+ <version>3.7.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-example-spring-boot-type-converter</artifactId>
+ <name>Camel SB Examples :: Custom Type Converter</name>
+ <description>An example showing how to create custom type converter with Camel and Spring Boot</description>
+
+ <properties>
+ <category>Beginner</category>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <spring.boot-version>${spring-boot-version}</spring.boot-version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Spring Boot BOM -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring.boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <!-- Camel BOM -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-bom</artifactId>
+ <version>${camel-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-stream-starter</artifactId>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Camel Maven Package Plugin to generate Type Converter Loader source code - Camel 3.x way -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>initialize</phase>
+ <goals>
+ <goal>add-source</goal>
+ <goal>add-resource</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/generated/java</source>
+ </sources>
+ <resources>
+ <resource>
+ <directory>src/generated/resources</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Adds mgenerated Type Converter Loader source in src/generated to the source path - Camel 3.x way -->
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-package-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <goals>
+ <goal>generate-component</goal>
+ </goals>
+ <phase>process-classes</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/camel-example-spring-boot-type-converter/src/generated/java/sample/camel/CustomGeneratedConverterLoader.java b/camel-example-spring-boot-type-converter/src/generated/java/sample/camel/CustomGeneratedConverterLoader.java
new file mode 100644
index 0000000..9f5df37
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/generated/java/sample/camel/CustomGeneratedConverterLoader.java
@@ -0,0 +1,43 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package sample.camel;
+
+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 CustomGeneratedConverterLoader implements TypeConverterLoader {
+
+ public CustomGeneratedConverterLoader() {
+ }
+
+ @Override
+ public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
+ registerConverters(registry);
+ }
+
+ private void registerConverters(TypeConverterRegistry registry) {
+ addTypeConverter(registry, sample.camel.Person.class, byte[].class, false,
+ (type, exchange, value) -> getCustomGeneratedConverter().toPerson((byte[]) value, exchange));
+ }
+
+ private static void addTypeConverter(TypeConverterRegistry registry, Class<?> toType, Class<?> fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) {
+ registry.addTypeConverter(toType, fromType, new SimpleTypeConverter(allowNull, method));
+ }
+
+ private volatile sample.camel.CustomGeneratedConverter customGeneratedConverter;
+ private sample.camel.CustomGeneratedConverter getCustomGeneratedConverter() {
+ if (customGeneratedConverter == null) {
+ customGeneratedConverter = new sample.camel.CustomGeneratedConverter();
+ }
+ return customGeneratedConverter;
+ }
+}
diff --git a/camel-example-spring-boot-type-converter/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader b/camel-example-spring-boot-type-converter/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 0000000..3bcad73
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+sample.camel.CustomGeneratedConverterLoader
diff --git a/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Application.java b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Application.java
new file mode 100644
index 0000000..4eeaa6d
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Application.java
@@ -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.
+ */
+package sample.camel;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomGeneratedConverter.java b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomGeneratedConverter.java
new file mode 100644
index 0000000..194b067
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomGeneratedConverter.java
@@ -0,0 +1,41 @@
+/*
+ * 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 sample.camel;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.TypeConverters;
+
+@Converter(generateLoader = true)
+public class CustomGeneratedConverter implements TypeConverters {
+
+ @Converter
+ public Person toPerson(byte[] data, Exchange exchange){
+ TypeConverter converter = exchange.getContext().getTypeConverter();
+
+ String s = converter.convertTo(String.class, data);
+
+ final String[] splitData = s.split(" ");
+ final String firstName = splitData[0];
+ final String lastName = splitData[1];
+ int age = Integer.parseInt(splitData[2]);
+
+ return new Person(firstName, lastName, age);
+ }
+
+}
diff --git a/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomRuntimeConverter.java b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomRuntimeConverter.java
new file mode 100644
index 0000000..18189e8
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/CustomRuntimeConverter.java
@@ -0,0 +1,41 @@
+/*
+ * 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 sample.camel;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.TypeConverters;
+
+@Converter
+public class CustomRuntimeConverter implements TypeConverters {
+
+ @Converter
+ public Person toPerson(byte[] data, Exchange exchange){
+ TypeConverter converter = exchange.getContext().getTypeConverter();
+
+ String s = converter.convertTo(String.class, data);
+
+ final String[] splitData = s.split(" ");
+ final String firstName = splitData[0];
+ final String lastName = splitData[1];
+ int age = Integer.parseInt(splitData[2]);
+
+ return new Person(firstName, lastName, age);
+ }
+
+}
diff --git a/camel-example-spring-boot-type-converter/src/main/java/sample/camel/DataTypeConverterRouter.java b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/DataTypeConverterRouter.java
new file mode 100644
index 0000000..4dfa9a8
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/DataTypeConverterRouter.java
@@ -0,0 +1,31 @@
+/*
+ * 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 sample.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class DataTypeConverterRouter extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:convert1")
+ .convertBodyTo(Person.class);
+ }
+}
\ No newline at end of file
diff --git a/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Person.java b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Person.java
new file mode 100644
index 0000000..508359a
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/java/sample/camel/Person.java
@@ -0,0 +1,54 @@
+/*
+ * 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 sample.camel;
+
+public class Person {
+
+ private String firstName;
+ private String lastName;
+ private int age;
+
+ public Person(String firstName, String lastName, int age) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.age = age;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ void setAge(int age) {
+ this.age = age;
+ }
+}
diff --git a/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
new file mode 100644
index 0000000..a71ab18
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
@@ -0,0 +1 @@
+sample.camel.CustomRuntimeConverter
\ No newline at end of file
diff --git a/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverterLoader b/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 0000000..82f34a6
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1 @@
+sample.camel.CustomGeneratedConverter
\ No newline at end of file
diff --git a/camel-example-spring-boot-type-converter/src/main/resources/application.properties b/camel-example-spring-boot-type-converter/src/main/resources/application.properties
new file mode 100644
index 0000000..e967019
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/main/resources/application.properties
@@ -0,0 +1,13 @@
+# the name of Camel
+camel.springboot.name = CamelCustomConverterExample
+
+# required for generated Type Converter Loader - Camel 3.x way
+camel.springboot.load-type-converters=true
+
+# to configure logging levels
+logging.level.org.springframework = INFO
+logging.level.org.apache.camel.spring.boot = INFO
+logging.level.org.apache.camel.impl = INFO
+logging.level.org.apache.camel = INFO
+logging.level.sample.camel = INFO
+#logging.level.sample.camel = DEBUG
diff --git a/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterGeneratedTest.java b/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterGeneratedTest.java
new file mode 100644
index 0000000..95c9613
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterGeneratedTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 sample.camel;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@CamelSpringBootTest
+@SpringBootTest(classes = Application.class)
+public class CustomConverterGeneratedTest {
+
+ @Autowired
+ private CamelContext context;
+
+ private ProducerTemplate producerTemplate;
+
+ @BeforeEach
+ public void setup() {
+ producerTemplate = context.createProducerTemplate();
+ }
+
+ @Test
+ public void testCustomConverter() {
+// Camel 2.x option : adding TypeConverter at runtime
+// Requires TypeConverter file in /META-INF/services/org/apache/camel/
+ context.getTypeConverterRegistry().addTypeConverters(new CustomGeneratedConverter());
+
+ byte[] data = "John Doe 22".getBytes();
+ final Person abc = producerTemplate.requestBody("direct:convert1", data, Person.class);
+
+ assertNotNull(abc);
+
+ assertEquals("John", abc.getFirstName());
+ assertEquals("Doe", abc.getLastName());
+ assertEquals(22, abc.getAge());
+ }
+
+}
diff --git a/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterRuntimeTest.java b/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterRuntimeTest.java
new file mode 100644
index 0000000..b60b858
--- /dev/null
+++ b/camel-example-spring-boot-type-converter/src/test/java/sample/camel/CustomConverterRuntimeTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 sample.camel;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@CamelSpringBootTest
+@SpringBootTest(classes = Application.class)
+public class CustomConverterRuntimeTest {
+
+ @Autowired
+ private CamelContext context;
+
+ private ProducerTemplate producerTemplate;
+
+ @BeforeEach
+ public void setup() {
+ producerTemplate = context.createProducerTemplate();
+ }
+
+ @Test
+ public void testCustomConverter() {
+// Camel 3.x option : Generating Type Converter Loader class
+// Requires TypeConverterLoader file in /META-INF/services/org/apache/camel/
+ context.getTypeConverterRegistry().addTypeConverters(new CustomRuntimeConverter());
+
+ byte[] data = "John Doe 22".getBytes();
+ final Person abc = producerTemplate.requestBody("direct:convert1", data, Person.class);
+
+ assertNotNull(abc);
+
+ assertEquals("John", abc.getFirstName());
+ assertEquals("Doe", abc.getLastName());
+ assertEquals(22, abc.getAge());
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index a939411..3b4f304 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,7 @@
<module>camel-example-spring-boot-servicecall</module>
<module>camel-example-spring-boot-supervising-route-controller</module>
<module>camel-example-spring-boot-twitter-salesforce</module>
+ <module>camel-example-spring-boot-type-converter</module>
<module>camel-example-spring-boot-undertow-spring-security</module>
<module>camel-example-spring-boot-validator</module>
<module>camel-example-spring-boot-webhook</module>