Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Available as of Camel 2.3

Validate can be used uses an expression or predicates to validate the contents of a message. Imagine you consume text files and before processing each file you want to be sure the content is validIt is useful for ensuring that messages are valid before attempting to process them.

You can use the validate DSL with all kind of Predicates and Expressions. Validate will just evaluated evaluates the Predicate/Expression and if its it is false an a PredicateValidationException is thrown. If it is true message processing continues.

Using from Java DSL

In the The route below it will read the file content contents and validate it them against a regular expression.

...

Code Block
from("file://inbox")
  .validate(header("bar").isGreaterThan(100))
.to("bean:MyServiceBean.processLine");

And sure, you You can also use validate together with simple.

...

To use validate in the Spring DSL, the easiest way is to use simple expressions.

Code Block
xml
xml
<route>
  <from uri="file://inbox"/>
  <validate>
    <simple>${body} regex ^\\w{10}\\,\\d{2}\\,\\w{24}$</simple>
  </validate>
  <beanRef ref="myServiceBean" method="processLine"/>
</route>

<bean id="myServiceBean" class="com.mycompany.MyServiceBean"/>

The XML DSL to validate the message header would looks like this.:

Code Block
xml
xml
<route>
  <from uri="file://inbox"/>
  <validate>
    <simple>${in.header.bar} == 100</simple>
  </validate>
  <beanRef ref="myServiceBean" method="processLine"/>
</route>

<bean id="myServiceBean" class="com.mycompany.MyServiceBean"/>
Include Page
CAMEL:Using This PatternCAMEL:
Using This Pattern