public class BeanValidationInterceptor<T extends Message<?>> extends Object implements MessageHandlerInterceptor<T>, MessageDispatchInterceptor<T>
Message
s. When validation on a message fails, a
JSR303ViolationException
is thrown, holding the constraint violations. This interceptor can either be used as
a MessageHandlerInterceptor
or as a MessageDispatchInterceptor
.Constructor and Description |
---|
BeanValidationInterceptor()
Initializes a validation interceptor using a default
ValidatorFactory . |
BeanValidationInterceptor(jakarta.validation.ValidatorFactory validatorFactory)
Initializes a validation interceptor using the given
ValidatorFactory . |
Modifier and Type | Method and Description |
---|---|
BiFunction<Integer,T,T> |
handle(List<? extends T> messages)
Apply this interceptor to the given list of
messages . |
Object |
handle(UnitOfWork<? extends T> unitOfWork,
InterceptorChain interceptorChain)
Invoked before a Message is handled by a designated
MessageHandler . |
protected Set<jakarta.validation.ConstraintViolation<Object>> |
validateMessage(Object message,
jakarta.validation.Validator validator)
Validate the given
message using the given validator . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handle
public BeanValidationInterceptor()
ValidatorFactory
.Validation.buildDefaultValidatorFactory()
public BeanValidationInterceptor(jakarta.validation.ValidatorFactory validatorFactory)
ValidatorFactory
.validatorFactory
- the factory providing Validator
instances for this interceptorpublic Object handle(@Nonnull UnitOfWork<? extends T> unitOfWork, @Nonnull InterceptorChain interceptorChain) throws Exception
MessageHandlerInterceptor
MessageHandler
.
The interceptor is responsible for the continuation of the handling process by invoking the InterceptorChain.proceed()
method on the given interceptorChain
.
The given unitOfWork
contains contextual information. Any information gathered by interceptors
may be attached to the unitOfWork.
Interceptors are highly recommended not to change the type of the message handling result, as the dispatching
component might expect a result of a specific type.handle
in interface MessageHandlerInterceptor<T extends Message<?>>
unitOfWork
- The UnitOfWork that is processing the messageinterceptorChain
- The interceptor chain that allows this interceptor to proceed the dispatch processException
- any exception that occurs while handling the message@Nonnull public BiFunction<Integer,T,T> handle(@Nonnull List<? extends T> messages)
MessageDispatchInterceptor
messages
. This method returns a function that can be invoked
to obtain a modified version of messages at each position in the list.handle
in interface MessageDispatchInterceptor<T extends Message<?>>
messages
- The Messages to pre-processprotected Set<jakarta.validation.ConstraintViolation<Object>> validateMessage(Object message, jakarta.validation.Validator validator)
message
using the given validator
. The default implementation merely calls
validator.validate(message)
.
Subclasses may override this method to alter the validation behavior in specific cases. Although the null
is accepted as return value to indicate that there are no constraint violations, implementations are encouraged
to return an empty Set instead.
message
- the message to validatevalidator
- the validator provided by the validator factoryConstraintViolation
s. May also return null
Copyright © 2010–2024. All rights reserved.