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 2018/02/06 09:14:18 UTC

[camel] 02/03: CAMEL-8958: Claim Check EIP with push/pop. Work in progress.

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 b9b52f74f2bbc48c38b93d8db0833e9a4cd79231
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Feb 6 09:40:13 2018 +0100

    CAMEL-8958: Claim Check EIP with push/pop. Work in progress.
---
 camel-core/src/main/docs/eips/claimCheck-eip.adoc  |  2 +-
 .../apache/camel/model/ClaimCheckDefinition.java   | 24 +++++++++++-----------
 .../apache/camel/model/ProcessorDefinition.java    |  7 +++----
 .../processor/ClaimCheckAggregationStrategy.java   | 21 ++++++++++++-------
 .../camel/processor/ClaimCheckProcessor.java       | 18 ++++++++--------
 .../processor/ClaimCheckEipPushPopBodyTest.xml     |  2 +-
 .../ClaimCheckEipPushPopHeadersPatternTest.xml     |  2 +-
 .../processor/ClaimCheckEipPushPopHeadersTest.xml  |  2 +-
 8 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/camel-core/src/main/docs/eips/claimCheck-eip.adoc b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
index a250cff..e4dc44a 100644
--- a/camel-core/src/main/docs/eips/claimCheck-eip.adoc
+++ b/camel-core/src/main/docs/eips/claimCheck-eip.adoc
@@ -20,7 +20,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
-| *data* | What data to merge when claiming from the 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 headers starting with foo bodyheader:foo. If [...]
+| *include* | What data to include when merging data back from 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 headers starting with  [...]
 | *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
 |===
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 d38460f..a78fe60 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
@@ -46,7 +46,7 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
     @XmlAttribute
     private String key;
     @XmlAttribute
-    private String data;
+    private String include;
     @XmlAttribute(name = "strategyRef") @Metadata(label = "advanced")
     private String aggregationStrategyRef;
     @XmlAttribute(name = "strategyMethodName") @Metadata(label = "advanced")
@@ -78,7 +78,7 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
         ClaimCheckProcessor claim = new ClaimCheckProcessor();
         claim.setOperation(operation.name());
         claim.setKey(getKey());
-        claim.setData(getData());
+        claim.setInclude(getInclude());
 
         AggregationStrategy strategy = createAggregationStrategy(routeContext);
         if (strategy != null) {
@@ -86,8 +86,8 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
         }
 
         // only data or aggregation strategy can be configured not both
-        if (getData() != null && strategy != null) {
-            throw new IllegalArgumentException("Cannot use both data and custom aggregation strategy on ClaimCheck EIP");
+        if (getInclude() != null && strategy != null) {
+            throw new IllegalArgumentException("Cannot use both include/exclude and custom aggregation strategy on ClaimCheck EIP");
         }
 
         return claim;
@@ -141,7 +141,7 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
     }
 
     /**
-     * What data to merge when claiming from the repository.
+     * What data to include when merging data back from claim check repository.
      *
      * The following syntax is supported:
      * <ul>
@@ -152,10 +152,10 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
      * </ul>
      * You can specify multiple rules separated by comma. For example to include the message body and all headers starting with foo
      * <tt>body,header:foo*</tt>.
-     * If the data rule is specified as empty or as wildcard then everything is merged.
+     * If the include rule is specified as empty or as wildcard then everything is included.
      */
-    public ClaimCheckDefinition data(String data) {
-        setData(data);
+    public ClaimCheckDefinition include(String include) {
+        setInclude(include);
         return this;
     }
 
@@ -204,12 +204,12 @@ public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinitio
         this.operation = operation;
     }
 
