Validate

The Validate EIP uses an Expression or Predicate to validate the contents of a message.

image

This is useful for ensuring that messages are valid before attempting to process them.

When a message is not valid then a PredicateValidationException is thrown.

Options

The Validate eip has no options.

Using Validate EIP

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

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

Validate EIP 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 the Simple language.

from("file:inbox")
  .validate(simple("${header.bar} > 100"))
  .to("bean:myServiceBean.processLine");

To use validate in the XML DSL, the easiest way is to use Simple language:

<route>
  <from uri="file:inbox"/>
  <validate>
    <simple>${body} regex ^\\w{10}\\,\\d{2}\\,\\w{24}$</simple>
  </validate>
  <to uri="bean:myServiceBean" method="processLine"/>
</route>
The XML DSL to validate the message header is as follows
<route>
  <from uri="file:inbox"/>
  <validate>
    <simple>${header.bar} &gt; 100</simple>
  </validate>
  <to uri="bean:myServiceBean" method="processLine"/>
</route>