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

commit 8568fca71200d78a170b3f80553f97d9dbcbfa54
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon May 13 12:38:17 2024 +0200

    CAMEL-20761: camel-debug - Message history must be enabled when debugging. 
Also history must come before debugger advice.
---
 .../camel/component/debug/CamelDebuggerFactory.java     |  8 ++++++++
 .../org/apache/camel/impl/engine/DefaultChannel.java    | 17 +++++++++++------
 .../java/org/apache/camel/main/BaseMainSupport.java     |  4 +++-
 .../apache/camel/management/BacklogDebuggerTest.java    |  2 +-
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-debug/src/main/java/org/apache/camel/component/debug/CamelDebuggerFactory.java
 
b/components/camel-debug/src/main/java/org/apache/camel/component/debug/CamelDebuggerFactory.java
index 204947c447b..aaf032cc051 100644
--- 
a/components/camel-debug/src/main/java/org/apache/camel/component/debug/CamelDebuggerFactory.java
+++ 
b/components/camel-debug/src/main/java/org/apache/camel/component/debug/CamelDebuggerFactory.java
@@ -35,6 +35,14 @@ public class CamelDebuggerFactory implements DebuggerFactory 
{
             BacklogDebugger backlog = 
DefaultBacklogDebugger.createDebugger(camelContext);
             backlog.setStandby(camelContext.isDebugStandby());
 
+            // must enable source location and history
+            // so debugger tooling knows to map breakpoints to source code
+            camelContext.setSourceLocationEnabled(true);
+            camelContext.setMessageHistory(true);
+
+            // enable debugger on camel
+            camelContext.setDebugging(true);
+
             // we need to enable debugger after context is started
             camelContext.addLifecycleStrategy(new LifecycleStrategySupport() {
                 @Override
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
index 07539ebedc0..d6be2911808 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
@@ -176,8 +176,10 @@ public class DefaultChannel extends CamelInternalProcessor 
implements Channel {
         // as we do not want regular tracer to trace the debugger)
         if (camelContext.isDebugStandby() || route.isDebugging()) {
             final Debugger customDebugger = camelContext.getDebugger();
+            final MessageHistoryFactory messageHistoryFactory = 
camelContext.getMessageHistoryFactory();
             if (customDebugger != null) {
                 // use custom debugger
+                addAdvice(new MessageHistoryAdvice(messageHistoryFactory, 
targetOutputDef));
                 addAdvice(new DebuggerAdvice(customDebugger, nextProcessor, 
targetOutputDef));
             }
             BacklogDebugger debugger = getBacklogDebugger(camelContext, 
customDebugger == null);
@@ -192,12 +194,13 @@ public class DefaultChannel extends 
CamelInternalProcessor implements Channel {
                 if (!skip && routeDefinition != null) {
                     backlogDebuggerSetupInitialBreakpoints(definition, 
routeDefinition, first, debugger, targetOutputDef);
                     if (first && debugger.isSingleStepIncludeStartEnd()) {
-                        // add breakpoint on route input instead of first node
-                        addAdvice(new BacklogDebuggerAdvice(debugger, 
nextProcessor, routeDefinition.getInput()));
                         // debugger captures message history, and we need to 
capture history of incoming
                         addAdvice(
                                 new 
MessageHistoryAdvice(camelContext.getMessageHistoryFactory(), 
routeDefinition.getInput()));
+                        // add breakpoint on route input instead of first node
+                        addAdvice(new BacklogDebuggerAdvice(debugger, 
nextProcessor, routeDefinition.getInput()));
                     }
+                    addAdvice(new MessageHistoryAdvice(messageHistoryFactory, 
targetOutputDef));
                     addAdvice(new BacklogDebuggerAdvice(debugger, 
nextProcessor, targetOutputDef));
                 }
             }
@@ -214,10 +217,12 @@ public class DefaultChannel extends 
CamelInternalProcessor implements Channel {
             addAdvice(new TracingAdvice(tracer, targetOutputDef, 
routeDefinition, first));
         }
 
-        if (route.isMessageHistory()) {
-            // add message history advice
-            MessageHistoryFactory factory = 
camelContext.getMessageHistoryFactory();
-            addAdvice(new MessageHistoryAdvice(factory, targetOutputDef));
+        // debugger will automatically include message history
+        boolean debugging = camelContext.isDebugStandby() || 
route.isDebugging();
+        if (!debugging && route.isMessageHistory()) {
+            final MessageHistoryFactory messageHistoryFactory = 
camelContext.getMessageHistoryFactory();
+            // add message history advice (when not debugging)
+            addAdvice(new MessageHistoryAdvice(messageHistoryFactory, 
targetOutputDef));
         }
         // add advice that keeps track of which node is processing
         addAdvice(new NodeHistoryAdvice(targetOutputDef));
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 90a833951f5..4bfddc7212a 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1617,8 +1617,10 @@ public abstract class BaseMainSupport extends 
BaseService {
             return;
         }
 
-        // must enable source location so debugger tooling knows to map 
breakpoints to source code
+        // must enable source location and history
+        // so debugger tooling knows to map breakpoints to source code
         camelContext.setSourceLocationEnabled(true);
+        camelContext.setMessageHistory(true);
 
         // enable debugger on camel
         camelContext.setDebugging(config.isEnabled());
diff --git 
a/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerTest.java
 
b/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerTest.java
index 7661c42a39d..5af09dd12a4 100644
--- 
a/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerTest.java
+++ 
b/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerTest.java
@@ -897,7 +897,7 @@ public class BacklogDebuggerTest extends 
ManagementTestSupport {
         assertTrue(response.getClass().isAssignableFrom(String.class));
         String history = (String) response;
         int count = (history.split("messageHistoryEntry", -1).length) - 1;
-        assertEquals(3, count);
+        assertEquals(4, count);
         
assertTrue(history.contains("processor=\"from[seda://start?concurrentConsumers=2]\""));
         assertTrue(history.contains("routeId=\"route1\""));
         assertTrue(history.contains("processorId=\"route1\""));

Reply via email to