<commit_before>= Validate EIP
:doctitle: Validate
:shortname: validate
:description: Validates a message based on an expression
:since: 
:supportlevel: Stable

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.

== Options

// eip options: START
include::partial$eip-options.adoc[]
// eip options: END

== Samples

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

[source,java]
----
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.

[source,java]
----
from("file://inbox")
  .validate(header("bar").isGreaterThan(100))
  .to("bean:MyServiceBean.processLine");
----

You can also use validate together with simple.

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

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

[source,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:

[source,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"/>
----<commit_msg>CAMEL-16861: Cleanup and update EIP docs<commit_after>= Validate EIP
:doctitle: Validate
:shortname: validate
:description: Validates a message based on an expression
:since: 
:supportlevel: Stable

The Validate EIP uses an xref:latest@manual:ROOT:expression.adoc[Expression] or xref:latest@manual:ROOT:predicate.adoc[Predicate]
to validate the contents of a message.

image::eip/MessageSelectorIcon.gif[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

// eip options: START
include::partial$eip-options.adoc[]
// eip options: END

=== Using Validate EIP

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

[source,java]
----
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.

[source,java]
----
from("file:inbox")
  .validate(header("bar").isGreaterThan(100))
  .to("bean:myServiceBean.processLine");
----

You can also use validate together with the xref:components:languages:simple-language.adoc[Simple] language.

[source,java]
----
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
xref:components:languages:simple-language.adoc[Simple] language:

[source,xml]
----
<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::

[source,xml]
----
<route>
  <from uri="file:inbox"/>
  <validate>
    <simple>${header.bar} &gt; 100</simple>
  </validate>
  <to uri="bean:myServiceBean" method="processLine"/>
</route>
----
{'fraction_non_alphanumeric': 0.15990037359900375, 'fraction_numerical': 0.010709838107098382, 'mean_word_length': 4.412398921832884, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4941970', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1258, 'n_words': 380}