Hey guys, could I possibly a see a sample application using JSR-303 validation? Sounds useful!
I’m not sure the example applications have a jsr303 example in them yet. I’ll check as soon as I have a proper computer at my disposal.
Configuring it is pretty simple. You’ll need a jsr303 implementation, such as Hibernate-Validator. Then, configure a validating interceptor (it’s provided by Axon) and configure it with a validator instance. If your commands are annotated with 303-annotations, you’ll see the exceptions flying by…
I’ll create a little code sample when I have the chance.
I added some JSR-303 “magic” to the Axon Trader sample. It’s a crude implementatoin, because the error handling is not implemented nicely.
The BeanValidationInterceptor is now defined as a dispatch interceptor. This means an exception will be thrown directly by the commandBus.dispatch method, instead of invoking the callback. If you configure it as a command handling interceptor, the callback will be invoked instead.
Generally, the former is a better idea for structural validation: you don’t want to spend CPU time on an invalid command. The earlier you fail, the better.