001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model; 018 019import java.util.function.Supplier; 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlAttribute; 023import javax.xml.bind.annotation.XmlRootElement; 024import javax.xml.bind.annotation.XmlTransient; 025 026import org.apache.camel.AggregationStrategy; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * The Claim Check EIP allows you to replace message content with a claim check 031 * (a unique key), which can be used to retrieve the message content at a later 032 * time. 033 */ 034@Metadata(label = "eip,routing") 035@XmlRootElement(name = "claimCheck") 036@XmlAccessorType(XmlAccessType.FIELD) 037public class ClaimCheckDefinition extends NoOutputDefinition<ClaimCheckDefinition> { 038 039 @XmlAttribute(required = true) 040 private ClaimCheckOperation operation; 041 @XmlAttribute 042 private String key; 043 @XmlAttribute 044 private String filter; 045 @XmlAttribute(name = "strategyRef") 046 @Metadata(label = "advanced") 047 private String aggregationStrategyRef; 048 @XmlAttribute(name = "strategyMethodName") 049 @Metadata(label = "advanced") 050 private String aggregationStrategyMethodName; 051 @XmlTransient 052 private AggregationStrategy aggregationStrategy; 053 054 public ClaimCheckDefinition() { 055 } 056 057 @Override 058 public String toString() { 059 if (operation != null) { 060 return "ClaimCheck[" + operation + "]"; 061 } else { 062 return "ClaimCheck"; 063 } 064 } 065 066 @Override 067 public String getShortName() { 068 return "claimCheck"; 069 } 070 071 @Override 072 public String getLabel() { 073 return "claimCheck"; 074 } 075 076 // Fluent API 077 // ------------------------------------------------------------------------- 078 079 /** 080 * The claim check operation to use. The following operations is supported: 081 * <ul> 082 * <li>Get</li> - Gets (does not remove) the claim check by the given key. 083 * <li>GetAndRemove</li> - Gets and remove the claim check by the given key. 084 * <li>Set</li> - Sets a new (will override if key already exists) claim 085 * check with the given key. 086 * <li>Push</li> - Sets a new claim check on the stack (does not use key). 087 * <li>Pop</li> - Gets the latest claim check from the stack (does not use 088 * key). 089 * </ul> 090 */ 091 public ClaimCheckDefinition operation(ClaimCheckOperation operation) { 092 setOperation(operation); 093 return this; 094 } 095 096 /** 097 * To use a specific key for claim check id (for dynamic keys use simple 098 * language syntax as the key). 099 */ 100 public ClaimCheckDefinition key(String key) { 101 setKey(key); 102 return this; 103 } 104 105 /** 106 * Specified a filter to control what data gets merging data back from the 107 * claim check repository. The following syntax is supported: 108 * <ul> 109 * <li>body</li> - to aggregate the message body 110 * <li>attachments</li> - to aggregate all the message attachments 111 * <li>headers</li> - to aggregate all the message headers 112 * <li>header:pattern</li> - to aggregate all the message headers that 113 * matches the pattern. 114 * </ul> 115 * The pattern uses the following rules are applied in this order: 116 * <ul> 117 * <li>exact match, returns true</li> 118 * <li>wildcard match (pattern ends with a * and the name starts with the 119 * pattern), returns true</li> 120 * <li>regular expression match, returns true</li> 121 * <li>otherwise returns false</li> 122 * </ul> 123 * <p> 124 * You can specify multiple rules separated by comma. For example to include 125 * the message body and all headers starting with foo 126 * <tt>body,header:foo*</tt>. The syntax supports the following prefixes 127 * which can be used to specify include,exclude, or remove 128 * <ul> 129 * <li>+</li> - to include (which is the default mode) 130 * <li>-</li> - to exclude (exclude takes precedence over include) 131 * <li>--</li> - to remove (remove takes precedence) 132 * </ul> 133 * For example to exclude a header name foo, and remove all headers starting 134 * with bar <tt>-header:foo,--headers:bar*</tt> Note you cannot have both 135 * include and exclude <tt>header:pattern</tt> at the same time. 136 */ 137 public ClaimCheckDefinition filter(String filter) { 138 setFilter(filter); 139 return this; 140 } 141 142 /** 143 * To use a custom {@link AggregationStrategy} instead of the default 144 * implementation. Notice you cannot use both custom aggregation strategy 145 * and configure data at the same time. 146 */ 147 public ClaimCheckDefinition aggregationStrategy(AggregationStrategy aggregationStrategy) { 148 setAggregationStrategy(aggregationStrategy); 149 return this; 150 } 151 152 /** 153 * To use a custom {@link AggregationStrategy} instead of the default 154 * implementation. Notice you cannot use both custom aggregation strategy 155 * and configure data at the same time. 156 */ 157 public ClaimCheckDefinition aggregationStrategy(Supplier<AggregationStrategy> aggregationStrategy) { 158 setAggregationStrategy(aggregationStrategy.get()); 159 return this; 160 } 161 162 /** 163 * To use a custom {@link AggregationStrategy} instead of the default 164 * implementation. Notice you cannot use both custom aggregation strategy 165 * and configure data at the same time. 166 */ 167 public ClaimCheckDefinition aggregationStrategyRef(String aggregationStrategyRef) { 168 setAggregationStrategyRef(aggregationStrategyRef); 169 return this; 170 } 171 172 /** 173 * This option can be used to explicit declare the method name to use, when 174 * using POJOs as the AggregationStrategy. 175 */ 176 public ClaimCheckDefinition aggregationStrategyMethodName(String aggregationStrategyMethodName) { 177 setAggregationStrategyMethodName(aggregationStrategyMethodName); 178 return this; 179 } 180 181 // Properties 182 // ------------------------------------------------------------------------- 183 184 public String getKey() { 185 return key; 186 } 187 188 public void setKey(String key) { 189 this.key = key; 190 } 191 192 public ClaimCheckOperation getOperation() { 193 return operation; 194 } 195 196 public void setOperation(ClaimCheckOperation operation) { 197 this.operation = operation; 198 } 199 200 public String getFilter() { 201 return filter; 202 } 203 204 public void setFilter(String filter) { 205 this.filter = filter; 206 } 207 208 public String getAggregationStrategyRef() { 209 return aggregationStrategyRef; 210 } 211 212 public void setAggregationStrategyRef(String aggregationStrategyRef) { 213 this.aggregationStrategyRef = aggregationStrategyRef; 214 } 215 216 public String getAggregationStrategyMethodName() { 217 return aggregationStrategyMethodName; 218 } 219 220 public void setAggregationStrategyMethodName(String aggregationStrategyMethodName) { 221 this.aggregationStrategyMethodName = aggregationStrategyMethodName; 222 } 223 224 public AggregationStrategy getAggregationStrategy() { 225 return aggregationStrategy; 226 } 227 228 public void setAggregationStrategy(AggregationStrategy aggregationStrategy) { 229 this.aggregationStrategy = aggregationStrategy; 230 } 231}