This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-23688-receive-empty-dump in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8c02e4997fb3c130a1c3c893c488278abf079982 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Oct 16 23:53:41 2026 +0200 CAMEL-23688: camel-console - the receive dev console dumps nothing when it has received nothing The receive dev console took the timestamps of the first and last message of a dump without checking that there was a message, so a dump with nothing received yet, or since the last dump, failed with an IndexOutOfBoundsException. The CLI connector of an integration dumps it all the time, which failed (and was swallowed) whenever no message had come in, and a dump through the HTTP dev console failed. Found while testing camel cmd receive. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/impl/console/ReceiveDevConsole.java | 22 ++++++++++++++-------- .../camel/impl/console/ReceiveDevConsoleTest.java | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java index 0c38c24a20ed..97a406aac315 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java @@ -164,10 +164,13 @@ public class ReceiveDevConsole extends AbstractDevConsole { if (removeOnDump) { q.clear(); } - JsonObject jo = (JsonObject) arr.get(0); - firstTimestamp = jo.getLongOrDefault("timestamp", 0); - jo = (JsonObject) arr.get(arr.size() - 1); - lastTimestamp = jo.getLongOrDefault("timestamp", 0); + // nothing may have been received since the last dump + if (!arr.isEmpty()) { + JsonObject jo = (JsonObject) arr.get(0); + firstTimestamp = jo.getLongOrDefault("timestamp", 0); + jo = (JsonObject) arr.get(arr.size() - 1); + lastTimestamp = jo.getLongOrDefault("timestamp", 0); + } String json = arr.toJson(); sb.append(json).append("\n"); return sb.toString(); @@ -216,10 +219,13 @@ public class ReceiveDevConsole extends AbstractDevConsole { if (removeOnDump) { q.clear(); } - JsonObject first = (JsonObject) messages.get(0); - firstTimestamp = first.getLongOrDefault("timestamp", 0); - JsonObject last = (JsonObject) messages.get(messages.size() - 1); - lastTimestamp = last.getLongOrDefault("timestamp", 0); + // nothing may have been received since the last dump + if (!messages.isEmpty()) { + JsonObject first = (JsonObject) messages.get(0); + firstTimestamp = first.getLongOrDefault("timestamp", 0); + JsonObject last = (JsonObject) messages.get(messages.size() - 1); + lastTimestamp = last.getLongOrDefault("timestamp", 0); + } Response response = new Response(messages, null, null, null, null, null, null, null, null); return JsonRecordSupport.toJsonObject(response); diff --git a/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java b/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java index c81502b34e4e..e869996ea626 100644 --- a/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java +++ b/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java @@ -16,10 +16,15 @@ */ package org.apache.camel.impl.console; +import java.util.Collection; +import java.util.Map; + import org.apache.camel.console.DevConsole; +import org.apache.camel.support.service.ServiceHelper; import org.apache.camel.util.json.JsonObject; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,4 +45,20 @@ public class ReceiveDevConsoleTest extends AbstractDevConsoleTest { assertNotNull(jsonOut.get("enabled")); assertNotNull(jsonOut.get("total")); } + + @Test + public void testDumpWithoutMessages() { + DevConsole console = assertConsoleExists("receive", "camel"); + // started, as the dev console registry of an application does + ServiceHelper.startService(console); + + // nothing received yet, or since the last dump: the camel cli connector dumps all the time + String textOut = callText(console, Map.of("dump", "true")); + assertEquals("[]", textOut.trim()); + + JsonObject jsonOut = callJson(console, Map.of("dump", "true")); + Collection<?> messages = jsonOut.getCollection("messages"); + assertNotNull(messages); + assertTrue(messages.isEmpty()); + } }