-    public String getData() {
-        return data;
+    public String getInclude() {
+        return include;
     }
 
-    public void setData(String data) {
-        this.data = data;
+    public void setInclude(String include) {
+        this.include = include;
     }
 
     public String getAggregationStrategyRef() {
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 19ac9c8..ac0e635 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -69,7 +69,6 @@ import org.apache.camel.processor.interceptor.StreamCaching;
 import org.apache.camel.processor.loadbalancer.LoadBalancer;
 import org.apache.camel.spi.AsEndpointUri;
 import org.apache.camel.spi.AsPredicate;
-import org.apache.camel.spi.ClaimCheckRepository;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.IdAware;
 import org.apache.camel.spi.IdempotentRepository;
@@ -3493,13 +3492,13 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
      *
      * @param operation the claim check operation to use.
      * @param key       the unique key to use for the get and set operations, can be <tt>null</tt> for push/pop operations
-     * @param data      describes what data to retrieve and merge back when using get or pop operations.
+     * @param include   describes what data to include and retrieve and merge back when using get or pop operations.
      */
-    public Type claimCheck(ClaimCheckOperation operation, String key, String data) {
+    public Type claimCheck(ClaimCheckOperation operation, String key, String include) {
         ClaimCheckDefinition answer = new ClaimCheckDefinition();
         answer.setOperation(operation);
         answer.setKey(key);
-        answer.setData(data);
+        answer.setInclude(include);
         addOutput(answer);
         return (Type) this;
     }
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 80b9bc0..02e0d7d 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
@@ -27,7 +27,7 @@ import org.apache.camel.util.StringHelper;
 /**
  * Default {@link AggregationStrategy} used by the {@link ClaimCheckProcessor} EIP.
  * <p/>
- * This strategy supports the following data rules syntax:
+ * This strategy supports the following include rules syntax:
  * <ul>
  *     <li>body</li> - to aggregate the message body
  *     <li>headers</li> - to aggregate all the message headers
@@ -36,14 +36,21 @@ import org.apache.camel.util.StringHelper;
  * </ul>
  * You can specify multiple rules separated by comma. For example to include the message body and all headers starting with foo
  * <tt>body,header:foo*</tt>.
- * If the data rule is specified as empty or as wildcard then everything is merged.
+ * If the include rule is specified as empty or as wildcard then everything is merged.
  */
 public class ClaimCheckAggregationStrategy implements AggregationStrategy {
 
-    private final String data; // describes what data to merge
+    private String include;
 
-    public ClaimCheckAggregationStrategy(String data) {
-        this.data = data;
+    public ClaimCheckAggregationStrategy() {
+    }
+
+    public String getInclude() {
+        return include;
+    }
+
+    public void setInclude(String include) {
+        this.include = include;
     }
 
     @Override
@@ -52,12 +59,12 @@ public class ClaimCheckAggregationStrategy implements AggregationStrategy {
             return oldExchange;
         }
 
-        if (ObjectHelper.isEmpty(data) || "*".equals(data)) {
+        if (ObjectHelper.isEmpty(include) || "*".equals(include)) {
             // grab everything if data is empty or wildcard
             return newExchange;
         }
 
-        Iterable it = ObjectHelper.createIterable(data, ",");
+        Iterable it = ObjectHelper.createIterable(include, ",");
         for (Object k : it) {
             String part = k.toString();
             if ("body".equals(part)) {
diff --git a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
index 9a904e9..137ecbf 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/ClaimCheckProcessor.java
@@ -49,7 +49,7 @@ public class ClaimCheckProcessor extends ServiceSupport implements AsyncProcesso
     private String operation;
     private AggregationStrategy aggregationStrategy;
     private String key;
-    private String data;
+    private String include;
 
     @Override
     public CamelContext getCamelContext() {
@@ -95,12 +95,12 @@ public class ClaimCheckProcessor extends ServiceSupport implements AsyncProcesso
         this.key = key;
     }
 
-    public String getData() {
-        return data;
+    public String getInclude() {
+        return include;
     }
 
-    public void setData(String data) {
-        this.data = data;
+    public void setInclude(String include) {
+        this.include = include;
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -176,7 +176,7 @@ public class ClaimCheckProcessor extends ServiceSupport implements AsyncProcesso
         ObjectHelper.notNull(operation, "operation", this);
 
         if (aggregationStrategy == null) {
-            aggregationStrategy = createAggregationStrategy(data);
+            aggregationStrategy = createAggregationStrategy();
         }
         if (aggregationStrategy instanceof CamelContextAware) {
             ((CamelContextAware) aggregationStrategy).setCamelContext(camelContext);
@@ -195,7 +195,9 @@ public class ClaimCheckProcessor extends ServiceSupport implements AsyncProcesso
         return "ClaimCheck[" + operation + "]";
     }
 
-    protected AggregationStrategy createAggregationStrategy(String data) {
-        return new ClaimCheckAggregationStrategy(data);
+    protected AggregationStrategy createAggregationStrategy() {
+        ClaimCheckAggregationStrategy answer = new ClaimCheckAggregationStrategy();
+        answer.setInclude(include);
+        return answer;
     }
 }
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopBodyTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopBodyTest.xml
index 7abb4f8..e4e2661 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopBodyTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopBodyTest.xml
@@ -36,7 +36,7 @@
         <constant>456</constant>
       </setHeader>
       <to uri="mock:b"/>
-      <claimCheck operation="Pop" data="body"/>
+      <claimCheck operation="Pop" include="body"/>
       <to uri="mock:c"/>
     </route>
   </camelContext>
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersPatternTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersPatternTest.xml
index e79fdfb..13eb12e 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersPatternTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersPatternTest.xml
@@ -37,7 +37,7 @@
       </setHeader>
       <removeHeader headerName="bar"/>
       <to uri="mock:b"/>
-      <claimCheck operation="Pop" data="header:(foo|bar)"/>
+      <claimCheck operation="Pop" include="header:(foo|bar)"/>
       <to uri="mock:c"/>
     </route>
   </camelContext>
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersTest.xml
index 1210b5e..e56be5e 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ClaimCheckEipPushPopHeadersTest.xml
@@ -36,7 +36,7 @@
         <constant>456</constant>
       </setHeader>
       <to uri="mock:b"/>
-      <claimCheck operation="Pop" data="headers"/>
+      <claimCheck operation="Pop" include="headers"/>
       <to uri="mock:c"/>
     </route>
   </camelContext>

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