Update Camel from v4.7.0 to v4.8.2

master
OCTOPUSCARDS\yanng 2 weeks ago
parent 2d07aff6b2
commit 5ba204bd59

@ -1,2 +1,5 @@
server:
port: 9090
camel:
springboot:
main-run-controller: true

@ -15,73 +15,66 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<camel.version>4.7.0</camel.version>
<jackson.version>2.17.2</jackson.version>
<camel.version>4.8.2</camel.version>
<cxf.version>4.0.6</cxf.version>
<springboot.version>${project.parent.version}</springboot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-bom</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bom</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-bom</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-xml-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf-rest</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-log-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-bean-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-bean-validator-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-cxf-rest-starter</artifactId>
</dependency>
<!-- jax-rs json provider from jackson -->
<dependency>
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
</dependency>
<!-- CXF WADL definition-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<build>
<plugins>

@ -0,0 +1,91 @@
== Spring Boot Example with Camel exposing REST services using Apache CXF
=== Introduction
This example illustrates how to use https://projects.spring.io/spring-boot/[Spring Boot] with http://camel.apache.org[Camel]. It provides a simple REST service that is created using https://cxf.apache.org/[Apache CXF].
=== Build
You can build this example using:
$ mvn package
=== Run
You can run this example using:
$ mvn spring-boot:run
After the Spring Boot application is started, you can open the following URL in your web browser to access the list of services: http://localhost:8080/services/ including WADL definition
You can also access the REST endpoint from the command line:
List all the users
[source,text]
----
$ curl http://localhost:8080/services/api/user -s | jq .
----
The command will produce the following output:
[source,json]
----
[ {
"id" : 1,
"name" : "John Coltrane"
}, {
"id" : 2,
"name" : "Miles Davis"
}, {
"id" : 3,
"name" : "Sonny Rollins"
} ]
----
Retrieve a specific user
[source,text]
----
$ curl http://localhost:8080/services/api/user/1 -s | jq .
----
The command will produce the following output:
[source,json]
----
{
"id": 1,
"name": "John Coltrane"
}
----
Insert/update user
[source,text]
----
$ curl -X PUT http://localhost:8080/services/api/user --data '{"id":4,"name":"Charlie Parker"}' -H 'Content-Type: application/json' -v
----
The http status code of the response will be https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml#http-status-codes-1[201]
Moreover, the input user is validated according to the annotations on the link:src/main/java/org/apache/camel/example/springboot/cxf/User.java[User bean]
[source,text]
----
$ curl -X PUT http://localhost:8080/services/api/user --data '{"id":4,"name":"C"}' -H 'Content-Type: application/json'
----
will produce a validation error
The Spring Boot application can be stopped pressing `[CTRL] + [C]` in the shell.
=== Help and contributions
If you hit any problem using Camel or have some feedback, then please
https://camel.apache.org/community/support/[let us know].
We also love contributors, so
https://camel.apache.org/community/contributing/[get involved] :-)
The Camel riders!

@ -6,10 +6,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource("classpath:camel-route.xml")
public class Boot {
private static final Logger logger = LoggerFactory.getLogger(Boot.class);

@ -3,6 +3,7 @@ package com.example.camel;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.bean.validator.BeanValidationException;
import org.springframework.stereotype.Component;
import jakarta.ws.rs.core.Response;
@ -12,6 +13,7 @@ public class CamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
//very raw way, just to handle the validation responses
onException(BeanValidationException.class)
.handled(true)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(Response.Status.BAD_REQUEST.getStatusCode()))
@ -19,7 +21,7 @@ public class CamelRouter extends RouteBuilder {
// @formatter:off
from("cxfrs:/api?" +
"resourceClasses=com.example.camel.UserService" +
"resourceClasses="+UserService.class.getName() +
"&bindingStyle=SimpleConsumer" +
"&providers=jaxrsProvider" +
"&loggingFeatureEnabled=true")

@ -1,90 +0,0 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="example-http-inbound">
<from uri="jetty:http://0.0.0.0:9090/example" />
<convertBodyTo type="java.lang.String" />
<log message="[EXAMPLE INBOUND] Received: ${body}" />
<choice>
<when>
<simple>${headers.CamelHttpMethod} == 'POST'</simple>
<setHeader name="type">
<jsonpath>$.notification.type</jsonpath>
</setHeader>
<choice>
<when>
<simple>${header.type} == 'email'</simple>
<log message="[EXAMPLE INBOUND] Received email notification" />
<to uri="direct:email" />
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
<constant>200</constant>
</setHeader>
</when>
<when>
<simple>${header.type} == 'http'</simple>
<log message="[EXAMPLE INBOUND] Received http notification" />
<to uri="direct:http" />
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
<constant>200</constant>
</setHeader>
</when>
<otherwise>
<log message="[EXAMPLE INBOUND] Unknown notification" />
<setBody>
<constant>{ "status": "reject", "type": "unknown" }</constant>
</setBody>
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
<constant>400</constant>
</setHeader>
</otherwise>
</choice>
</when>
<otherwise>
<log
message="[EXAMPLE INBOUND] only POST is accepted (${headers.CamelHttpMethod})" />
<setBody>
<constant>{ "error": "only POST is accepted" }</constant>
</setBody>
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
<constant>500</constant>
</setHeader>
</otherwise>
</choice>
</route>
<route id="example-email">
<from uri="direct:email" />
<log message="[EXAMPLE EMAIL] Sending notification email" />
<setHeader name="to">
<jsonpath>$.notification.to</jsonpath>
</setHeader>
<setHeader name="subject">
<constant>Notification</constant>
</setHeader>
<setBody>
<jsonpath>$.notification.message</jsonpath>
</setBody>
<!-- <to uri="smtp://localhost"/> -->
<setBody>
<simple>{ "status": "email sent", "to": "${header.to}", "subject":
"${header.subject}" }</simple>
</setBody>
</route>
<route id="example-http">
<from uri="direct:http" />
<log message="[EXAMPLE HTTP] Sending http notification" />
<setHeader name="service">
<jsonpath>$.notification.service</jsonpath>
</setHeader>
<!-- <to uri="jetty:..." /> -->
<setBody>
<simple>{ "status": "http requested", "service": "${header.service}"
}</simple>
</setBody>
</route>
</camel:camelContext>
</beans>
Loading…
Cancel
Save