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>
|
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
Div |
---|
class | confluenceTableSmall |
---|
|
Wiki Markup |
---|
{div:class=confluenceTableSmall}
|| Option || Default || Description ||
| {{group}} | {{ Option | Default | Description |
---|
group |
javax.validation.groups.Default
|
}} | |
| {{validationProviderResolver}} | Depends on JSR303 jar provided. | Reference to a custom {{ | validationProviderResolver | Depends on JSR303 jar provided. | Camel 2.13.0: Reference to a custom javax.validation.ValidationProviderResolver |
}} []. |
| {{messageInterpolator}} | {{. | messageInterpolator | org.hibernate.validator.engine.
|
\\ResourceBundleMessageInterpolator}} | Reference to a custom {{ ResourceBundleMessageInterpolator
| Reference to a custom javax.validation.MessageInterpolator |
}} []. |
| {{traversableResolver}} | {{. | traversableResolver | org.hibernate.validator.engine.resolver.
|
\\DefaultTraversableResolver}} | Reference to a custom {{ DefaultTraversableResolver
| Reference to a custom javax.validation.TraversableResolver |
}} []. |
| {{constraintValidatorFactory}} | {{. | constraintValidatorFactory | org.hibernate.validator.engine.
|
\\ConstraintValidatorFactoryImpl}} | Reference to a custom {{ ConstraintValidatorFactoryImpl
| Reference to a custom javax.validation.ConstraintValidatorFactory |
}} []. |
{div} |
ServiceMix4/OSGi Deployment.
OSGi deployment
To use Hibernate Validator in the OSGi environment use dedicated ValidationProviderResolver
implementation, just as org.apache.camel.component.bean.validator.HibernateValidationProviderResolver
. The snippet below demonstrates this approach. Keep in mind that you can use HibernateValidationProviderResolver
starting from the Camel 2.13.0.
Code Block |
---|
title | Using HibernateValidationProviderResolver |
---|
|
from("direct:test").
to("bean-validator://ValidationProviderResolverTest?validationProviderResolver=#myValidationProviderResolver");
...
<bean id="myValidationProviderResolver" class="org.apache.camel.component.bean.validator.HibernateValidationProviderResolver"/> |
If no custom ValidationProviderResolver
is defined and the validator component has been deployed into the OSGi environment, the HibernateValidationProviderResolver
will be automatically usedThe 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.
Example
Assumed we have a java bean with the following annotations
...