Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.

Validate

Available as of Camel 2.3

Validate uses an expression or predicates to validate the contents of a message. It 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 evaluates the Predicate/Expression and if it is false a PredicateValidationException is thrown. If it is true message processing continues.

Using from Java DSL

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

from("file://inbox")
  .validate(body(String.class).regex("^\\w{10}\\,\\d{2}\\,\\w{24}$"))
.to("bean:MyServiceBean.processLine");

Validate is not limited to the message body. You can also validate the message header.

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

You can also use validate together with simple.

from("file://inbox")
  .validate(simple("${in.header.bar} == 100"))
.to("bean:MyServiceBean.processLine");

Using from Spring DSL

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

<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:

<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"/>

Using This Pattern

If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram