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 35c2c80d4504 CAMEL-26929: camel-jbang - camel get consumer and camel
get producer work again (#29908)
35c2c80d4504 is described below
commit 35c2c80d45042c3ddc408c31d8b71fdcdfd8c2b9
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 09:58:24 2026 +0100
CAMEL-26929: camel-jbang - camel get consumer and camel get producer work
again (#29908)
Item 1 of [CAMEL-26929](https://issues.apache.org/jira/browse/CAMEL-26929).
## Problem
`camel get consumer` and `camel get producer` fail with exit 70 on any
integration that has a consumer or producer:
```
$ camel get consumer --json
{"status":"error","code":70,"message":"Cannot invoke
\"String.endsWith(String)\" because \"s\" is null"}
```
Since CAMEL-24565 (Camel 4.23) the consumer and producer dev consoles are
records. Their key for the class is `clazz`, and a hosted service is `hosted`.
`ListConsumer` and `ListProducer` still read `class` and `hostedService`, get
null, and `getType` fails. The TUI was fixed at the time (`StatusParser`); the
CLI was not. The tests passed because their fixtures wrote the old keys by hand.
## Change
- `ListConsumer` and `ListProducer` read `clazz` / `hosted`. If those are
missing they fall back to `class` / `hostedService`, so the CLI keeps working
against integrations on Camel 4.22 and older. This is the same rule
`StatusParser` uses.
- `getType` returns an empty type when there is no class, instead of
failing.
- The test fixtures are now built from `ConsumerDevConsole.ConsumerEntry` /
`ProducerDevConsole.ProducerEntry` with `JsonRecordSupport`, so renaming a
console key breaks a test. Each command gets a new test for the old keys.
I also checked the other console keys CAMEL-24565 removed against every key
the CLI reads. `clazz` and `hosted` are the only renamed keys the CLI depends
on.
## Tests
`ListConsumerTest` and `ListProducerTest`: 11 tests. Without the fix, 7 of
them fail with the NullPointerException above; with the fix all pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../jbang/core/commands/process/ListConsumer.java | 8 ++-
.../jbang/core/commands/process/ListProducer.java | 6 +-
.../core/commands/process/ListConsumerTest.java | 76 ++++++++++++++++++----
.../core/commands/process/ListProducerTest.java | 46 ++++++++++---
4 files changed, 111 insertions(+), 25 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumer.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumer.java
index 6e6b65d75bce..7b7230566568 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumer.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumer.java
@@ -102,8 +102,9 @@ public class ListConsumer extends ProcessWatchCommand {
row.id = o.getString("id");
row.uri = o.getString("uri");
row.state = o.getString("state");
- row.className = o.getString("class");
- row.hostedService = o.getBooleanOrDefault("hostedService",
false);
+ // the console says clazz and hosted (class and
hostedService before Camel 4.23)
+ row.className = o.getStringOrDefault("clazz",
o.getString("class"));
+ row.hostedService = o.getBooleanOrDefault("hosted",
o.getBooleanOrDefault("hostedService", false));
row.scheduled = o.getBoolean("scheduled");
row.inflight = o.getInteger("inflight");
row.polling = o.getBoolean("polling");
@@ -231,6 +232,9 @@ public class ListConsumer extends ProcessWatchCommand {
private String getType(Row r) {
String s = r.className;
+ if (s == null) {
+ return "";
+ }
if (s.endsWith("Consumer")) {
s = s.substring(0, s.length() - 8);
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducer.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducer.java
index 2e6698098d85..6c7b832db526 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducer.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducer.java
@@ -97,7 +97,8 @@ public class ListProducer extends ProcessWatchCommand {
row.uri = o.getString("uri");
row.id = o.getString("routeId");
row.state = o.getString("state");
- row.className = o.getString("class");
+ // the console says clazz (class before Camel 4.23)
+ row.className = o.getStringOrDefault("clazz",
o.getString("class"));
row.singleton = o.getBoolean("singleton");
row.remote = o.getBoolean("remote");
row.uptime = extractSince(ph);
@@ -188,6 +189,9 @@ public class ListProducer extends ProcessWatchCommand {
private String getType(Row r) {
String s = r.className;
+ if (s == null) {
+ return "";
+ }
if (s.endsWith("Producer")) {
s = s.substring(0, s.length() - 8);
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumerTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumerTest.java
index d31e51f557bd..81f032f291fa 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumerTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListConsumerTest.java
@@ -17,11 +17,14 @@
package org.apache.camel.dsl.jbang.core.commands.process;
import java.util.Collections;
+import java.util.List;
import java.util.stream.Stream;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.impl.console.ConsumerDevConsole;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.JsonRecordSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
@@ -107,6 +110,59 @@ class ListConsumerTest extends ProcessCommandTestSupport {
}
}
+ @Test
+ void testJsonOutputShowsType() throws Exception {
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("consumers", consumerContainer(consumer()));
+ writeStatusFile(TEST_PID, root);
+
+ ListConsumer command = new ListConsumer(new
CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+ command.jsonOutput = true;
+
+ try (MockedStatic<ProcessHandle> mocked =
mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv ->
Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+
assertTrue(printer.getOutput().contains("\"type\":\"org.apache.camel.component.timer.Timer\""),
+ "Consumer suffix should be removed from type");
+ }
+ }
+
+ @Test
+ void testConsumerOfOlderCamelVersion() throws Exception {
+ // Camel 4.22 and older say class and hostedService
+ JsonObject c = consumer();
+ c.put("class", c.remove("clazz"));
+ c.put("hostedService", c.remove("hosted"));
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("consumers", consumerContainer(c));
+ writeStatusFile(TEST_PID, root);
+
+ ListConsumer command = new ListConsumer(new
CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+ command.jsonOutput = true;
+
+ try (MockedStatic<ProcessHandle> mocked =
mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv ->
Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+
assertTrue(printer.getOutput().contains("\"type\":\"org.apache.camel.component.timer.Timer\""));
+ }
+ }
+
private static JsonObject contextObj() {
JsonObject ctx = new JsonObject();
ctx.put("name", "myApp");
@@ -121,19 +177,13 @@ class ListConsumerTest extends ProcessCommandTestSupport {
return container;
}
+ // built from the record of the consumer console, so a renamed key breaks
this test
private static JsonObject consumer() {
- JsonObject c = new JsonObject();
- c.put("id", "route1");
- c.put("uri", "timer:tick");
- c.put("state", "Started");
- c.put("class", "org.apache.camel.component.timer.TimerConsumer");
- c.put("inflight", 0);
- c.put("polling", false);
- c.put("scheduled", false);
- c.put("hostedService", false);
- c.put("totalCounter", 0L);
- c.put("delay", 0L);
- c.put("period", 1000L);
- return c;
+ ConsumerDevConsole.ConsumerEntry entry = new
ConsumerDevConsole.ConsumerEntry(
+ "route1", "timer:tick", "Started",
"org.apache.camel.component.timer.TimerConsumer", false, false, 0, true,
+ null, null, null, null, null, null, null, null, null, null,
"OFF", 0L, null, null, null, null, null, null,
+ null, null, null, "tick", false, 1000L, null);
+ JsonObject response = JsonRecordSupport.toJsonObject(new
ConsumerDevConsole.Response(List.of(entry)));
+ return (JsonObject) ((JsonArray) response.get("consumers")).get(0);
}
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducerTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducerTest.java
index 90d58230e34d..addce01746de 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducerTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListProducerTest.java
@@ -17,11 +17,14 @@
package org.apache.camel.dsl.jbang.core.commands.process;
import java.util.Collections;
+import java.util.List;
import java.util.stream.Stream;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.impl.console.ProducerDevConsole;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.JsonRecordSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
@@ -163,7 +166,35 @@ class ListProducerTest extends ProcessCommandTestSupport {
String output = printer.getOutput();
assertTrue(output.startsWith("["), "JSON output should be array");
assertTrue(output.contains("direct:out"));
- assertTrue(output.contains("Log"), "Producer suffix should be
removed from type");
+
assertTrue(output.contains("\"type\":\"org.apache.camel.component.log.Log\""),
+ "Producer suffix should be removed from type");
+ }
+ }
+
+ @Test
+ void testProducerOfOlderCamelVersion() throws Exception {
+ // Camel 4.22 and older say class
+ JsonObject p = producer("route1", "direct:out");
+ p.put("class", p.remove("clazz"));
+ JsonObject root = new JsonObject();
+ root.put("context", contextObj());
+ root.put("producers", producerContainer(p));
+ writeStatusFile(TEST_PID, root);
+
+ ListProducer command = new ListProducer(new
CamelJBangMain().withPrinter(printer));
+ command.sort = "pid";
+ command.jsonOutput = true;
+
+ try (MockedStatic<ProcessHandle> mocked =
mockStatic(ProcessHandle.class)) {
+ ProcessHandle ph = mockProcessHandle(TEST_PID);
+ ProcessHandle currentHandle = mockCurrentHandle();
+ mocked.when(ProcessHandle::current).thenReturn(currentHandle);
+ mocked.when(ProcessHandle::allProcesses).thenAnswer(inv ->
Stream.of(ph));
+
+ int exit = command.doCall();
+
+ assertEquals(0, exit);
+
assertTrue(printer.getOutput().contains("\"type\":\"org.apache.camel.component.log.Log\""));
}
}
@@ -181,14 +212,11 @@ class ListProducerTest extends ProcessCommandTestSupport {
return container;
}
+ // built from the record of the producer console, so a renamed key breaks
this test
private static JsonObject producer(String routeId, String uri) {
- JsonObject p = new JsonObject();
- p.put("routeId", routeId);
- p.put("uri", uri);
- p.put("state", "Started");
- p.put("class", "org.apache.camel.component.log.LogProducer");
- p.put("singleton", true);
- p.put("remote", false);
- return p;
+ ProducerDevConsole.ProducerEntry entry = new
ProducerDevConsole.ProducerEntry(
+ uri, "Started", "org.apache.camel.component.log.LogProducer",
false, true, routeId, null);
+ JsonObject response = JsonRecordSupport.toJsonObject(new
ProducerDevConsole.Response(List.of(entry)));
+ return (JsonObject) ((JsonArray) response.get("producers")).get(0);
}
}