This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d931046ccb3c chore: camel-jbang - sync the bundled examples: the SKU
lookup is Groovy instead of a jsonpath filter
d931046ccb3c is described below
commit d931046ccb3c8ed0067af1f06fecf6ee8beed9ae
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Oct 2 20:13:44 2026 +0200
chore: camel-jbang - sync the bundled examples: the SKU lookup is Groovy
instead of a jsonpath filter
Synced with the sync-example-catalog profile after
apache/camel-jbang-examples#95:
stock-api, http-client and openapi-server unmarshal stock.json and find the
SKU with body.find { it.sku == headers.sku }, the item or null.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
---
.../examples/camel-jbang-example-catalog.json | 9 ++++----
.../connect/http-client/http-client.camel.yaml | 15 ++++++-------
.../resources/examples/connect/stock-api/README.md | 10 ++++-----
.../connect/stock-api/stock-api.camel.yaml | 15 ++++++-------
.../examples/contracts/openapi-server/README.md | 4 ++--
.../openapi-server/openapi-server.camel.yaml | 25 ++++++----------------
6 files changed, 32 insertions(+), 46 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/camel-jbang-example-catalog.json
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/camel-jbang-example-catalog.json
index dbabdbe6816a..3991cebcf06e 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/camel-jbang-example-catalog.json
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/camel-jbang-example-catalog.json
@@ -112,7 +112,7 @@
],
"languages": [
"simple",
- "jsonpath",
+ "groovy",
"constant"
],
"dataformats": [
@@ -548,7 +548,7 @@
],
"languages": [
"simple",
- "jsonpath"
+ "groovy"
],
"dataformats": [
"json"
@@ -589,11 +589,12 @@
"setBody",
"setHeader",
"choice",
+ "unmarshal",
"marshal"
],
"languages": [
"constant",
- "jsonpath",
+ "groovy",
"simple"
],
"dataformats": [
@@ -728,7 +729,7 @@
],
"languages": [
"simple",
- "jsonpath",
+ "groovy",
"constant"
],
"dataformats": [
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/http-client/http-client.camel.yaml
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/http-client/http-client.camel.yaml
index 79f40db5b295..a73f67e54f97 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/http-client/http-client.camel.yaml
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/http-client/http-client.camel.yaml
@@ -19,16 +19,19 @@
expression:
constant:
expression: resource:file:stock.json
+ - unmarshal:
+ json:
+ library: Jackson
+ # the item of that SKU as a map, or null when there is none
- setBody:
expression:
- jsonpath:
- expression: "$[?(@.sku == '${header.sku}')]"
- resultType: java.util.List
+ groovy:
+ expression: "body.find { it.sku == headers.sku }"
- choice:
when:
- expression:
simple:
- expression: "${body.size()} == 0"
+ expression: "${body} == null"
steps:
- setHeader:
name: CamelHttpResponseCode
@@ -41,10 +44,6 @@
expression: '{"error": "unknown sku ${header.sku}"}'
otherwise:
steps:
- - setBody:
- expression:
- simple:
- expression: "${body[0]}"
- marshal:
json:
library: Jackson
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/README.md
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/README.md
index 10cbd834a40f..6cf1cf0cf2c5 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/README.md
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/README.md
@@ -40,17 +40,17 @@ Then, in another terminal, call it with `curl` as above.
Stop it with `ctrl` + `
item. Each operation hands over to a `direct` route. The CLI starts the HTTP
server on port 8080 because the
file uses the REST DSL; `application.properties` sets the port.
- The list route sets the body to `resource:file:stock.json`, the file next to
the route, and the content type.
-- The item route loads the same file and picks the item with a `jsonpath`
filter, `$[?(@.sku == '...')]`, in which
- the `{sku}` path parameter arrives as the header `sku`. The result is a
list: empty means 404 with a small error
- body, otherwise the first element is marshalled back to JSON.
+- The item route loads the same file, unmarshals it into a list of maps, and
picks the item with one line of Groovy,
+ `body.find { it.sku == headers.sku }`, in which the `{sku}` path parameter
arrives as the header `sku`. The result is
+ the item or null: null means 404 with a small error body, otherwise the item
is marshalled back to JSON.
- `CamelHttpResponseCode` is the header that sets the status code; 200 is the
default.
## Build it step by step
1. A `rest` with one `get` that answers `resource:file:stock.json`; run it and
`curl localhost:8080/stock`.
2. Add the `/{sku}` operation and log `${header.sku}` to see the path
parameter arrive.
-3. Filter the file with `jsonpath` and return the first element; `curl` a
known SKU.
-4. Add the `choice` for the empty result and the 404.
+3. Unmarshal the file and find the item with Groovy, `body.find { it.sku ==
headers.sku }`; `curl` a known SKU.
+4. Add the `choice` for the null result and the 404.
## Try changing
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/stock-api.camel.yaml
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/stock-api.camel.yaml
index b5464b803204..94fafe5b8933 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/stock-api.camel.yaml
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/connect/stock-api/stock-api.camel.yaml
@@ -37,16 +37,19 @@
expression:
constant:
expression: resource:file:stock.json
+ - unmarshal:
+ json:
+ library: Jackson
+ # the item of that SKU as a map, or null when there is none
- setBody:
expression:
- jsonpath:
- expression: "$[?(@.sku == '${header.sku}')]"
- resultType: java.util.List
+ groovy:
+ expression: "body.find { it.sku == headers.sku }"
- choice:
when:
- expression:
simple:
- expression: "${body.size()} == 0"
+ expression: "${body} == null"
steps:
- setHeader:
name: CamelHttpResponseCode
@@ -59,10 +62,6 @@
expression: '{"error": "unknown sku ${header.sku}"}'
otherwise:
steps:
- - setBody:
- expression:
- simple:
- expression: "${body[0]}"
- marshal:
json:
library: Jackson
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/README.md
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/README.md
index 04fbb1092666..746aaa90b5fa 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/README.md
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/README.md
@@ -48,8 +48,8 @@ Stop it with `ctrl` + `c`.
`apiContextPath: openapi` serves the contract.
- Each operation is a `direct` route named after its `operationId`:
`listStock`, `getStock`, `reserveStock`.
Path parameters arrive as headers, `sku` here; the request body is the
message body.
-- `lookup` is a helper route the two SKU operations share: it filters the
stock file with `jsonpath` and
- leaves the item, or null, as the body.
+- `lookup` is a helper route the two SKU operations share: it unmarshals the
stock file and finds the SKU
+ with Groovy, `body.find { it.sku == headers.sku }`, which leaves the item,
or null, as the body.
- The contract check does not look at the values, so `reserveStock` runs
`validate` on them and an
`onException` turns the failed predicate into a 400 with an error body, the
status the contract promises.
- `CamelHttpResponseCode` sets 404 and 409; the bodies are the JSON the
contract's `Error` schema describes.
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/openapi-server.camel.yaml
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/openapi-server.camel.yaml
index 23d364e09707..d2f497b6ceb1 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/openapi-server.camel.yaml
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/examples/contracts/openapi-server/openapi-server.camel.yaml
@@ -139,24 +139,11 @@
expression:
constant:
expression: resource:file:stock.json
+ - unmarshal:
+ json:
+ library: Jackson
+ # the item of that SKU as a map, or null when there is none
- setBody:
expression:
- jsonpath:
- expression: "$[?(@.sku == '${header.sku}')]"
- resultType: java.util.List
- - choice:
- when:
- - expression:
- simple:
- expression: "${body.size()} == 0"
- steps:
- - setBody:
- expression:
- simple:
- expression: "${null}"
- otherwise:
- steps:
- - setBody:
- expression:
- simple:
- expression: "${body[0]}"
+ groovy:
+ expression: "body.find { it.sku == headers.sku }"