Class PayloadValidatingMessageSelector

java.lang.Object
org.springframework.integration.selector.PayloadValidatingMessageSelector
All Implemented Interfaces:
GenericSelector<Message<?>>, MessageSelector

public class PayloadValidatingMessageSelector extends Object implements MessageSelector
The MessageSelector implementation to accept a message only if its payload passes the validation of the provided Validator.

A Bean Validation (JSR-303) provider can be plugged in through the org.springframework.validation.beanvalidation.LocalValidatorFactoryBean, which exposes it as a Spring Validator.

Used with a MessageFilter, messages with an invalid payload are discarded, sent to the discard channel or rejected with an exception, according to the filter configuration.

A payload the validator does not support is rejected by default; set setAcceptUnsupportedPayloads(boolean) to true to accept such messages instead.

Each rejection is logged at INFO level with the ID of the message and the validation errors (the field names and the error messages, but not the rejected values).

Since:
7.2
Author:
Sharang Gupta, Artem Bilan
See Also:
  • Constructor Details

    • PayloadValidatingMessageSelector

      public PayloadValidatingMessageSelector(Validator validator)
      Create a selector for the provided validator.
      Parameters:
      validator - the validator to apply to the message payload.
  • Method Details

    • setValidationHints

      public void setValidationHints(Object... validationHints)
      Set the validation hints to pass to a SmartValidator, for example Bean Validation groups. Ignored when the validator is not a SmartValidator.
      Parameters:
      validationHints - the validation hints.
      See Also:
    • setAcceptUnsupportedPayloads

      public void setAcceptUnsupportedPayloads(boolean acceptUnsupportedPayloads)
      Whether a payload the validator does not support is accepted.
      Parameters:
      acceptUnsupportedPayloads - true to accept such payloads; false (the default) to reject them.
    • accept

      public boolean accept(Message<?> message)
      Specified by:
      accept in interface GenericSelector<Message<?>>
      Specified by:
      accept in interface MessageSelector