camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [7/8] camel git commit: CAMEL-9551: ErrorHandler - Should not log message body by default.
Date Sat, 30 Jan 2016 16:06:31 GMT
CAMEL-9551: ErrorHandler - Should not log message body by default.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1ac13365
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1ac13365
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1ac13365

Branch: refs/heads/master
Commit: 1ac133653adee33d68de3288ec29f01edd566c83
Parents: f2e9801
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jan 30 15:55:37 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jan 30 17:06:16 2016 +0100

----------------------------------------------------------------------
 .../mbean/ManagedErrorHandlerMBean.java         |  6 +++
 .../builder/DefaultErrorHandlerBuilder.java     |  5 +++
 .../management/mbean/ManagedErrorHandler.java   | 18 ++++++++
 .../camel/model/OnExceptionDefinition.java      | 18 ++++++++
 .../camel/model/RedeliveryPolicyDefinition.java | 37 +++++++++++++++
 .../camel/processor/RedeliveryErrorHandler.java |  4 +-
 .../camel/processor/RedeliveryPolicy.java       | 33 ++++++++++++++
 ...lLogExhaustedMessageHistoryWithBodyTest.java | 47 ++++++++++++++++++++
 8 files changed, 167 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
index d1a276c..45aa08f 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
@@ -131,6 +131,12 @@ public interface ManagedErrorHandlerMBean {
     @ManagedAttribute(description = "RedeliveryPolicy for logging exhausted with message
history")
     void setLogExhaustedMessageHistory(Boolean log);
 
+    @ManagedAttribute(description = "RedeliveryPolicy for logging exhausted with message
history")
+    Boolean getLogExhaustedMessageBody();
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging exhausted with message
body")
+    void setLogExhaustedMessageBody(Boolean log);
+
     @ManagedAttribute(description = "RedeliveryPolicy for logging handled and continued exceptions")
     Boolean getLogContinued();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
b/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
index 96a408e..b565bfe 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
@@ -208,6 +208,11 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport
{
         return this;
     }
     
+    public DefaultErrorHandlerBuilder logExhaustedMessageBody(boolean logExhaustedMessageBody)
{
+        getRedeliveryPolicy().setLogExhaustedMessageBody(logExhaustedMessageBody);
+        return this;
+    }
+
     public DefaultErrorHandlerBuilder exchangeFormatterRef(String exchangeFormatterRef) {
         getRedeliveryPolicy().setExchangeFormatterRef(exchangeFormatterRef);
         return this;

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
index e7e0aea..314891f 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
@@ -367,6 +367,24 @@ public class ManagedErrorHandler implements ManagedErrorHandlerMBean
{
         redelivery.getRedeliveryPolicy().setLogExhaustedMessageHistory(log);
     }
 
+    public Boolean getLogExhaustedMessageBody() {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().isLogExhaustedMessageBody();
+    }
+
+    public void setLogExhaustedMessageBody(Boolean log) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setLogExhaustedMessageBody(log);
+    }
+
     public Boolean getLogContinued() {
         if (!isSupportRedelivery()) {
             return null;

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java b/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
index 433601b..9070ae0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
@@ -624,6 +624,24 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
     }
 
     /**
+     * Sets whether to log exhausted message body with message history.
+     * Requires <tt>logExhaustedMessageHistory</tt> to be enabled.
+     */
+    public OnExceptionDefinition logExhaustedMessageBody(boolean logExhaustedMessageBody)
{
+        getOrCreateRedeliveryPolicy().logExhaustedMessageBody(logExhaustedMessageBody);
+        return this;
+    }
+
+    /**
+     * Sets whether to log exhausted message body with message history.
+     * Requires <tt>logExhaustedMessageHistory</tt> to be enabled.
+     */
+    public OnExceptionDefinition logExhaustedMessageBody(String logExhaustedMessageBody)
{
+        getOrCreateRedeliveryPolicy().logExhaustedMessageBody(logExhaustedMessageBody);
+        return this;
+    }
+
+    /**
      * Sets the maximum redeliveries
      * <ul>
      * <li>5 = default value</li>

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
index f695d26..e5975d5 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
@@ -74,6 +74,8 @@ public class RedeliveryPolicyDefinition {
     @XmlAttribute
     private String logExhaustedMessageHistory;
     @XmlAttribute
+    private String logExhaustedMessageBody;
+    @XmlAttribute
     private String disableRedelivery;
     @XmlAttribute
     private String delayPattern;
@@ -150,6 +152,9 @@ public class RedeliveryPolicyDefinition {
             if (logExhaustedMessageHistory != null) {
                 answer.setLogExhaustedMessageHistory(CamelContextHelper.parseBoolean(context,
logExhaustedMessageHistory));
             }
+            if (logExhaustedMessageBody != null) {
+                answer.setLogExhaustedMessageBody(CamelContextHelper.parseBoolean(context,
logExhaustedMessageBody));
+            }
             if (disableRedelivery != null) {
                 if (CamelContextHelper.parseBoolean(context, disableRedelivery)) {
                     answer.setMaximumRedeliveries(0);
@@ -496,6 +501,30 @@ public class RedeliveryPolicyDefinition {
     }
 
     /**
+     * Sets whether exhausted message body should be logged including message history or
not (supports property placeholders).
+     * Can be used to include or reduce verbose. Requires <tt>logExhaustedMessageHistory</tt>
to be enabled.
+     *
+     * @param logExhaustedMessageBody  whether exhausted message body should be logged with
message history
+     * @return the builder
+     */
+    public RedeliveryPolicyDefinition logExhaustedMessageBody(boolean logExhaustedMessageBody)
{
+        setLogExhaustedMessageBody(Boolean.toString(logExhaustedMessageBody));
+        return this;
+    }
+
+    /**
+     * Sets whether exhausted message body should be logged including message history or
not (supports property placeholders).
+     * Can be used to include or reduce verbose. Requires <tt>logExhaustedMessageHistory</tt>
to be enabled.
+     *
+     * @param logExhaustedMessageBody  whether exhausted message body should be logged with
message history
+     * @return the builder
+     */
+    public RedeliveryPolicyDefinition logExhaustedMessageBody(String logExhaustedMessageBody)
{
+        setLogExhaustedMessageBody(logExhaustedMessageBody);
+        return this;
+    }
+
+    /**
      * Sets the maximum redeliveries
      * <ul>
      *   <li>x = redeliver at most x times</li>
@@ -748,6 +777,14 @@ public class RedeliveryPolicyDefinition {
         this.logExhaustedMessageHistory = logExhaustedMessageHistory;
     }
 
+    public String getLogExhaustedMessageBody() {
+        return logExhaustedMessageBody;
+    }
+
+    public void setLogExhaustedMessageBody(String logExhaustedMessageBody) {
+        this.logExhaustedMessageBody = logExhaustedMessageBody;
+    }
+
     public String getDisableRedelivery() {
         return disableRedelivery;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 04784eb..20026f6 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -1157,7 +1157,9 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
impleme
             String msg = message;
             // should we include message history
             if (!shouldRedeliver && data.currentRedeliveryPolicy.isLogExhaustedMessageHistory())
{
-                String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange,
exchangeFormatter, e != null && logStackTrace);
+                // only use the exchange formatter if we should log exhausted message body
+                ExchangeFormatter formatter = data.currentRedeliveryPolicy.isLogExhaustedMessageBody()
? exchangeFormatter : null;
+                String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange,
formatter, e != null && logStackTrace);
                 if (routeStackTrace != null) {
                     msg = msg + "\n" + routeStackTrace;
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
index 4b33a4b..8b835f2 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
@@ -98,6 +98,7 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
     protected boolean logExhausted = true;
     protected boolean logNewException = true;
     protected Boolean logExhaustedMessageHistory;
+    protected Boolean logExhaustedMessageBody;
     protected boolean logRetryAttempted = true;
     protected String delayPattern;
     protected boolean asyncDelayedRedelivery;
@@ -124,6 +125,7 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
             + ", logExhausted=" + logExhausted
             + ", logNewException=" + logNewException
             + ", logExhaustedMessageHistory=" + logExhaustedMessageHistory
+            + ", logExhaustedMessageBody=" + logExhaustedMessageBody
             + ", useExponentialBackOff="  + useExponentialBackOff
             + ", backOffMultiplier=" + backOffMultiplier
             + ", useCollisionAvoidance=" + useCollisionAvoidance
@@ -405,6 +407,14 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
     }
 
     /**
+     * Sets whether to log exhausted errors including message body (requires message history
to be enabled)
+     */
+    public RedeliveryPolicy logExhaustedMessageBody(boolean logExhaustedMessageBody) {
+        setLogExhaustedMessageBody(logExhaustedMessageBody);
+        return this;
+    }
+
+    /**
      * Sets the delay pattern with delay intervals.
      */
     public RedeliveryPolicy delayPattern(String delayPattern) {
@@ -708,6 +718,29 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
         this.logExhaustedMessageHistory = logExhaustedMessageHistory;
     }
 
+    public boolean isLogExhaustedMessageBody() {
+        // should default be disabled
+        return logExhaustedMessageBody != null && logExhaustedMessageBody;
+    }
+
+    /**
+     * Whether the option logExhaustedMessageBody has been configured or not
+     *
+     * @return <tt>null</tt> if not configured, or the configured value as true
or false
+     * @see #isLogExhaustedMessageBody()
+     */
+    public Boolean getLogExhaustedMessageBody() {
+        return logExhaustedMessageBody;
+    }
+
+    /**
+     * Sets whether exhausted message body/headers should be logged with message history
included
+     * (requires logExhaustedMessageHistory to be enabled).
+     */
+    public void setLogExhaustedMessageBody(Boolean logExhaustedMessageBody) {
+        this.logExhaustedMessageBody = logExhaustedMessageBody;
+    }
+
     public boolean isAsyncDelayedRedelivery() {
         return asyncDelayedRedelivery;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1ac13365/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryWithBodyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryWithBodyTest.java
b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryWithBodyTest.java
new file mode 100644
index 0000000..13403ec
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryWithBodyTest.java
@@ -0,0 +1,47 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class DeadLetterChannelLogExhaustedMessageHistoryWithBodyTest extends ContextTestSupport
{
+
+    public void testLogExhaustedMessageHistory() throws Exception {
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // no delay to speedup test
+                errorHandler(deadLetterChannel("mock:dead").redeliveryDelay(0).maximumRedeliveries(3)
+                        .logExhaustedMessageHistory(true).logExhaustedMessageBody(true));
+
+                from("direct:start")
+                    .log("Incoming ${body}")
+                    .throwException(new IllegalArgumentException("Forced"));
+            }
+        };
+    }
+}


Mime
View raw message