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

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

commit 1b4cafeb5d8fdf6b236763b0826d28ec4ef9ddbb
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Feb 6 16:37:07 2018 +0100

    CAMEL-8958: Claim Check EIP with push/pop. Work in progress.
---
 camel-core/src/main/docs/eips/claimCheck-eip.adoc  | 10 ++++-
 .../apache/camel/model/ClaimCheckDefinition.java   |  1 +
 .../processor/ClaimCheckAggregationStrategy.java   | 45 ++++++++++++++++++++--
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/camel-core/src/main/docs/eips/claimCheck-eip.adoc 
b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
index b2f4593..8e8af58 100644
--- a/camel-core/src/main/docs/eips/claimCheck-eip.adoc
+++ b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
@@ -22,7 +22,7 @@ The Claim Check EIP supports 5 options which are listed below:
 | Name | Description | Default | Type
 | *operation* | *Required* The claim check operation to use. The following 
operations is supported: Get - Gets (does not remove) the claim check by the 
given key. GetAndRemove - Gets and remove the claim check by the given key. Set 
- Sets a new (will override if key already exists) claim check with the given 
key. Push - Sets a new claim check on the stack (does not use key). Pop - Gets 
the latest claim check from the stack (does not use key). |  | 
ClaimCheckOperation
 | *key* | To use a specific key for claim check id. |  | String
-| *filter* | Specified a filter to control what data gets merging data back 
from the claim check repository. The following syntax is supported: body - to 
aggregate the message body headers - to aggregate all the message headers 
header:pattern - to aggregate all the message headers that matches the pattern. 
The pattern syntax is documented by: link EndpointHelpermatchPattern(String 
String). You can specify multiple rules separated by comma. For example to 
include the message body and all  [...]
+| *filter* | Specified a filter to control what data gets merging data back 
from the claim check repository. The following syntax is supported: body - to 
aggregate the message body attachments - to aggregate all the message 
attachments headers - to aggregate all the message headers header:pattern - to 
aggregate all the message headers that matches the pattern. The pattern syntax 
is documented by: link EndpointHelpermatchPattern(String String). You can 
specify multiple rules separated by  [...]
 | *strategyRef* | To use a custom AggregationStrategy instead of the default 
implementation. Notice you cannot use both custom aggregation strategy and 
configure data at the same time. |  | String
 | *strategyMethodName* | This option can be used to explicit declare the 
method name to use when using POJOs as the AggregationStrategy. |  | String
 |===
@@ -53,6 +53,7 @@ then its merged using a `AggregationStrategy`. The default 
strategy uses the `fi
 The `filter` option takes a `String` value with the following syntax:
 
 * `body` = to aggregate the message body
+* `attachments` = to aggregate all the message attachments
 * `headers` = to aggregate all the message headers
 * `header:pattern` = to aggregate all the message headers that matches the 
pattern.
 
@@ -79,6 +80,13 @@ To only merge back the message body:
 body
 ----
 
+To only merge back the message attachments:
+
+[text]
+----
+attachments
+----
+
 To only merge back headers:
 
 [text]
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ClaimCheckDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/ClaimCheckDefinition.java
index 2b5dbce..760c7c0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ClaimCheckDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ClaimCheckDefinition.java
@@ -190,6 +190,7 @@ public class ClaimCheckDefinition extends 
NoOutputDefinition<ClaimCheckDefinitio
      * The following syntax is supported:
      * <ul>
      *     <li>body</li> - to aggregate the message body
+     *     <li>attachments</li> - to aggregate all the message attachments
      *     <li>headers</li> - to aggregate all the message headers
      *     <li>header:pattern</li> - to aggregate all the message headers that 
matches the pattern.
      *     The pattern syntax is documented by: {@link 
EndpointHelper#matchPattern(String, String)}.
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckAggregationStrategy.java
 
b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckAggregationStrategy.java
index b608ad2..6416533 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckAggregationStrategy.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckAggregationStrategy.java
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
  * This strategy supports the following include rules syntax:
  * <ul>
  *     <li>body</li> - to aggregate the message body
+ *     <li>attachments</li> - to aggregate all the message attachments
  *     <li>headers</li> - to aggregate all the message headers
  *     <li>header:pattern</li> - to aggregate all the message headers that 
matches the pattern.
  *     The pattern syntax is documented by: {@link 
EndpointHelper#matchPattern(String, String)}.
@@ -69,8 +70,14 @@ public class ClaimCheckAggregationStrategy implements 
AggregationStrategy {
             // grab everything
             
oldExchange.getMessage().setBody(newExchange.getMessage().getBody());
             LOG.trace("Including: body");
-            
oldExchange.getMessage().getHeaders().putAll(newExchange.getMessage().getHeaders());
-            LOG.trace("Including: headers");
+            if (newExchange.getMessage().hasHeaders()) {
+                
oldExchange.getMessage().getHeaders().putAll(newExchange.getMessage().getHeaders());
+                LOG.trace("Including: headers");
+            }
+            if (newExchange.getMessage().hasAttachments()) {
+                
oldExchange.getMessage().getAttachments().putAll(newExchange.getMessage().getAttachments());
+                LOG.trace("Including: attachments");
+            }
             return oldExchange;
         }
 
@@ -80,10 +87,20 @@ public class ClaimCheckAggregationStrategy implements 
AggregationStrategy {
             LOG.trace("Including: body");
         }
 
+        // attachments is by default often included
+        if (isAttachmentsEnabled()) {
+            if (newExchange.getMessage().hasAttachments()) {
+                
oldExchange.getMessage().getAttachments().putAll(newExchange.getMessage().getAttachments());
+                LOG.trace("Including: attachments");
+            }
+        }
+
         // headers is by default often included
         if (isHeadersEnabled()) {
-            
oldExchange.getMessage().getHeaders().putAll(newExchange.getMessage().getHeaders());
-            LOG.trace("Including: headers");
+            if (newExchange.getMessage().hasHeaders()) {
+                
oldExchange.getMessage().getHeaders().putAll(newExchange.getMessage().getHeaders());
+                LOG.trace("Including: headers");
+            }
         }
 
         // filter specific header if they are somehow enabled by the filter
@@ -254,6 +271,26 @@ public class ClaimCheckAggregationStrategy implements 
AggregationStrategy {
         return onlyExclude;
     }
 
+    private boolean isAttachmentsEnabled() {
+        // attachments is always enabled unless excluded
+        String[] parts = filter.split(",");
+
+        boolean onlyExclude = true;
+        for (String pattern : parts) {
+            if (pattern.startsWith("--")) {
+                continue;
+            }
+            if ("attachments".equals(pattern) || 
"+attachments".equals(pattern)) {
+                return true;
+            } else if ("-attachments".equals(pattern)) {
+                return false;
+            }
+            onlyExclude &= pattern.startsWith("-");
+        }
+        // attachments is enabled if we only have exclude patterns
+        return onlyExclude;
+    }
+
     private boolean isHeadersEnabled() {
         // headers may be enabled unless excluded
         String[] parts = filter.split(",");

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to