This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-26929-get-consumer-producer
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 95ab3f5c3977392f2770bcf4a10e13f45ba5cca6
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 10:07:25 2026 +0100

    CAMEL-26929: camel-jbang - camel get consumer and camel get producer work 
again
    
    Since Camel 4.23 the consumer and producer consoles are records, and the 
key of the
    class is clazz (and hosted for a hosted service). The commands read the old 
key, got
    null and failed with exit 70 on any integration with a consumer or producer.
    
    Read the new key and fall back to the old one, so integrations of older 
Camel
    versions keep working. The test fixtures are now built from the console 
records,
    so a renamed key breaks a test.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[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);
     }
 }

Reply via email to