diff --git a/platform-http/README.adoc b/platform-http/README.adoc index 8a4a0af23..ab0967dad 100644 --- a/platform-http/README.adoc +++ b/platform-http/README.adoc @@ -6,7 +6,7 @@ This example illustrates how to use https://projects.spring.io/spring-boot/[Spri The project uses the `camel-spring-boot-starter` dependency, a Spring Boot starter dependency for Camel that simplifies the Maven configuration. -The project also uses `camel-servlet-starter` component as the implementation for platform-http-engine. +The project also uses `camel-platform-http-starter`, which exposes the Camel REST DSL routes through the Spring MVC / embedded Tomcat servlet engine provided by `spring-boot-starter-webmvc`. === Build @@ -38,16 +38,15 @@ You should see the following output when the application is launched (timestamp ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ - :: Spring Boot :: (v3.4.5) + :: Spring Boot :: (v4.1.1) -o.a.c.example.springboot.Application : Starting Application using Java 17.0.15 with PID 3707237 +o.a.c.example.springboot.Application : Starting Application using Java 25.0.2 with PID 15931 o.a.c.example.springboot.Application : No active profile set, falling back to 1 default profile: "default" -o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) +o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) o.apache.catalina.core.StandardService : Starting service [Tomcat] -o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.40] -o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext -w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 451 ms -o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/' +o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.24] +b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 479 ms +o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/' o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.23.0-SNAPSHOT (MyCamel) is starting o.a.c.impl.engine.AbstractCamelContext : Routes startup (total:6 rest-dsl:6) o.a.c.impl.engine.AbstractCamelContext : Started route1 (rest://get:/todos) @@ -56,8 +55,8 @@ o.a.c.impl.engine.AbstractCamelContext : Started route3 (rest://patch:/tod o.a.c.impl.engine.AbstractCamelContext : Started route4 (rest://post:/todos) o.a.c.impl.engine.AbstractCamelContext : Started route5 (rest://delete:/todos) o.a.c.impl.engine.AbstractCamelContext : Started route6 (rest://delete:/todos:/%7Bid%7D) -o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.23.0-SNAPSHOT (MyCamel) started in 8ms (build:0ms init:0ms start:8ms boot:428ms) -o.a.c.example.springboot.Application : Started Application in 1.155 seconds (process running for 1.283) +o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.23.0-SNAPSHOT (MyCamel) started in 16ms (build:0ms init:0ms start:16ms boot:430ms) +o.a.c.example.springboot.Application : Started Application in 1.196 seconds (process running for 1.372) ---- diff --git a/platform-http/src/main/java/org/apache/camel/example/springboot/CamelRouter.java b/platform-http/src/main/java/org/apache/camel/example/springboot/CamelRouter.java index c3b264f35..e11bb1960 100644 --- a/platform-http/src/main/java/org/apache/camel/example/springboot/CamelRouter.java +++ b/platform-http/src/main/java/org/apache/camel/example/springboot/CamelRouter.java @@ -30,12 +30,12 @@ @Component public class CamelRouter extends RouteBuilder { - @Override - public void configure() throws Exception { - restConfiguration() - .bindingMode(RestBindingMode.json); + @Override + public void configure() throws Exception { + restConfiguration() + .bindingMode(RestBindingMode.json); - // @formatter:off + // @formatter:off rest("/todos").description("Todo REST service") .consumes("application/json") .produces("application/json") @@ -43,7 +43,7 @@ public void configure() throws Exception { .get().description("Find all todos").outType(Todo[].class) .responseMessage().code(200).message("All todos successfully returned").endResponseMessage() .to("bean:todoService?method=listAll") - + .get("/{id}").description("Find todo by ID") .outType(Todo.class) .param().name("id").type(path).description("The ID of the todo").dataType("long").endParam() @@ -54,7 +54,7 @@ public void configure() throws Exception { .param().name("id").type(path).description("The ID of the todo to update").dataType("long").endParam() .param().name("body").type(body).description("The todo to update").endParam() .responseMessage().code(204).message("Todo successfully updated").endResponseMessage() - .to("bean:todoService?method=update(${body}, ${header.id})") + .to("bean:todoService?method=update(${body}, ${header.id})") .post().description("Create a todo").type(Todo.class) .param().name("body").type(body).endParam() @@ -70,5 +70,5 @@ public void configure() throws Exception { .responseMessage().code(200).message("Todo deleted").endResponseMessage() .to("bean:todoService?method=deleteOne(${header.id})"); // @formatter:on - } + } } diff --git a/platform-http/src/main/java/org/apache/camel/example/springboot/Todo.java b/platform-http/src/main/java/org/apache/camel/example/springboot/Todo.java index e75f28bfe..7ae383a22 100644 --- a/platform-http/src/main/java/org/apache/camel/example/springboot/Todo.java +++ b/platform-http/src/main/java/org/apache/camel/example/springboot/Todo.java @@ -17,60 +17,60 @@ package org.apache.camel.example.springboot; public class Todo { - private long id; - private String title; - private boolean completed; - private int order; - private String url; + private long id; + private String title; + private boolean completed; + private int order; + private String url; - public long getId() { - return id; - } + public long getId() { + return id; + } - public void setId(long id) { - this.id = id; - } + public void setId(long id) { + this.id = id; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - this.title = title; - } + public void setTitle(String title) { + this.title = title; + } - public boolean isCompleted() { - return completed; - } + public boolean isCompleted() { + return completed; + } - public void setCompleted(boolean completed) { - this.completed = completed; - } + public void setCompleted(boolean completed) { + this.completed = completed; + } - public int getOrder() { - return order; - } + public int getOrder() { + return order; + } - public void setOrder(int order) { - this.order = order; - } + public void setOrder(int order) { + this.order = order; + } - public String getUrl() { - return url; - } + public String getUrl() { + return url; + } - public void setUrl(String url) { - this.url = url; - } + public void setUrl(String url) { + this.url = url; + } - @Override - public String toString() { - return "Todo{" + - "id=" + id + - ", title='" + title + '\'' + - ", completed=" + completed + - ", order=" + order + - ", url='" + url + '\'' + - '}'; - } + @Override + public String toString() { + return "Todo{" + + "id=" + id + + ", title='" + title + '\'' + + ", completed=" + completed + + ", order=" + order + + ", url='" + url + '\'' + + '}'; + } } diff --git a/platform-http/src/main/java/org/apache/camel/example/springboot/TodoService.java b/platform-http/src/main/java/org/apache/camel/example/springboot/TodoService.java index a266fe4b9..719a08bfb 100644 --- a/platform-http/src/main/java/org/apache/camel/example/springboot/TodoService.java +++ b/platform-http/src/main/java/org/apache/camel/example/springboot/TodoService.java @@ -22,19 +22,19 @@ * Service interface for managing todos. */ public interface TodoService { - Collection findNotCompleted(); + Collection findNotCompleted(); - Collection findCompleted(); + Collection findCompleted(); - long deleteCompleted(); + long deleteCompleted(); - Todo findById(long id); + Todo findById(long id); - void create(Todo todo); + void create(Todo todo); - Todo update(Todo todo, long id); + Todo update(Todo todo, long id); - void deleteOne(long id); + void deleteOne(long id); - Collection listAll(); + Collection listAll(); } diff --git a/platform-http/src/main/java/org/apache/camel/example/springboot/TodoServiceImpl.java b/platform-http/src/main/java/org/apache/camel/example/springboot/TodoServiceImpl.java index af9e2c392..43e157e7c 100644 --- a/platform-http/src/main/java/org/apache/camel/example/springboot/TodoServiceImpl.java +++ b/platform-http/src/main/java/org/apache/camel/example/springboot/TodoServiceImpl.java @@ -27,60 +27,60 @@ @Service("todoService") public class TodoServiceImpl implements TodoService { - private Map todos = new ConcurrentHashMap<>(); - private AtomicLong counter = new AtomicLong(1); + private Map todos = new ConcurrentHashMap<>(); + private AtomicLong counter = new AtomicLong(1); - @Override - public Collection findNotCompleted() { - return todos.values().stream().filter(todo -> !todo.isCompleted()).collect(Collectors.toList()); - } + @Override + public Collection findNotCompleted() { + return todos.values().stream().filter(todo -> !todo.isCompleted()).collect(Collectors.toList()); + } - @Override - public Collection findCompleted() { - return todos.values().stream().filter(Todo::isCompleted).collect(Collectors.toList()); - } + @Override + public Collection findCompleted() { + return todos.values().stream().filter(Todo::isCompleted).collect(Collectors.toList()); + } - @Override - public long deleteCompleted() { - long completed = todos.values().stream().filter(Todo::isCompleted).count(); + @Override + public long deleteCompleted() { + long completed = todos.values().stream().filter(Todo::isCompleted).count(); - todos.entrySet().removeIf(entry -> entry.getValue().isCompleted()); + todos.entrySet().removeIf(entry -> entry.getValue().isCompleted()); - return completed; - } + return completed; + } - @Override - public Todo findById(long id) { - return todos.get(id); - } + @Override + public Todo findById(long id) { + return todos.get(id); + } - @Override - public void create(Todo todo) { - todo.setId(counter.getAndIncrement()); - todos.put(todo.getId(), todo); - } + @Override + public void create(Todo todo) { + todo.setId(counter.getAndIncrement()); + todos.put(todo.getId(), todo); + } - @Override - public Todo update(Todo todo, long id) { - Todo persistedTodo = todos.get(id); - if (persistedTodo != null) { - persistedTodo.setCompleted(todo.isCompleted()); - persistedTodo.setTitle(todo.getTitle()); - persistedTodo.setOrder(todo.getOrder()); - persistedTodo.setUrl(todo.getUrl()); + @Override + public Todo update(Todo todo, long id) { + Todo persistedTodo = todos.get(id); + if (persistedTodo != null) { + persistedTodo.setCompleted(todo.isCompleted()); + persistedTodo.setTitle(todo.getTitle()); + persistedTodo.setOrder(todo.getOrder()); + persistedTodo.setUrl(todo.getUrl()); - return persistedTodo; - } - return null; - } + return persistedTodo; + } + return null; + } - @Override - public void deleteOne(long id) { - todos.remove(id); - } + @Override + public void deleteOne(long id) { + todos.remove(id); + } - @Override - public Collection listAll() { - return todos.values(); - } + @Override + public Collection listAll() { + return todos.values(); + } }