Class PayloadValidatingMessageSelector
java.lang.Object
org.springframework.integration.selector.PayloadValidatingMessageSelector
- All Implemented Interfaces:
GenericSelector<Message<?>>, 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 Summary
ConstructorsConstructorDescriptionPayloadValidatingMessageSelector(Validator validator) Create a selector for the provided validator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidsetAcceptUnsupportedPayloads(boolean acceptUnsupportedPayloads) Whether a payload the validator does notsupportis accepted.voidsetValidationHints(Object... validationHints) Set the validation hints to pass to aSmartValidator, for example Bean Validation groups.
-
Constructor Details
-
PayloadValidatingMessageSelector
Create a selector for the provided validator.- Parameters:
validator- the validator to apply to the message payload.
-
-
Method Details
-
setValidationHints
Set the validation hints to pass to aSmartValidator, for example Bean Validation groups. Ignored when the validator is not aSmartValidator.- Parameters:
validationHints- the validation hints.- See Also:
-
setAcceptUnsupportedPayloads
public void setAcceptUnsupportedPayloads(boolean acceptUnsupportedPayloads) Whether a payload the validator does notsupportis accepted.- Parameters:
acceptUnsupportedPayloads- true to accept such payloads; false (the default) to reject them.
-
accept
- Specified by:
acceptin interfaceGenericSelector<Message<?>>- Specified by:
acceptin interfaceMessageSelector
-