validate

Processor that validates payloads by a given schema. Fails message processing if validation fails.

Properties

Name Summary

schema

The schema to validate against. Can be either the actual schema text or a resource-registry ID on the format <type>:<id>:<revision>. Set <revision> to latest to retrieve the latest one. For example: JsonSchema2019-09:transactions:latest.

format

The ValidationFormat of the string payload to be validated.

name

Optional, descriptive name for the processor.

id

Required identifier of the processor, unique across all processors within the flow. Must be between 3 and 30 characters long; contain only lower and uppercase alphabetical characters (a-z and A-Z), numbers, dashes ("-"), and underscores ("_"); and start with an alphabetical character. In other words, it adheres to the regex pattern [a-zA-Z][a-zA-Z0-9_-]{2,29}.

exchangeProperties

Optional set of custom properties in a simple jdk-format, that are added to the message exchange properties before processing the incoming payload. Any existing properties with the same name will be replaced by properties defined here.

retainPayloadOnFailure

Whether the incoming payload is available for error processing on failure. Defaults to false.

Sub-builders

Name Summary

messageLoggingStrategy

Strategy for describing how a processor’s message is logged on the server.

payloadArchivingStrategy

Strategy for archiving payloads.

inboundTransformationStrategy

Strategy that customizes the conversion of an incoming payload by a processor (e.g., string to object). Should be used when the processor’s default conversion logic cannot be used.

Details

Validation Sources

The validate processor can load validation content from the Resource Registry in the following manner:

validate {
    id = "xmlValidate"
    schema = "XSD:meterreadings:latest"
    format = ValidationFormat.XML
}

The resource type can be either XSD for XML validations or JsonSchema2019-09 for JSON compliant validations. The schema text can also be written verbatim in the schema property itself, as the following demonstrates:

validate {
    id = "jsonValidate"
    schema = """
      {
        "$id": "https://example.com/person.schema.json",
        "$schema": "https://json-schema.org/draft/2019-09/schema",
        "type": "object",
        "properties": {
          "myValue": {
            "type": "string",
            "maxLength": 10
          }
        }
      }
    """.trimIndent()
    format = ValidationFormat.JSON
}
Refer to the JSON Schema specifications for help on writing JSON validations.

Message Processing

If a payload does not meet the validation criteria, message processing will be interrupted with a non-transient error. In a REST-based flow, the response status code becomes 400, and the response body includes a message property detailing the validation failure.

The validate processor converts the incoming payload to a string. If validation is successful, the payload is passed on to the next processor as a string.