Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions platform-http/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)

----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
@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")

.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()
Expand All @@ -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()
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
* Service interface for managing todos.
*/
public interface TodoService {
Collection<Todo> findNotCompleted();
Collection<Todo> findNotCompleted();

Collection<Todo> findCompleted();
Collection<Todo> 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<Todo> listAll();
Collection<Todo> listAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,60 +27,60 @@
@Service("todoService")
public class TodoServiceImpl implements TodoService {

private Map<Long, Todo> todos = new ConcurrentHashMap<>();
private AtomicLong counter = new AtomicLong(1);
private Map<Long, Todo> todos = new ConcurrentHashMap<>();
private AtomicLong counter = new AtomicLong(1);

@Override
public Collection<Todo> findNotCompleted() {
return todos.values().stream().filter(todo -> !todo.isCompleted()).collect(Collectors.toList());
}
@Override
public Collection<Todo> findNotCompleted() {
return todos.values().stream().filter(todo -> !todo.isCompleted()).collect(Collectors.toList());
}

@Override
public Collection<Todo> findCompleted() {
return todos.values().stream().filter(Todo::isCompleted).collect(Collectors.toList());
}
@Override
public Collection<Todo> 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<Todo> listAll() {
return todos.values();
}
@Override
public Collection<Todo> listAll() {
return todos.values();
}
}
Loading