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-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new 6de672a1bd3 CAMEL-20078: camel-jbang - Debug command 6de672a1bd3 is described below commit 6de672a1bd3aec1e2ec8c588d120fff2ea8f2797 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Nov 4 09:19:17 2023 +0100 CAMEL-20078: camel-jbang - Debug command --- .../src/main/docs/spring-boot.json | 80 +++++++++- .../spring/boot/CamelConfigurationProperties.java | 7 - .../boot/debug/CamelDebugAutoConfiguration.java | 77 ++++++++++ .../debug/CamelDebugConfigurationProperties.java | 164 +++++++++++++++++++++ ...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +- 5 files changed, 315 insertions(+), 15 deletions(-) diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json index 024bbfdf1ef..a7ddce211b3 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -73,6 +73,11 @@ "sourceType": "org.apache.camel.spring.boot.DataFormatConfigurationProperties", "sourceMethod": "getCustomizer()" }, + { + "name": "camel.debug", + "type": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties" + }, { "name": "camel.health", "type": "org.apache.camel.spring.boot.actuate.health.CamelHealthCheckConfigurationProperties", @@ -421,6 +426,74 @@ "sourceType": "org.apache.camel.spring.boot.DataFormatConfigurationProperties", "defaultValue": true }, + { + "name": "camel.debug.body-include-files", + "type": "java.lang.Boolean", + "description": "Whether to include the message body of file based messages. The overhead is that the file content has to be read from the file.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.debug.body-include-streams", + "type": "java.lang.Boolean", + "description": "Whether to include the message body of stream based messages. If enabled then beware the stream may not be re-readable later. See more about Stream Caching.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.debug.body-max-chars", + "type": "java.lang.Integer", + "description": "To limit the message body to a maximum size in the traced message. Use 0 or negative value to use unlimited size.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": 0 + }, + { + "name": "camel.debug.breakpoints", + "type": "java.lang.String", + "description": "Allows to pre-configure breakpoints (node ids) to use with debugger on startup. Multiple ids can be separated by comma. Use special value FIRST_ROUTES to add a breakpoint for the first node for every route, in other words this makes it easy to debug from the beginning of every route without knowing the exact node ids.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties" + }, + { + "name": "camel.debug.enabled", + "type": "java.lang.Boolean", + "description": "Enables Debugger in your Camel application.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.debug.include-exception", + "type": "java.lang.Boolean", + "description": "Trace messages to include exception if the message failed", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.debug.include-exchange-properties", + "type": "java.lang.Boolean", + "description": "Whether to include the exchange properties in the traced message", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.debug.logging-level", + "type": "org.apache.camel.LoggingLevel", + "description": "The debugger logging level to use when logging activity.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties" + }, + { + "name": "camel.debug.single-step-include-start-end", + "type": "java.lang.Boolean", + "description": "In single step mode, then when the exchange is created and completed, then simulate a breakpoint at start and end, that allows to suspend and watch the incoming\/complete exchange at the route (you can see message body as response, failed exception etc).", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.debug.wait-for-attach", + "type": "java.lang.Boolean", + "description": "Whether the debugger should suspend on startup, and wait for a remote debugger to attach. This is what the IDEA and VSCode tooling is using.", + "sourceType": "org.apache.camel.spring.boot.debug.CamelDebugConfigurationProperties", + "defaultValue": false + }, { "name": "camel.health.consumers-enabled", "type": "java.lang.Boolean", @@ -581,13 +654,6 @@ "sourceType": "org.apache.camel.spring.boot.CamelConfigurationProperties", "defaultValue": false }, - { - "name": "camel.springboot.debugging", - "type": "java.lang.Boolean", - "description": "Sets whether debugging is enabled or not. Default is false.", - "sourceType": "org.apache.camel.spring.boot.CamelConfigurationProperties", - "defaultValue": false - }, { "name": "camel.springboot.description", "type": "java.lang.String", diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java index 99b0e2920f6..eeee8d7e791 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java @@ -385,13 +385,6 @@ public class CamelConfigurationProperties extends DefaultConfigurationProperties */ private boolean typeConverterStatisticsEnabled; - /** - * Sets whether debugging is enabled or not. - * - * Default is false. - */ - private boolean debugging; - /** * Sets whether backlog tracing is enabled or not. * diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugAutoConfiguration.java new file mode 100644 index 00000000000..fae6522ae28 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugAutoConfiguration.java @@ -0,0 +1,77 @@ +/* + * 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.spring.boot.debug; + +import org.apache.camel.CamelContext; +import org.apache.camel.impl.debugger.DefaultBacklogDebugger; +import org.apache.camel.spi.BacklogDebugger; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.support.LifecycleStrategySupport; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnBean(CamelAutoConfiguration.class) +@EnableConfigurationProperties(CamelDebugConfigurationProperties.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +public class CamelDebugAutoConfiguration { + + @Bean + public BacklogDebugger backlogDebugger(CamelContext camelContext, CamelDebugConfigurationProperties config) throws Exception { + if (!config.isEnabled()) { + return null; + } + + // must enable source location so debugger tooling knows to map breakpoints to source code + camelContext.setSourceLocationEnabled(true); + + // enable debugger on camel + camelContext.setDebugging(true); + + BacklogDebugger debugger = DefaultBacklogDebugger.createDebugger(camelContext); + debugger.setInitialBreakpoints(config.getBreakpoints()); + debugger.setSingleStepIncludeStartEnd(config.isSingleStepIncludeStartEnd()); + debugger.setBodyMaxChars(config.getBodyMaxChars()); + debugger.setBodyIncludeStreams(config.isBodyIncludeStreams()); + debugger.setBodyIncludeFiles(config.isBodyIncludeFiles()); + debugger.setIncludeExchangeProperties(config.isIncludeExchangeProperties()); + debugger.setIncludeException(config.isIncludeException()); + debugger.setLoggingLevel(config.getLoggingLevel().name()); + debugger.setSuspendMode(config.isWaitForAttach()); + + // start debugger after context is started + camelContext.addLifecycleStrategy(new LifecycleStrategySupport() { + @Override + public void onContextStarted(CamelContext context) { + debugger.enableDebugger(); + } + + @Override + public void onContextStopping(CamelContext context) { + debugger.disableDebugger(); + } + }); + + camelContext.addService(debugger); + + return debugger; + } + +} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugConfigurationProperties.java new file mode 100644 index 00000000000..bf91896bbca --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/debug/CamelDebugConfigurationProperties.java @@ -0,0 +1,164 @@ +/* + * 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.spring.boot.debug; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.spi.Metadata; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.debug") +public class CamelDebugConfigurationProperties { + + /** + * Enables Debugger in your Camel application. + */ + private boolean enabled; + + /** + * Whether the debugger should suspend on startup, and wait for a remote debugger to attach. This is what the IDEA + * and VSCode tooling is using. + */ + private boolean waitForAttach; + + /** + * The debugger logging level to use when logging activity. + */ + @Metadata(defaultValue = "INFO") + private LoggingLevel loggingLevel = LoggingLevel.INFO; + + /** + * Allows to pre-configure breakpoints (node ids) to use with debugger on startup. Multiple ids can be separated by + * comma. Use special value FIRST_ROUTES to add a breakpoint for the first node for every route, in other words this + * makes it easy to debug from the beginning of every route without knowing the exact node ids. + */ + private String breakpoints; + + /** + * In single step mode, then when the exchange is created and completed, then simulate a breakpoint at start and + * end, that allows to suspend and watch the incoming/complete exchange at the route (you can see message body as + * response, failed exception etc). + */ + private boolean singleStepIncludeStartEnd; + + /** + * To limit the message body to a maximum size in the traced message. Use 0 or negative value to use unlimited size. + */ + @Metadata(defaultValue = "131072") + private int bodyMaxChars = 128 * 1024; + + /** + * Whether to include the message body of stream based messages. If enabled then beware the stream may not be + * re-readable later. See more about Stream Caching. + */ + private boolean bodyIncludeStreams; + + /** + * Whether to include the message body of file based messages. The overhead is that the file content has to be read + * from the file. + */ + private boolean bodyIncludeFiles = true; + + /** + * Whether to include the exchange properties in the traced message + */ + private boolean includeExchangeProperties = true; + + /** + * Trace messages to include exception if the message failed + */ + private boolean includeException = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public boolean isWaitForAttach() { + return waitForAttach; + } + + public void setWaitForAttach(boolean waitForAttach) { + this.waitForAttach = waitForAttach; + } + + public LoggingLevel getLoggingLevel() { + return loggingLevel; + } + + public void setLoggingLevel(LoggingLevel loggingLevel) { + this.loggingLevel = loggingLevel; + } + + public String getBreakpoints() { + return breakpoints; + } + + public void setBreakpoints(String breakpoints) { + this.breakpoints = breakpoints; + } + + public boolean isSingleStepIncludeStartEnd() { + return singleStepIncludeStartEnd; + } + + public void setSingleStepIncludeStartEnd(boolean singleStepIncludeStartEnd) { + this.singleStepIncludeStartEnd = singleStepIncludeStartEnd; + } + + public int getBodyMaxChars() { + return bodyMaxChars; + } + + public void setBodyMaxChars(int bodyMaxChars) { + this.bodyMaxChars = bodyMaxChars; + } + + public boolean isBodyIncludeStreams() { + return bodyIncludeStreams; + } + + public void setBodyIncludeStreams(boolean bodyIncludeStreams) { + this.bodyIncludeStreams = bodyIncludeStreams; + } + + public boolean isBodyIncludeFiles() { + return bodyIncludeFiles; + } + + public void setBodyIncludeFiles(boolean bodyIncludeFiles) { + this.bodyIncludeFiles = bodyIncludeFiles; + } + + public boolean isIncludeExchangeProperties() { + return includeExchangeProperties; + } + + public void setIncludeExchangeProperties(boolean includeExchangeProperties) { + this.includeExchangeProperties = includeExchangeProperties; + } + + public boolean isIncludeException() { + return includeException; + } + + public void setIncludeException(boolean includeException) { + this.includeException = includeException; + } +} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index eb2fd0f9aed..58e74acca75 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -27,6 +27,7 @@ org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscoveryAutoConfiguration org.apache.camel.spring.boot.cloud.CamelCloudServiceFilterAutoConfiguration org.apache.camel.spring.boot.cloud.CamelCloudServiceChooserAutoConfiguration org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration +org.apache.camel.spring.boot.debug.CamelDebugAutoConfiguration org.apache.camel.spring.boot.properties.PropertiesComponentAutoConfiguration org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration org.apache.camel.spring.boot.threadpool.CamelThreadPoolAutoConfiguration @@ -35,4 +36,3 @@ org.apache.camel.spring.boot.vault.AwsVaultAutoConfiguration org.apache.camel.spring.boot.vault.GcpVaultAutoConfiguration org.apache.camel.spring.boot.vault.AzureVaultAutoConfiguration org.apache.camel.spring.boot.vault.HashicorpVaultAutoConfiguration -