Bean
...
Validator Component
Available as of Camel 2.3
The Validation Validator component performs bean validation of the message body using the Java Bean Validation API (JSR 303). Camel uses the reference implementation, which is Hibernate Validator.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-bean-validator</artifactId> <version>x.y.z</version> <!-- use the same version as your Camel core version --> </dependency> |
URI format
Code Block |
---|
bean-validator:label[?options] |
...
Where label is an arbitrary text value describing the endpoint.
You can append query options to the URI in the following format, ?option=value&option=value&...
URI Options
Wiki Markup |
---|
{div:class=confluenceTableSmall} || Option || Default || Description || | {{group}} | {{javax.validation.groups.Default}} | The custom validation group to use. | | {{validationProviderResolver}} | Depends on JSR303 jar provided. | Camel *2.13.0*: Reference to a custom {{javax.validation.ValidationProviderResolver}} in the [Registry]. | | {{messageInterpolator}} | {{org.hibernate.validator.engine.\\ResourceBundleMessageInterpolator}} | Reference to a custom {{javax.validation.MessageInterpolator}} in the [Registry]. | | {{traversableResolver}} | {{org.hibernate.validator.engine.resolver.\\DefaultTraversableResolver}} | Reference to a custom {{javax.validation.TraversableResolver}} in the [Registry]. | | {{constraintValidatorFactory}} | {{org.hibernate.validator.engine.\\ConstraintValidatorFactoryImpl}} | Reference to a custom {{javax.validation.ConstraintValidatorFactory}} in the [Registry]. | {div} |
ServiceMix4/OSGi Deployment.
The bean-validator when deployed in an OSGi environment requires a little help to accommodate the resource loading specified in JSR303, this was fixed in Servicemix-Specs 1.6-SNAPSHOT.
...
Code Block | ||
---|---|---|
| ||
from("direct:test"). to("bean-validator://ValidationProviderResolverTest?validationProviderResolver=#myValidationProviderResolver"); ... <bean id="myValidationProviderResolver" class="org.apache.camel.component.bean.validator.HibernateValidationProviderResolver"/> |
Example
Assumed we have a java bean with the following annotations
...