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

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


The following commit(s) were added to refs/heads/CAMEL-13870 by this push:
     new abc454c  CAMEL-13870: Fast property configuration of Camel endpoints. 
Work in progress.
abc454c is described below

commit abc454cf1c02e3b238db928013675b20313ba1d3
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Aug 22 09:07:54 2019 +0200

    CAMEL-13870: Fast property configuration of Camel endpoints. Work in 
progress.
---
 .../camel-log/src/main/docs/log-component.adoc     |   3 +-
 .../apache/camel/component/log/LogComponent.java   |   4 -
 .../apache/camel/component/log/LogEndpoint.java    | 213 ++++++++++++++++++++-
 .../camel/processor/SimpleMockPlaceholderTest.java |   2 +-
 .../endpoint/dsl/LogEndpointBuilderFactory.java    |  27 +++
 5 files changed, 239 insertions(+), 10 deletions(-)

diff --git a/components/camel-log/src/main/docs/log-component.adoc 
b/components/camel-log/src/main/docs/log-component.adoc
index 23a7668..3682f2f 100644
--- a/components/camel-log/src/main/docs/log-component.adoc
+++ b/components/camel-log/src/main/docs/log-component.adoc
@@ -93,7 +93,7 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (27 parameters):
+=== Query Parameters (28 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -108,6 +108,7 @@ with the following path and query parameters:
 | *logMask* (producer) | If true, mask sensitive information like password or 
passphrase in the log. |  | Boolean
 | *marker* (producer) | An optional Marker name to use. |  | String
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic 
property binding (Camel 2.x) or the newer property binding with additional 
capabilities | false | boolean
+| *exchangeFormatter* (advanced) | To use a custom exchange formatter |  | 
ExchangeFormatter
 | *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used, or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
 | *maxChars* (formatting) | Limits the number of characters logged per line. | 
10000 | int
 | *multiline* (formatting) | If enabled then each information is outputted on 
a newline. | false | boolean
diff --git 
a/components/camel-log/src/main/java/org/apache/camel/component/log/LogComponent.java
 
b/components/camel-log/src/main/java/org/apache/camel/component/log/LogComponent.java
index 7176455..1164041 100644
--- 
a/components/camel-log/src/main/java/org/apache/camel/component/log/LogComponent.java
+++ 
b/components/camel-log/src/main/java/org/apache/camel/component/log/LogComponent.java
@@ -65,10 +65,6 @@ public class LogComponent extends DefaultComponent {
             // do not set properties, the exchangeFormatter is explicitly set, 
therefore the
             // user would have set its properties explicitly too
             localFormatter = exchangeFormatter;
-        } else {
-            // if no formatter is available in the Registry, create a local 
one of the default type, for a single use
-            localFormatter = new DefaultExchangeFormatter();
-            setProperties(localFormatter, parameters);
         }
 
         LogEndpoint endpoint = new LogEndpoint(uri, this);
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 3da4aca..0f5234f 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
@@ -64,9 +64,45 @@ public class LogEndpoint extends ProcessorEndpoint {
     private Long groupDelay;
     @UriParam
     private Boolean logMask;
-    // we want to include the uri options of the DefaultExchangeFormatter as 
additional configurations in the docs
     @UriParam(label = "advanced")
-    private final DefaultExchangeFormatter formatter = new 
DefaultExchangeFormatter();
+    private ExchangeFormatter exchangeFormatter;
+    @UriParam(label = "formatting", description = "Show the unique exchange 
ID.")
+    private boolean showExchangeId;
+    @UriParam(label = "formatting", defaultValue = "true", description = 
"Shows the Message Exchange Pattern (or MEP for short).")
+    private boolean showExchangePattern = true;
+    @UriParam(label = "formatting", description = "Show the exchange 
properties.")
+    private boolean showProperties;
+    @UriParam(label = "formatting", description = "Show the message headers.")
+    private boolean showHeaders;
+    @UriParam(label = "formatting", 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 the body, which then 
will log the body as is.")
+    private boolean skipBodyLineSeparator = true;
+    @UriParam(label = "formatting", defaultValue = "true", description = "Show 
the message body.")
+    private boolean showBody = true;
+    @UriParam(label = "formatting", defaultValue = "true", description = "Show 
the body Java type.")
+    private boolean showBodyType = true;
+    @UriParam(label = "formatting", description = "If the exchange has an 
exception, show the exception message (no stacktrace)")
+    private boolean showException;
+    @UriParam(label = "formatting", description = "f the exchange has a caught 
exception, show the exception message (no stack trace)."
+            + "A caught exception is stored as a property on the exchange 
(using the key org.apache.camel.Exchange#EXCEPTION_CAUGHT and for instance a 
doCatch can catch exceptions.")
+    private boolean showCaughtException;
+    @UriParam(label = "formatting", description = "Show the stack trace, if an 
exchange has an exception. Only effective if one of showAll, showException or 
showCaughtException are enabled.")
+    private boolean showStackTrace;
+    @UriParam(label = "formatting", description = "Quick option for turning 
all options on. (multiline, maxChars has to be manually set if to be used)")
+    private boolean showAll;
+    @UriParam(label = "formatting", description = "If enabled then each 
information is outputted on a newline.")
+    private boolean multiline;
+    @UriParam(label = "formatting", description = "If enabled Camel will on 
Future objects wait for it to complete to obtain the payload to be logged.")
+    private boolean showFuture;
+    @UriParam(label = "formatting", 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 been read by this logger. To remedy this you will have to 
use Stream Caching.")
+    private boolean showStreams;
+    @UriParam(label = "formatting", description = "If enabled Camel will 
output files")
+    private boolean showFiles;
+    @UriParam(label = "formatting", defaultValue = "10000", description = 
"Limits the number of characters logged per line.")
+    private int maxChars = 10000;
+    @UriParam(label = "formatting", enums = "Default,Tab,Fixed", defaultValue 
= "Default", description = "Sets the outputs style to use.")
+    private DefaultExchangeFormatter.OutputStyle style = 
DefaultExchangeFormatter.OutputStyle.Default;
 
     public LogEndpoint() {
     }
@@ -80,8 +116,31 @@ public class LogEndpoint extends ProcessorEndpoint {
         setLogger(logger);
     }
 
-    public DefaultExchangeFormatter getFormatter() {
-        return formatter;
+    @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+
+        this.localFormatter = exchangeFormatter;
+        if (this.localFormatter == null) {
+            DefaultExchangeFormatter def = new DefaultExchangeFormatter();
+            def.setShowExchangeId(showExchangeId);
+            def.setShowExchangePattern(showExchangePattern);
+            def.setShowProperties(showProperties);
+            def.setShowHeaders(showHeaders);
+            def.setSkipBodyLineSeparator(skipBodyLineSeparator);
+            def.setShowBody(showBody);
+            def.setShowBodyType(showBodyType);
+            def.setShowException(showException);
+            def.setShowStackTrace(showStackTrace);
+            def.setShowAll(showAll);
+            def.setMultiline(multiline);
+            def.setShowFuture(showFuture);
+            def.setShowStreams(showStreams);
+            def.setShowFiles(showFiles);
+            def.setMaxChars(maxChars);
+            def.setStyle(style);
+            this.localFormatter = def;
+        }
     }
 
     @Override
@@ -292,4 +351,150 @@ public class LogEndpoint extends ProcessorEndpoint {
         this.logMask = logMask;
     }
 
+    public ExchangeFormatter getExchangeFormatter() {
+        return exchangeFormatter;
+    }
+
+    /**
+     * To use a custom exchange formatter
+     */
+    public void setExchangeFormatter(ExchangeFormatter exchangeFormatter) {
+        this.exchangeFormatter = exchangeFormatter;
+    }
+
+    public boolean isShowExchangeId() {
+        return showExchangeId;
+    }
+
+    public void setShowExchangeId(boolean showExchangeId) {
+        this.showExchangeId = showExchangeId;
+    }
+
+    public boolean isShowExchangePattern() {
+        return showExchangePattern;
+    }
+
+    public void setShowExchangePattern(boolean showExchangePattern) {
+        this.showExchangePattern = showExchangePattern;
+    }
+
+    public boolean isShowProperties() {
+        return showProperties;
+    }
+
+    public void setShowProperties(boolean showProperties) {
+        this.showProperties = showProperties;
+    }
+
+    public boolean isShowHeaders() {
+        return showHeaders;
+    }
+
+    public void setShowHeaders(boolean showHeaders) {
+        this.showHeaders = showHeaders;
+    }
+
+    public boolean isSkipBodyLineSeparator() {
+        return skipBodyLineSeparator;
+    }
+
+    public void setSkipBodyLineSeparator(boolean skipBodyLineSeparator) {
+        this.skipBodyLineSeparator = skipBodyLineSeparator;
+    }
+
+    public boolean isShowBody() {
+        return showBody;
+    }
+
+    public void setShowBody(boolean showBody) {
+        this.showBody = showBody;
+    }
+
+    public boolean isShowBodyType() {
+        return showBodyType;
+    }
+
+    public void setShowBodyType(boolean showBodyType) {
+        this.showBodyType = showBodyType;
+    }
+
+    public boolean isShowException() {
+        return showException;
+    }
+
+    public void setShowException(boolean showException) {
+        this.showException = showException;
+    }
+
+    public boolean isShowCaughtException() {
+        return showCaughtException;
+    }
+
+    public void setShowCaughtException(boolean showCaughtException) {
+        this.showCaughtException = showCaughtException;
+    }
+
+    public boolean isShowStackTrace() {
+        return showStackTrace;
+    }
+
+    public void setShowStackTrace(boolean showStackTrace) {
+        this.showStackTrace = showStackTrace;
+    }
+
+    public boolean isShowAll() {
+        return showAll;
+    }
+
+    public void setShowAll(boolean showAll) {
+        this.showAll = showAll;
+    }
+
+    public boolean isMultiline() {
+        return multiline;
+    }
+
+    public void setMultiline(boolean multiline) {
+        this.multiline = multiline;
+    }
+
+    public boolean isShowFuture() {
+        return showFuture;
+    }
+
+    public void setShowFuture(boolean showFuture) {
+        this.showFuture = showFuture;
+    }
+
+    public boolean isShowStreams() {
+        return showStreams;
+    }
+
+    public void setShowStreams(boolean showStreams) {
+        this.showStreams = showStreams;
+    }
+
+    public boolean isShowFiles() {
+        return showFiles;
+    }
+
+    public void setShowFiles(boolean showFiles) {
+        this.showFiles = showFiles;
+    }
+
+    public int getMaxChars() {
+        return maxChars;
+    }
+
+    public void setMaxChars(int maxChars) {
+        this.maxChars = maxChars;
+    }
+
+    public DefaultExchangeFormatter.OutputStyle getStyle() {
+        return style;
+    }
+
+    public void setStyle(DefaultExchangeFormatter.OutputStyle style) {
+        this.style = style;
+    }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java
index be92152..80c992b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleMockPlaceholderTest.java
@@ -68,7 +68,7 @@ public class SimpleMockPlaceholderTest extends 
ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("direct:start?block=true").to("{{foo}}").to("log:bar?groupSize=3").to("mock:{{end}}");
+                
from("direct:start?block=true").to("{{foo}}?showAll=true").to("log:bar?groupSize=3").to("mock:{{end}}");
             }
         };
     }
diff --git 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
index 9d85afa..134bc75 100644
--- 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
+++ 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/LogEndpointBuilderFactory.java
@@ -20,6 +20,7 @@ import javax.annotation.Generated;
 import org.apache.camel.builder.EndpointConsumerBuilder;
 import org.apache.camel.builder.EndpointProducerBuilder;
 import org.apache.camel.builder.endpoint.AbstractEndpointBuilder;
+import org.apache.camel.spi.ExchangeFormatter;
 
 /**
  * The log component logs message exchanges to the underlying logging 
mechanism.
@@ -626,6 +627,32 @@ public interface LogEndpointBuilderFactory {
             return this;
         }
         /**
+         * To use a custom exchange formatter.
+         * 
+         * The option is a: <code>org.apache.camel.spi.ExchangeFormatter</code>
+         * type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedLogEndpointBuilder exchangeFormatter(
+                ExchangeFormatter exchangeFormatter) {
+            setProperty("exchangeFormatter", exchangeFormatter);
+            return this;
+        }
+        /**
+         * To use a custom exchange formatter.
+         * 
+         * The option will be converted to a
+         * <code>org.apache.camel.spi.ExchangeFormatter</code> type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedLogEndpointBuilder exchangeFormatter(
+                String exchangeFormatter) {
+            setProperty("exchangeFormatter", exchangeFormatter);
+            return this;
+        }
+        /**
          * Sets whether synchronous processing should be strictly used, or 
Camel
          * is allowed to use asynchronous processing (if supported).
          * 

Reply via email to