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 3f42c46a8aca CAMEL-25200: camel-yaml-dsl-validator - the body check
reads the calls between routes as EndpointRules does (#30802)
3f42c46a8aca is described below
commit 3f42c46a8acafca477ddb69fd763cdf78977e54b
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 25 22:12:15 2026 +0100
CAMEL-25200: camel-yaml-dsl-validator - the body check reads the calls
between routes as EndpointRules does (#30802)
The check that a route reads a body nothing ever sets follows the calls
between the routes of a file. It read them with its own rules, which
differed from the EndpointRules that camel validate and camel overview
use for the endpoints between routes (CAMEL-25180):
- direct://lookup and direct:lookup are the same endpoint: a call or a
route written with the slashes was not linked, so a finding was missed.
- an enrich with a constant endpoint (enrich: {constant: direct:lookup})
calls the route, as EndpointConsumers already reads it.
- a pollEnrich consumes its endpoint and does not call the route; it is
still a step that sends for the text body checks (RouteGraph.SENDS).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/dsl/yaml/validator/BodyTypeFlow.java | 4 +-
.../dsl/yaml/validator/EndpointConsumers.java | 2 +-
.../camel/dsl/yaml/validator/RouteGraph.java | 24 ++++--
.../camel/dsl/yaml/validator/BodyTypeFlowTest.java | 87 ++++++++++++++++++++++
4 files changed, 109 insertions(+), 8 deletions(-)
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlow.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlow.java
index 6fd79327bb2c..818069ed571f 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlow.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlow.java
@@ -185,10 +185,10 @@ final class BodyTypeFlow {
/** Whether this step is the call to that route. */
private static boolean sendsToTheRoute(String name, JsonNode value, String
wanted) {
- if (!"to".equals(name) && !"toD".equals(name) &&
!"enrich".equals(name) && !"wireTap".equals(name)) {
+ if (!RouteGraph.CALLS_A_ROUTE.contains(name)) {
return false;
}
- String uri = endpointOf(value);
+ String uri = EndpointConsumers.uriOf(name, value);
return uri != null && normalize(uri).equals(wanted);
}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/EndpointConsumers.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/EndpointConsumers.java
index 7b75a5e1d978..b75da11e92b4 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/EndpointConsumers.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/EndpointConsumers.java
@@ -213,7 +213,7 @@ public final class EndpointConsumers {
* of {@code pollEnrich: {constant: seda:orders}}), as the Java and XML
checks read them; an expression of another
* language is only known at runtime, and not an endpoint here.
*/
- private static String uriOf(String key, JsonNode value) {
+ static String uriOf(String key, JsonNode value) {
if (("enrich".equals(key) || "pollEnrich".equals(key)) && value !=
null && value.isObject()
&& !value.has("uri")) {
JsonNode constant = value.has("expression") ?
value.get("expression").get("constant") : value.get("constant");
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/RouteGraph.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/RouteGraph.java
index 5d47b8636e70..d2c59080d924 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/RouteGraph.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/RouteGraph.java
@@ -36,9 +36,15 @@ import tools.jackson.databind.JsonNode;
*/
final class RouteGraph {
- /** The steps that send a message to an endpoint. */
+ /** The steps that send a message to an endpoint, or poll one. */
static final Set<String> SENDS = Set.of("to", "toD", "enrich",
"pollEnrich", "wireTap");
+ /**
+ * The steps that call another route with their message, the senders of
{@link EndpointRules} that are steps. A
+ * pollEnrich is not one: it consumes its endpoint, as the route does.
+ */
+ static final Set<String> CALLS_A_ROUTE = Set.of("to", "toD", "enrich",
"wireTap");
+
private RouteGraph() {
}
@@ -118,7 +124,7 @@ final class RouteGraph {
return uri;
}
- /** The endpoints a route sends to, at any depth: to, toD and the enrich
family. */
+ /** The endpoints a route sends to, at any depth: to, toD, enrich and
wireTap. */
static List<String> sendsTo(JsonNode steps) {
List<String> answer = new ArrayList<>();
collect(steps, answer);
@@ -141,8 +147,8 @@ final class RouteGraph {
for (var it = node.propertyNames().iterator(); it.hasNext();) {
String name = it.next();
JsonNode value = node.get(name);
- if (SENDS.contains(name)) {
- String uri = endpointOf(value);
+ if (CALLS_A_ROUTE.contains(name)) {
+ String uri = EndpointConsumers.uriOf(name, value);
if (uri != null) {
answer.add(uri);
}
@@ -227,8 +233,16 @@ final class RouteGraph {
return answer;
}
- /** The endpoint without its options: direct:lookup?timeout=1000 is the
endpoint direct:lookup. */
+ /**
+ * The endpoint without its options: direct:lookup?timeout=1000 is the
endpoint direct:lookup. An endpoint that
+ * links the routes of the application is read as {@link
EndpointRules#endpoint(String)} reads it, so
+ * direct://lookup is direct:lookup too, as Camel resolves both to the
same endpoint.
+ */
static String normalize(String uri) {
+ String endpoint = EndpointRules.endpoint(uri);
+ if (endpoint != null) {
+ return endpoint;
+ }
if (uri == null) {
return "";
}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlowTest.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlowTest.java
index 045684d9ff46..96d1988ff29f 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlowTest.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/BodyTypeFlowTest.java
@@ -249,6 +249,93 @@ public class BodyTypeFlowTest {
assertThat(messages(yaml)).noneMatch(m -> m.contains("reads the
message body"));
}
+ @Test
+ public void testACallWrittenWithSlashesIsACall() {
+ // direct://lookup and direct:lookup are the same endpoint, so the
timer route is the caller of lookup,
+ // whichever side has the slashes
+ String yaml = """
+ - route:
+ id: tick
+ from:
+ uri: timer:tick
+ steps:
+ - to:
+ uri: %s
+ - route:
+ id: lookup
+ from:
+ uri: %s
+ steps:
+ - setBody:
+ expression:
+ jsonpath:
+ expression: "$.sku"
+ """;
+ assertThat(messages(yaml.formatted("direct://lookup",
"direct:lookup")))
+ .anyMatch(m -> m.contains("route lookup: jsonpath reads the
message body")
+ && m.contains("the routes that call it do not set one
either"));
+ assertThat(messages(yaml.formatted("direct:lookup?timeout=1000",
"direct://lookup")))
+ .anyMatch(m -> m.contains("route lookup: jsonpath reads the
message body"));
+ }
+
+ @Test
+ public void testAnEnrichWithAConstantEndpointIsACall() {
+ // enrich sends a copy of the message to its endpoint, written as a
constant expression here
+ String yaml = """
+ - route:
+ id: tick
+ from:
+ uri: timer:tick
+ steps:
+ - enrich:
+ constant: direct:lookup
+ - route:
+ id: lookup
+ from:
+ uri: direct:lookup
+ steps:
+ - setBody:
+ expression:
+ jsonpath:
+ expression: "$.sku"
+ """;
+ assertThat(messages(yaml)).anyMatch(m -> m.contains("route lookup:
jsonpath reads the message body"));
+ }
+
+ @Test
+ public void testAPollEnrichIsNotACall() {
+ // a pollEnrich consumes from the queue, as the route does: it does
not call the route with its message, so
+ // the only caller of lookup is the timer, which sets no body. Its
constant endpoint is read the way the one of
+ // an enrich is, and must not make it a caller
+ String yaml = """
+ - route:
+ id: tick
+ from:
+ uri: timer:tick
+ steps:
+ - to:
+ uri: seda:lookup
+ - route:
+ id: poller
+ from:
+ uri: platform-http:/poll
+ steps:
+ - pollEnrich:
+ constant: seda:lookup
+ timeout: 1000
+ - route:
+ id: lookup
+ from:
+ uri: seda:lookup
+ steps:
+ - setBody:
+ expression:
+ jsonpath:
+ expression: "$.sku"
+ """;
+ assertThat(messages(yaml)).anyMatch(m -> m.contains("route lookup:
jsonpath reads the message body"));
+ }
+
private List<String> messages(String yaml) {
try {
return
validator.validate(yaml).stream().map(Error::getMessage).toList();