Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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
xml
xml
<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

Div
classconfluenceTableSmall
Wiki Markup
{div:class=confluenceTableSmall} || Option || Default || Description || | {{group}} | {{

Option

Default

Description

group

javax.validation.groups.Default

}} |

The

custom

validation

group

to

use.

| | {{validationProviderResolver}} | Depends on JSR303 jar provided. | Camel *

validationProviderResolver

Depends on JSR303 jar provided.

Camel 2.13.0

*

:

Reference

to

a

custom

{{

javax.validation.ValidationProviderResolver

}}

in

the

[]. | | {{messageInterpolator}} | {{

.

messageInterpolator

org.hibernate.validator.engine.

\\ResourceBundleMessageInterpolator}} | Reference to a custom {{


ResourceBundleMessageInterpolator

Reference to a custom javax.validation.MessageInterpolator

}}

in

the

[]. | | {{traversableResolver}} | {{

.

traversableResolver

org.hibernate.validator.engine.resolver.

\\DefaultTraversableResolver}} | Reference to a custom {{


DefaultTraversableResolver

Reference to a custom javax.validation.TraversableResolver

}}

in

the

[]. | | {{constraintValidatorFactory}} | {{

.

constraintValidatorFactory

org.hibernate.validator.engine.

\\ConstraintValidatorFactoryImpl}} | Reference to a custom {{


ConstraintValidatorFactoryImpl

Reference to a custom javax.validation.ConstraintValidatorFactory

}}

in

the

[]

.

| {div}

...

OSGi

...

deployment

To use

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.

The other way to load Hibernate Validator in the OSGi environment is to 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
titleUsing 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 used.

Example

Assumed we have a java bean with the following annotations

...