Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
3.19. Using an MVEL Expression
- To use an MVEL expression on a rule set, divide the Regex rules and place them in two separate
.propertiesfiles. - Drop these rules into the example
rulesdirectory. - Put the MVEL expression in a
.csvfile, also in therulesdirectory.The customer-related Regex rules that go in thecustomer.propertiesfile look like this:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Insert the product-related Regex rule in the
product.propertiesfile:Product data rules...
# Product data rules... productId=[0-9]{3}Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Insert the MVEL expression for performing the order item total check into the
order-rules.csvfile.NoteThe easiest way to edit a .csv file is through using a spreadsheet application like LibreOffice Calc or Gnumeric. - Create resource bundle
.propertiesfiles for each of the rule source files.NoteThe names of these files are derived from the names of their corresponding rule files.The message bundle for the rules defined inrules/customer.propertiesis located in therules/i18n/customer.propertiesfile:customerId=ftl:Invalid customer number '${ruleResult.text}' at '${path}'. Customer number must begin with an uppercase character, followed by 5 digits. email=ftl:Invalid email address '${ruleResult.text}' at '${path}'. Email addresses match pattern '${ruleResult.pattern}'.customerId=ftl:Invalid customer number '${ruleResult.text}' at '${path}'. Customer number must begin with an uppercase character, followed by 5 digits. email=ftl:Invalid email address '${ruleResult.text}' at '${path}'. Email addresses match pattern '${ruleResult.pattern}'.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The message bundle for the rule defined inrules/product.propertiesis located in therules/i18n/product.propertiesfile:Product data rule messages...
# Product data rule messages... productId=ftl:Invalid product ID '${ruleResult.text}' at '${path}'. Product ID must match pattern '${ruleResult.pattern}'.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The message bundle for the rule defined inrules/order-rules.csvis located in therules/i18n/order-rules.propertiesfile:Order item rule messages. The "orderDetails" and "orderItem" beans are populated by Smooks bindings
# Order item rule messages. The "orderDetails" and "orderItem" beans are populated by Smooks bindings order_item_total=ftl:Order ${orderDetails.orderId} contains an order item for product ${orderItem.productId} with a quantity of ${orderItem.quantity} and a unit price of ${orderItem.price}. This exceeds the permitted per order item total.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Apply this validation to the rules:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Execute from the example's
Mainclass using this code:Copy to Clipboard Copied! Toggle word wrap Toggle overflow