Learning integrating of Apache Camel into a Java Spring Boot application..in a funny way!
This is a small demo project that uses Apache Camel and Spring Boot to create a simple API gateway. The application exposes a REST endpoint that, when called, queries a public random joke API, processes its JSON response, and returns a simplified, clean version to the user.
It's was made for learning the basic concepts of integration with Apache Camel in a modern Spring Boot environment.
This project was built to illustrate the following key concepts:
-> Integrating Apache Camel into a Spring Boot application.
-> Defining a REST endpoint using the Camel REST DSL.
-> Calling an external API with the camel-http component.
-> Data transformation (Unmarshalling) from JSON to a Java object (POJO) with camel-jackson.
-> Manipulating the in-flight message (Message Body).
-> Code organization into packages (model, route, config).
Java 21
Spring Boot 3.2.5
Apache Camel 4.6.0
Maven as a build tool
Before you begin, ensure you have the following installed:
JDK 21 or higher
Apache Maven 3.8+
Follow these simple steps to run the application locally:
Clone the repository:
Bash
git clone https://github.com/danotoriousflaco101/Apache_Camel_integration_with_Java_and_SpringBoot
Navigate into the project directory:
Bash
cd Learning_Apache_Camel_integration_with_Java_and_SpringBoot
Run the application using Maven:
Bash
mvn spring-boot:run
This command will download dependencies and start the web server. You will see the Spring Boot banner in your terminal and a message confirming that the application has started on port 8080.
Once the application is running, you can test the endpoint in two ways:
Using a Browser:
Open your favorite browser and visit the following URL:
http://localhost:8080/api/battuta
Using the Terminal (with curl): Open a new terminal and run the command:
Bash
curl http://localhost:8080/api/battuta
In both cases, the expected result is a string of text containing a random joke, for example:
What's the difference between a hippo and a zippo? ... One is really heavy, the other is a little lighter.
This one really sets me on fire, anyway.....
During the creation of this project, i've faced and solved different problems, and they all served as an important lesson:
Version Incompatibility: an incompatible version of Camel being used with the chosen Spring Boot version.
BOM to the Rescue: Introduced a Camel BOM (Bill of Materials) in the section of the pom.xml, allowing it to manage all Camel library versions consistently.
Bean Conflict: A BeanDefinitionOverrideException error occurred because both Camel's auto-configuration and manual configuration were trying to create the same bean. This was solved by excluding the auto-configuration (ServletMappingAutoConfiguration.class) in the @SpringBootApplication annotation.
This process demonstrates the importance of proper dependency management and understanding Spring Boot's auto-configuration mechanisms.
