Contact Free trial Login

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.

Is Blank String

Verifies that provided value is a blank String:

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

Is Not Blank String

Verifies that provided value is not a blank String:

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

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

Is Not an Empty Collection

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

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

Validate Size

Validates that the input’s size is between given min and max boundaries. This 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:

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

Is Not Null

Fails if the provided value is null:

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

Is Null

Fails if the provided value is not null:

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

Is True

Verifies that an expression evaluates to true:

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

Is False

Verifies that an expression evaluates to false:

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

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

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

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

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

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

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

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

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

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

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

Using the Module in Anypoint Studio 7

You can use this module by adding it as a dependency in your Mule app.

Installing the Extension

  1. Open your Mule project in Anypoint Studio.

  2. Go to the Mule Palette.

  3. Select Search in Exchange, and search for the Validation Module.

  4. Add the extension.

  5. You can now search in the Mule Palette for operations of the Validation Module.

Was this article helpful?

πŸ’™ Thanks for your feedback!

Edit on GitHub