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 87c8d487d48d chore: camel-jbang - About's Out has a call once when the
route names it with a property placeholder
87c8d487d48d is described below
commit 87c8d487d48d976256906e85174d7a56a80fe6db
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 11 10:25:28 2026 +0100
chore: camel-jbang - About's Out has a call once when the route names it
with a property placeholder
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../dsl/jbang/core/commands/tui/ObservedOuts.java | 42 ++++++++++++++++++++--
.../jbang/core/commands/tui/ObservedOutsTest.java | 15 ++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOuts.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOuts.java
index 19701a8ee5b0..0b42d8cf35de 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOuts.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOuts.java
@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import org.apache.camel.dsl.jbang.core.commands.ai.About;
import org.apache.camel.dsl.jbang.core.commands.ai.AboutReport;
@@ -61,7 +62,7 @@ final class ObservedOuts {
continue;
}
String base = AboutReport.baseUri(ep.uri);
- if (knownUris.contains(base) || consumed.contains(ep.routeId + "|"
+ base)) {
+ if (knownUris.contains(base) || consumed.contains(ep.routeId + "|"
+ base) || named(known, ep.routeId, base)) {
continue;
}
String key = ep.routeId + "|" + group(base);
@@ -99,11 +100,48 @@ final class ObservedOuts {
return scheme.startsWith("http") || scheme.endsWith("http") ? "http" :
scheme;
}
- /** Whether the URI of a line stands for the URIs under it, and so matches
the base URI of an endpoint. */
+ /**
+ * Whether the URI of a line stands for the URIs under it, and so matches
the base URI of an endpoint. A property
+ * placeholder after the scheme stands for its value, which the runtime
has:
+ * http:localhost:{{camel.server.port}}/payment is
http://localhost:8080/payment.
+ */
static boolean matches(String lineUri, String endpointBaseUri) {
if (lineUri.endsWith(MORE)) {
return endpointBaseUri.startsWith(lineUri.substring(0,
lineUri.length() - MORE.length()));
}
+ int placeholder = lineUri.indexOf("{{");
+ if (placeholder > 0 && lineUri.lastIndexOf(':', placeholder) > 0) {
+ // only after a scheme as written: {{ship.url}} can be any endpoint
+ return placeholders(lineUri).matcher(endpointBaseUri).matches();
+ }
return lineUri.equals(endpointBaseUri);
}
+
+ /** Whether a route names the endpoint with a property placeholder, the
endpoint being what the runtime resolved. */
+ private static boolean named(List<About.Out> known, String routeId, String
base) {
+ for (About.Out o : known) {
+ if (routeId.equals(o.route()) && o.uri() != null &&
o.uri().contains("{{")
+ && matches(AboutReport.baseUri(o.uri()), base)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static Pattern placeholders(String uri) {
+ StringBuilder regex = new StringBuilder();
+ int i = 0;
+ int start = uri.indexOf("{{");
+ while (start >= 0) {
+ int end = uri.indexOf("}}", start);
+ if (end < 0) {
+ break;
+ }
+ regex.append(Pattern.quote(uri.substring(i, start))).append(".+?");
+ i = end + 2;
+ start = uri.indexOf("{{", i);
+ }
+ regex.append(Pattern.quote(uri.substring(i)));
+ return Pattern.compile(regex.toString());
+ }
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOutsTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOutsTest.java
index 3985234d4034..aee30bd7618c 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOutsTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ObservedOutsTest.java
@@ -80,6 +80,21 @@ class ObservedOutsTest {
.isEqualTo(6);
}
+ @Test
+ void anOutWithAPlaceholderIsTheOneTheRuntimeResolved() {
+ // fail-well/chaos: the route names
http:localhost:{{camel.server.port}}/payment, the runtime counts it as
+ // http://localhost:8080/payment
+ IntegrationInfo info = new IntegrationInfo();
+ info.endpoints.add(endpoint("orders", "out",
"http://localhost:8080/payment", "remote", 68));
+ List<About.Out> known = List.of(new About.Out("http",
"http:localhost:{{camel.server.port}}/payment", "out", "orders"));
+
+ assertThat(ObservedOuts.of(info, known)).isEmpty();
+ assertThat(AboutView.outHits(info,
"http:localhost:{{camel.server.port}}/payment", "orders")).isEqualTo(68);
+ // the placeholder is the port, not the rest of the URI
+
assertThat(ObservedOuts.matches("http:localhost:{{camel.server.port}}/payment",
"http:localhost:8080/refund"))
+ .isFalse();
+ }
+
@Test
void theServiceOfAUriIsAllButItsLastSegment() {
assertThat(ObservedOuts.group("http://localhost:8080/stock/CAMEL-MUG")).isEqualTo("http://localhost:8080/stock/");