Nav

Validation Module

The Validation module can verify that the contents of a message in a Mule flow match specific criteria. The module provides explicit messages about the cause of an exception in a flow. Based on the specific data you are validating, you can customize the exception message that is displayed in the logs.

If a message does not meet the defined validation criteria, the validation fails and returns a VALIDATION error (such as VALIDATION:INVALID_URL), which is a ValidationException. By default, this message includes a meaningful message that you can customize.

Supported Validation Operations

The Validation Module comes with a set validations to use out of the box (described below):

Is Blank String

Verifies that provided value is a blank String:


          
       
1
<validation:is-blank-string value="#[payload]"/>

Is Blank String

Verifies that provided value is not a blank String:


          
       
1
<validation:is-not-blank-string value="#[payload]" message="The username cannot be blank"/>

Is Empty Collection

Verifies that the provided value is an empty collection:


          
       
1
<validation:is-empty-collection values="#[payload]"/>

Is Not Empty Collection

Verifies that a value is not an empty collection. This value defaults to the payload:


          
       
1
<validation:is-not-empty-collection values="#[payload]"/>

Validate Size

Validates that the input’s size is between given min and max boundaries. It is valid for inputs of type String, Collection, Map, and Array. In the case of a String, the size refers to the length in characters:


          
       
1
<validation:validate-size value="#[payload]" min="#[vars.minLength]" max="#[vars.maxLength]"/>

Is Not Null

Fails if the provided value is null:


          
       
1
<validation:is-not-null value="#[payload]" message="Null is not a valid value"/>

Is Null

Fails if the provided value is not null:


          
       
1
<validation:is-null value="#[payload]"/>

Is True

Verifies that an expression evaluates to true:


          
       
1
<validation:is-true expression="#[vars.doReply]"/>

Is False

Verifies that an expression evaluates to false:


          
       
1
<validation:is-false expression="#[vars.withFailures]"/>

Is Number

Verifies that a String can be parsed as a Number of a specified numeric type, using the given locale (defaulting to the System Locale) and pattern (which defaults to the Locale pattern). This validation can include a range in which the number is valid using the minValue, maxValue parameters:


          
       
1
2
3
4
<validation:is-number value="#[payload]"
                      minValue="#[vars.minValue]"
                      maxValue="#[vars.maxValue]"
                      numberType="INTEGER" locale="US"/>

Is Time

Verifies that a time is valid for the given pattern and locale. If no pattern is provided, then the locale’s default will be used:


          
       
1
<validation:is-time time="#[payload]" pattern="h:mm a" locale="UK"/>

Is Elapsed Time

Validates that a given time has elapsed since the specified initial time:


          
       
1
<validation:is-elapsed time="20" timeUnit="SECONDS" since="#[vars.initialTime]"/>

Is Not Elapsed Time

Validates that a given time has not elapsed since the specified initial time:


          
       
1
<validation:is-not-elapsed time="20" timeUnit="SECONDS" since="#[vars.time]"/>

Is Email

Checks that a given email is valid. The value defaults to the payload:


          
       
1
<validation:is-email email="#[vars.email]" message="The value is not a valid email"/>

Is URL

Validates that a given String can be interpreted as a URL. This is done by invoking the URL(String) constructor in the java.net.URL class. If this constructor throws exception, then the validation fails. Any String that this constructor accepts is considered valid:


          
       
1
<validation:is-url url="#[vars.callbackUrl]"/>

Is IP

Checks that a given IP address is valid. It supports both IPV4 and IPV6. In the case of IPV6, both full and collapsed addresses are supported, but addresses containing ports are not supported:


          
       
1
<validation:is-ip ip="#[payload]" message="The value provided is not a valid IP address"/>

Is Whitelisted IP

Validates that a given IP is in the whitelisted IP list. The IP filter list can be defined globally in the app or inline for each validator:


          
       
1
2
3
4
5
6
7
8
9
10
11
<validation:ip-filter-list name="whitelist_ipv4">
  <validation:ips>
      <validation:ip value="192.168.1.0/24"/>
      <validation:ip value="127.0.0.1"/>
      <validation:ip value="193.1"/>
  </validation:ips>
</validation:ip-filter-list>

<flow name="validate-id">
  <validation:is-whitelisted-ip whiteList="whitelist_ipv4" ipAddress="#[payload]"/>
</flow>

Is Not Blacklisted IP

Validates that a given IP is not in the blacklisted IP list. The IP filter list can be defined globally in the app or inline for each validator:


          
       
1
2
3
4
5
6
7
8
9
<flow name="validate-not-filtered-ip">
  <validation:is-not-blacklisted-ip ipAddress="#[vars.ip]">
    <validation:black-list>
        <validation:ips>
            <validation:ip value="2001:db8::/48"/>
        </validation:ips>
    </validation:black-list>
  </validation:is-not-blacklisted-ip>
</flow>

Matches Regex

Validates that a given expression matches a Java regular expression:


          
       
1
<validation:matches-regex value="#[payload]" regex=".+\.log" caseSensitive="false"/>