You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/11/22 10:04:34 UTC
(camel) branch main updated: CAMEL-20136: Enable source location if debug or tracing in standby mode (#12131)
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 a4af63baa05 CAMEL-20136: Enable source location if debug or tracing in standby mode (#12131)
a4af63baa05 is described below
commit a4af63baa05140336a8e70e0c5382d3deec841b0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 22 11:04:25 2023 +0100
CAMEL-20136: Enable source location if debug or tracing in standby mode (#12131)
---
.../camel/impl/engine/AbstractCamelContext.java | 3 -
.../apache/camel/model/ProcessorDefinition.java | 6 +-
.../org/apache/camel/model/RouteDefinition.java | 7 +-
.../DumpModelAsXmlSourceLocationStandbyTest.java | 81 ++++++++++++++++++++++
4 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index e4e0b4f63b6..49629404a41 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2332,9 +2332,6 @@ public abstract class AbstractCamelContext extends BaseService
}
addService(runtimeEndpointRegistry, true, true);
}
- // setup debugger if not already installed
- if (isDebugging() && getDebugger() == null) {
- }
bindDataFormats();
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 0ead7f1bc73..e4f67115463 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -211,8 +211,10 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
configureChild(output);
getOutputs().add(output);
- if (context != null && (context.isSourceLocationEnabled() || context.isDebugging() || context.isTracing())) {
- // we want to capture source location:line for every output
+ if (context != null && (context.isSourceLocationEnabled()
+ || context.isDebugging() || context.isDebugStandby()
+ || context.isTracing() || context.isTracingStandby())) {
+ // we want to capture source location:line for every output (also when debugging or tracing enabled/standby)
Resource resource = this instanceof ResourceAware ? ((ResourceAware) this).getResource() : null;
ProcessorDefinitionHelper.prepareSourceLocation(resource, output);
}
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
index 3cb51242e3c..1944ca9474e 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -783,9 +783,10 @@ public class RouteDefinition extends OutputDefinition<RouteDefinition>
// does not have a <from> as it is implied to be the rest endpoint
this.input = input;
- if (getCamelContext() != null && (getCamelContext().isSourceLocationEnabled() || getCamelContext().isDebugging()
- || getCamelContext().isTracing())) {
- // we want to capture source location:line for every output
+ if (getCamelContext() != null && (getCamelContext().isSourceLocationEnabled()
+ || getCamelContext().isDebugging() || getCamelContext().isDebugStandby()
+ || getCamelContext().isTracing() || getCamelContext().isTracingStandby())) {
+ // we want to capture source location:line for every output (also when debugging or tracing enabled/standby)
ProcessorDefinitionHelper.prepareSourceLocation(getResource(), input);
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlSourceLocationStandbyTest.java b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlSourceLocationStandbyTest.java
new file mode 100644
index 00000000000..2d853ad4dd9
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlSourceLocationStandbyTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.PluginHelper;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class DumpModelAsXmlSourceLocationStandbyTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ // should capture source location in standby mode
+ context.setDebugging(false);
+ context.setDebugStandby(true);
+ return context;
+ }
+
+ @Test
+ public void testDumpModelAsXml() throws Exception {
+ // turn on debugging before dump to include source
+ context.setDebugging(true);
+
+ String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
+ assertNotNull(xml);
+ log.info(xml);
+
+ Assertions.assertTrue(xml.contains(
+ "sourceLineNumber=\"72\" sourceLocation=\"DumpModelAsXmlSourceLocationStandbyTest.java\""));
+ }
+
+ @Test
+ public void testDumpModelAsXmlExternal() throws Exception {
+ // turn on debugging before dump to include source
+ context.setDebugging(true);
+
+ String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, context.getRouteDefinition("cool"));
+ assertNotNull(xml);
+ log.info(xml);
+
+ Assertions.assertTrue(xml.contains(
+ "sourceLineNumber=\"25\" sourceLocation=\"MyCoolRoute.java\" uri=\"direct:cool\"/>"));
+ Assertions.assertTrue(xml.contains("sourceLineNumber=\"26\" sourceLocation=\"MyCoolRoute.java\""));
+ }
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {
+ new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").routeId("myRoute")
+ .filter(simple("${body} > 10"))
+ .to("mock:result");
+ }
+ },
+ new MyCoolRoute()
+ };
+ }
+
+}