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/12/30 15:15:02 UTC

(camel) 05/25: CAMEL-19749: Add variables as concept to Camel

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch var
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 10e8d0da4a400d802d7ce23319da0ba71b0db8c3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Dec 28 13:28:01 2023 +0100

    CAMEL-19749: Add variables as concept to Camel
---
 .../org/apache/camel/catalog/components/log.json   |  5 ++--
 .../camel/component/log/LogEndpointConfigurer.java |  6 +++++
 .../camel/component/log/LogEndpointUriFactory.java |  3 ++-
 .../org/apache/camel/component/log/log.json        |  5 ++--
 .../apache/camel/component/log/LogEndpoint.java    | 13 ++++++++-
 .../log/DefaultExchangeFormatterTest.java          |  1 +
 .../DefaultExchangeFormatterConfigurer.java        |  6 +++++
 .../processor/DefaultExchangeFormatter.java        | 19 +++++++++++++
 .../endpoint/dsl/LogEndpointBuilderFactory.java    | 31 ++++++++++++++++++++++
 9 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/log.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/log.json
index 26bebc29b44..64f0087f0e7 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/log.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/log.json
@@ -60,7 +60,8 @@
     "showRouteId": { "index": 28, "kind": "parameter", "displayName": "Show Route Id", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show route ID." },
     "showStackTrace": { "index": 29, "kind": "parameter", "displayName": "Show Stack Trace", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show the stack trace, if an exchange has an exception. Only effective if one of showAll, showException or showCaughtException are enabled." },
     "showStreams": { "index": 30, "kind": "parameter", "displayName": "Show Streams", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether Camel should show stream bodies or not (eg such as java.io.InputStream). Beware if you enable this option then you may not be able later to access the message body as the stream have already bee [...]
-    "skipBodyLineSeparator": { "index": 31, "kind": "parameter", "displayName": "Skip Body Line Separator", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to skip line separators when logging the message body. This allows to log the message body in one line, setting this option to false will preserve any line separators from t [...]
-    "style": { "index": 32, "kind": "parameter", "displayName": "Style", "group": "formatting", "label": "formatting", "required": false, "type": "object", "javaType": "org.apache.camel.support.processor.DefaultExchangeFormatter.OutputStyle", "enum": [ "Default", "Tab", "Fixed" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Default", "description": "Sets the outputs style to use." }
+    "showVariables": { "index": 31, "kind": "parameter", "displayName": "Show Variables", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show the variables." },
+    "skipBodyLineSeparator": { "index": 32, "kind": "parameter", "displayName": "Skip Body Line Separator", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to skip line separators when logging the message body. This allows to log the message body in one line, setting this option to false will preserve any line separators from t [...]
+    "style": { "index": 33, "kind": "parameter", "displayName": "Style", "group": "formatting", "label": "formatting", "required": false, "type": "object", "javaType": "org.apache.camel.support.processor.DefaultExchangeFormatter.OutputStyle", "enum": [ "Default", "Tab", "Fixed" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Default", "description": "Sets the outputs style to use." }
   }
 }
diff --git a/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointConfigurer.java b/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointConfigurer.java
index dc4d54ae626..c7588165c03 100644
--- a/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointConfigurer.java
+++ b/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointConfigurer.java
@@ -75,6 +75,8 @@ public class LogEndpointConfigurer extends PropertyConfigurerSupport implements
         case "showStackTrace": target.setShowStackTrace(property(camelContext, boolean.class, value)); return true;
         case "showstreams":
         case "showStreams": target.setShowStreams(property(camelContext, boolean.class, value)); return true;
+        case "showvariables":
+        case "showVariables": target.setShowVariables(property(camelContext, boolean.class, value)); return true;
         case "skipbodylineseparator":
         case "skipBodyLineSeparator": target.setSkipBodyLineSeparator(property(camelContext, boolean.class, value)); return true;
         case "sourcelocationloggername":
@@ -141,6 +143,8 @@ public class LogEndpointConfigurer extends PropertyConfigurerSupport implements
         case "showStackTrace": return boolean.class;
         case "showstreams":
         case "showStreams": return boolean.class;
+        case "showvariables":
+        case "showVariables": return boolean.class;
         case "skipbodylineseparator":
         case "skipBodyLineSeparator": return boolean.class;
         case "sourcelocationloggername":
@@ -208,6 +212,8 @@ public class LogEndpointConfigurer extends PropertyConfigurerSupport implements
         case "showStackTrace": return target.isShowStackTrace();
         case "showstreams":
         case "showStreams": return target.isShowStreams();
+        case "showvariables":
+        case "showVariables": return target.isShowVariables();
         case "skipbodylineseparator":
         case "skipBodyLineSeparator": return target.isSkipBodyLineSeparator();
         case "sourcelocationloggername":
diff --git a/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointUriFactory.java b/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointUriFactory.java
index dd892a15624..b263d4463c1 100644
--- a/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointUriFactory.java
+++ b/components/camel-log/src/generated/java/org/apache/camel/component/log/LogEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class LogEndpointUriFactory extends org.apache.camel.support.component.En
     private static final Set<String> SECRET_PROPERTY_NAMES;
     private static final Set<String> MULTI_VALUE_PREFIXES;
     static {
-        Set<String> props = new HashSet<>(33);
+        Set<String> props = new HashSet<>(34);
         props.add("exchangeFormatter");
         props.add("groupActiveOnly");
         props.add("groupDelay");
@@ -52,6 +52,7 @@ public class LogEndpointUriFactory extends org.apache.camel.support.component.En
         props.add("showRouteId");
         props.add("showStackTrace");
         props.add("showStreams");
+        props.add("showVariables");
         props.add("skipBodyLineSeparator");
         props.add("sourceLocationLoggerName");
         props.add("style");
diff --git a/components/camel-log/src/generated/resources/org/apache/camel/component/log/log.json b/components/camel-log/src/generated/resources/org/apache/camel/component/log/log.json
index 26bebc29b44..64f0087f0e7 100644
--- a/components/camel-log/src/generated/resources/org/apache/camel/component/log/log.json
+++ b/components/camel-log/src/generated/resources/org/apache/camel/component/log/log.json
@@ -60,7 +60,8 @@
     "showRouteId": { "index": 28, "kind": "parameter", "displayName": "Show Route Id", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show route ID." },
     "showStackTrace": { "index": 29, "kind": "parameter", "displayName": "Show Stack Trace", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show the stack trace, if an exchange has an exception. Only effective if one of showAll, showException or showCaughtException are enabled." },
     "showStreams": { "index": 30, "kind": "parameter", "displayName": "Show Streams", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether Camel should show stream bodies or not (eg such as java.io.InputStream). Beware if you enable this option then you may not be able later to access the message body as the stream have already bee [...]
-    "skipBodyLineSeparator": { "index": 31, "kind": "parameter", "displayName": "Skip Body Line Separator", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to skip line separators when logging the message body. This allows to log the message body in one line, setting this option to false will preserve any line separators from t [...]
-    "style": { "index": 32, "kind": "parameter", "displayName": "Style", "group": "formatting", "label": "formatting", "required": false, "type": "object", "javaType": "org.apache.camel.support.processor.DefaultExchangeFormatter.OutputStyle", "enum": [ "Default", "Tab", "Fixed" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Default", "description": "Sets the outputs style to use." }
+    "showVariables": { "index": 31, "kind": "parameter", "displayName": "Show Variables", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Show the variables." },
+    "skipBodyLineSeparator": { "index": 32, "kind": "parameter", "displayName": "Skip Body Line Separator", "group": "formatting", "label": "formatting", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to skip line separators when logging the message body. This allows to log the message body in one line, setting this option to false will preserve any line separators from t [...]
+    "style": { "index": 33, "kind": "parameter", "displayName": "Style", "group": "formatting", "label": "formatting", "required": false, "type": "object", "javaType": "org.apache.camel.support.processor.DefaultExchangeFormatter.OutputStyle", "enum": [ "Default", "Tab", "Fixed" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Default", "description": "Sets the outputs style to use." }
   }
 }
diff --git a/components/camel-log/src/main/java/org/apache/camel/component/log/LogEndpoint.java b/components/camel-log/src/main/java/org/apache/camel/component/log/LogEndpoint.java
index 8f12cd45f43..f0e2d508cb9 100644
--- a/components/camel-log/src/main/java/org/apache/camel/component/log/LogEndpoint.java
+++ b/components/camel-log/src/main/java/org/apache/camel/component/log/LogEndpoint.java
@@ -87,6 +87,8 @@ public class LogEndpoint extends ProcessorEndpoint implements LineNumberAware {
     private boolean showProperties;
     @UriParam(label = "formatting", description = "Show all of the exchange properties (both internal and custom).")
     private boolean showAllProperties;
+    @UriParam(label = "formatting", description = "Show the variables.")
+    private boolean showVariables;
     @UriParam(label = "formatting", description = "Show the message headers.")
     private boolean showHeaders;
     @UriParam(label = "formatting", defaultValue = "true",
@@ -163,7 +165,7 @@ public class LogEndpoint extends ProcessorEndpoint implements LineNumberAware {
             boolean changed = showExchangePattern || !skipBodyLineSeparator || !showBody || !showBodyType || maxChars != 10000
                     || style != DefaultExchangeFormatter.OutputStyle.Default || plain;
             changed |= showRouteId || showRouteGroup;
-            changed |= showExchangeId || showProperties || showAllProperties || showHeaders || showException
+            changed |= showExchangeId || showProperties || showAllProperties || showVariables || showHeaders || showException
                     || showCaughtException
                     || showStackTrace;
             changed |= showAll || multiline || showFuture || !showCachedStreams || showStreams || showFiles;
@@ -183,6 +185,7 @@ public class LogEndpoint extends ProcessorEndpoint implements LineNumberAware {
                 def.setShowFiles(showFiles);
                 def.setShowFuture(showFuture);
                 def.setShowHeaders(showHeaders);
+                def.setShowVariables(showVariables);
                 def.setShowProperties(showProperties);
                 def.setShowAllProperties(showAllProperties);
                 def.setShowStackTrace(showStackTrace);
@@ -495,6 +498,14 @@ public class LogEndpoint extends ProcessorEndpoint implements LineNumberAware {
         this.showAllProperties = showAllProperties;
     }
 
+    public boolean isShowVariables() {
+        return showVariables;
+    }
+
+    public void setShowVariables(boolean showVariables) {
+        this.showVariables = showVariables;
+    }
+
     public boolean isShowHeaders() {
         return showHeaders;
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
index 0f7ffc779d7..449b76c5204 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
@@ -176,6 +176,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
         assertFalse(formatter.isShowExchangeId());
         assertFalse(formatter.isShowProperties());
         assertFalse(formatter.isShowHeaders());
+        assertFalse(formatter.isShowVariables());
         assertTrue(formatter.isShowBodyType());
         assertTrue(formatter.isShowBody());
         assertFalse(formatter.isShowException());
diff --git a/core/camel-support/src/generated/java/org/apache/camel/support/processor/DefaultExchangeFormatterConfigurer.java b/core/camel-support/src/generated/java/org/apache/camel/support/processor/DefaultExchangeFormatterConfigurer.java
index 5765e5932a2..bf62d2e1d28 100644
--- a/core/camel-support/src/generated/java/org/apache/camel/support/processor/DefaultExchangeFormatterConfigurer.java
+++ b/core/camel-support/src/generated/java/org/apache/camel/support/processor/DefaultExchangeFormatterConfigurer.java
@@ -61,6 +61,8 @@ public class DefaultExchangeFormatterConfigurer extends org.apache.camel.support
         case "ShowStackTrace": target.setShowStackTrace(property(camelContext, boolean.class, value)); return true;
         case "showstreams":
         case "ShowStreams": target.setShowStreams(property(camelContext, boolean.class, value)); return true;
+        case "showvariables":
+        case "ShowVariables": target.setShowVariables(property(camelContext, boolean.class, value)); return true;
         case "skipbodylineseparator":
         case "SkipBodyLineSeparator": target.setSkipBodyLineSeparator(property(camelContext, boolean.class, value)); return true;
         case "style":
@@ -112,6 +114,8 @@ public class DefaultExchangeFormatterConfigurer extends org.apache.camel.support
         case "ShowStackTrace": return boolean.class;
         case "showstreams":
         case "ShowStreams": return boolean.class;
+        case "showvariables":
+        case "ShowVariables": return boolean.class;
         case "skipbodylineseparator":
         case "SkipBodyLineSeparator": return boolean.class;
         case "style":
@@ -164,6 +168,8 @@ public class DefaultExchangeFormatterConfigurer extends org.apache.camel.support
         case "ShowStackTrace": return target.isShowStackTrace();
         case "showstreams":
         case "ShowStreams": return target.isShowStreams();
+        case "showvariables":
+        case "ShowVariables": return target.isShowVariables();
         case "skipbodylineseparator":
         case "SkipBodyLineSeparator": return target.isSkipBodyLineSeparator();
         case "style":
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java b/core/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
index e249806ebf0..ffd911aacf4 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
@@ -63,6 +63,8 @@ public class DefaultExchangeFormatter implements ExchangeFormatter {
     private boolean showProperties;
     @UriParam(label = "formatting", description = "Show all the exchange properties (both internal and custom).")
     private boolean showAllProperties;
+    @UriParam(label = "formatting", description = "Show the variables.")
+    private boolean showVariables;
     @UriParam(label = "formatting", description = "Show the message headers.")
     private boolean showHeaders;
     @UriParam(label = "formatting", defaultValue = "true",
@@ -179,6 +181,12 @@ public class DefaultExchangeFormatter implements ExchangeFormatter {
             }
             style(sb, "Properties").append(sortMap(filterHeaderAndProperties(exchange.getProperties())));
         }
+        if (showAll || showVariables) {
+            if (multiline) {
+                sb.append(SEPARATOR);
+            }
+            style(sb, "Variables").append(sortMap(filterHeaderAndProperties(exchange.getVariables())));
+        }
         if (showAll || showHeaders) {
             if (multiline) {
                 sb.append(SEPARATOR);
@@ -327,6 +335,17 @@ public class DefaultExchangeFormatter implements ExchangeFormatter {
         this.showAllProperties = showAllProperties;
     }
 
+    public boolean isShowVariables() {
+        return showVariables;
+    }
+
+    /**
+     * Show the variables.
+     */
+    public void setShowVariables(boolean showVariables) {
+        this.showVariables = showVariables;
+    }
+
     public boolean isShowHeaders() {
         return showHeaders;
     }
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
index 57a0fefb6f2..842acc4a91d 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
@@ -911,6 +911,37 @@ public interface LogEndpointBuilderFactory {
             doSetProperty("showStreams", showStreams);
             return this;
         }
+        /**
+         * Show the variables.
+         * 
+         * The option is a: &lt;code&gt;boolean&lt;/code&gt; type.
+         * 
+         * Default: false
+         * Group: formatting
+         * 
+         * @param showVariables the value to set
+         * @return the dsl builder
+         */
+        default LogEndpointBuilder showVariables(boolean showVariables) {
+            doSetProperty("showVariables", showVariables);
+            return this;
+        }
+        /**
+         * Show the variables.
+         * 
+         * The option will be converted to a &lt;code&gt;boolean&lt;/code&gt;
+         * type.
+         * 
+         * Default: false
+         * Group: formatting
+         * 
+         * @param showVariables the value to set
+         * @return the dsl builder
+         */
+        default LogEndpointBuilder showVariables(String showVariables) {
+            doSetProperty("showVariables", showVariables);
+            return this;
+        }
         /**
          * Whether to skip line separators when logging the message body. This
          * allows to log the message body in one line, setting this option to