public class BeanValidationInterceptor<T extends Message<?>> extends Object implements MessageHandlerInterceptor<T>, MessageDispatchInterceptor<T>
MessageHandlerInterceptor
or as a MessageDispatchInterceptor
.Constructor and Description |
---|
BeanValidationInterceptor()
Initializes a validation interceptor using a default ValidatorFactory (see
Validation.buildDefaultValidatorFactory() ). |
BeanValidationInterceptor(javax.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<javax.validation.ConstraintViolation<Object>> |
validateMessage(Object message,
javax.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()
Validation.buildDefaultValidatorFactory()
).public BeanValidationInterceptor(javax.validation.ValidatorFactory validatorFactory)
validatorFactory
- the factory providing Validator instances for this interceptor.public Object handle(UnitOfWork<? extends T> unitOfWork, 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 messagepublic BiFunction<Integer,T,T> handle(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<javax.validation.ConstraintViolation<Object>> validateMessage(Object message, javax.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 factorynull
.Copyright © 2010–2019. All rights reserved.