|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.commandhandling.interceptors.BeanValidationInterceptor
public class BeanValidationInterceptor
Interceptor that applies JSR303 bean validation on incoming commands. When validation on a command fails, a JSR303ViolationException is thrown, holding the constraint violations.
This interceptor can either be used as aCommandHandlerInterceptor
or as a CommandDispatchInterceptor
.
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
CommandMessage<?> |
handle(CommandMessage<?> command)
Invoked each time a command is about to be dispatched on a Command Bus. |
Object |
handle(CommandMessage<?> command,
UnitOfWork unitOfWork,
InterceptorChain interceptorChain)
The handle method is invoked each time a command is dispatched through the command bus that the CommandHandlerInterceptor is declared on. |
protected Set<javax.validation.ConstraintViolation<Object>> |
validateCommand(Object command,
javax.validation.Validator validator)
Validate the given command using the given validator . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanValidationInterceptor()
Validation.buildDefaultValidatorFactory()
).
public BeanValidationInterceptor(javax.validation.ValidatorFactory validatorFactory)
validatorFactory
- the factory providing Validator instances for this interceptor.Method Detail |
---|
public Object handle(CommandMessage<?> command, UnitOfWork unitOfWork, InterceptorChain interceptorChain) throws Throwable
CommandHandlerInterceptor
unitOfWork
.
The interceptor is responsible for the continuation of the dispatch process by invoking the InterceptorChain.proceed(CommandMessage)
method on the given
interceptorChain
.
Any information gathered by interceptors may be attached to the unitOfWork. This information is made
available to the CommandCallback provided by the dispatching component.
Interceptors are highly recommended not to change the type of the command handling result, as the dispatching
component might expect a result of a specific type.
handle
in interface CommandHandlerInterceptor
command
- The command being dispatchedunitOfWork
- The UnitOfWork in whichinterceptorChain
- The interceptor chain that allows this interceptor to proceed the dispatch process
Throwable
- any exception that occurs while handling the commandpublic CommandMessage<?> handle(CommandMessage<?> command)
CommandDispatchInterceptor
commandMessage
represents the command being dispatched.
handle
in interface CommandDispatchInterceptor
command
- The command message intended to be dispatched on the Command Bus
protected Set<javax.validation.ConstraintViolation<Object>> validateCommand(Object command, javax.validation.Validator validator)
command
using the given validator
. The default implementation
merely calls validator.validate(command)
.
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.
command
- The command to validatevalidator
- The validator provided by the validator factory
null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |