This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
The following commit(s) were added to refs/heads/main by this push:
new f02dfa8 Use Camel REST DSL in REST JSON example
f02dfa8 is described below
commit f02dfa8a2b6cc5555b404ae16cd952925352fcb7
Author: James Netherton <[email protected]>
AuthorDate: Fri May 7 14:41:02 2021 +0100
Use Camel REST DSL in REST JSON example
---
rest-json/pom.xml | 4 +--
.../src/main/java/org/acme/rest/json/Routes.java | 40 +++++++++++-----------
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/rest-json/pom.xml b/rest-json/pom.xml
index f3f6fd0..c94643a 100644
--- a/rest-json/pom.xml
+++ b/rest-json/pom.xml
@@ -63,11 +63,11 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-platform-http</artifactId>
+ <artifactId>camel-quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-jackson</artifactId>
+ <artifactId>camel-quarkus-rest</artifactId>
</dependency>
<!-- test dependencies -->
diff --git a/rest-json/src/main/java/org/acme/rest/json/Routes.java
b/rest-json/src/main/java/org/acme/rest/json/Routes.java
index 431eae0..d6021d8 100644
--- a/rest-json/src/main/java/org/acme/rest/json/Routes.java
+++ b/rest-json/src/main/java/org/acme/rest/json/Routes.java
@@ -21,7 +21,7 @@ import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.dataformat.JsonLibrary;
+import org.apache.camel.model.rest.RestBindingMode;
/**
* Camel route definitions.
@@ -43,26 +43,26 @@ public class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
- from("platform-http:/fruits?httpMethodRestrict=GET,POST")
- .choice()
- .when(simple("${header.CamelHttpMethod} == 'GET'"))
- .setBody()
- .constant(fruits)
- .endChoice()
- .when(simple("${header.CamelHttpMethod} == 'POST'"))
- .unmarshal()
- .json(JsonLibrary.Jackson, Fruit.class)
- .process()
- .body(Fruit.class, fruits::add)
- .setBody()
- .constant(fruits)
- .endChoice()
- .end()
- .marshal().json();
- from("platform-http:/legumes?httpMethodRestrict=GET")
- .setBody().constant(legumes)
- .marshal().json();
+ restConfiguration().bindingMode(RestBindingMode.json);
+
+ rest("/fruits")
+ .get()
+ .route()
+ .setBody().constant(fruits)
+ .endRest()
+ .post()
+ .type(Fruit.class)
+ .route()
+ .process().body(Fruit.class, fruits::add)
+ .setBody().constant(fruits)
+ .endRest();
+
+ rest("/legumes")
+ .get()
+ .route()
+ .setBody().constant(legumes)
+ .endRest();
}
}