This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch standby in repository https://gitbox.apache.org/repos/asf/camel.git
commit a0bc3b8aa8d2882a6d2874d2d4d834406e658981 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Nov 22 10:18:42 2023 +0100 CAMEL-20136: Enable source location if debug or tracing in standby mode --- .../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() + }; + } + +}
