Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.このコンテンツは選択した言語では利用できません。
Chapter 10. Bean Validation
Bean Validation Component リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Available as of Apache Camel 2.3
The Validation 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.
Maven users will need to add the following dependency to their
pom.xml
for this component:
URI format リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
bean-validator:something[?options]
bean-validator:something[?options]
or
bean-validator://something[?options]
bean-validator://something[?options]
Where something must be present to provide a valid URL. You can append query options to the URI in the following format,
?option=value&option=value&...
URI Options リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The following URI options are supported:
Option | Default | Description |
---|---|---|
group
|
javax.validation.groups.Default
|
The custom validation group to use. |
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.
|
Example リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Assumed we have a java bean with the following annotations
Car.java
and an interface definition for our custom validation group
OptionalChecks.java
public interface OptionalChecks { }
public interface OptionalChecks {
}
with the following Apache Camel route, only the @NotNull constraints on the attributes manufacturer and licensePlate will be validated (Apache Camel uses the default group
javax.validation.groups.Default
).
from("direct:start") .to("bean-validator://x") .to("mock:end")
from("direct:start")
.to("bean-validator://x")
.to("mock:end")
If you want to check the constraints from the group
OptionalChecks
, you have to define the route like this
from("direct:start") .to("bean-validator://x?group=OptionalChecks") .to("mock:end")
from("direct:start")
.to("bean-validator://x?group=OptionalChecks")
.to("mock:end")
If you want to check the constraints from both groups, you have to define a new interface first
AllChecks.java
@GroupSequence({Default.class, OptionalChecks.class}) public interface AllChecks { }
@GroupSequence({Default.class, OptionalChecks.class})
public interface AllChecks {
}
and then your route definition should looks like this
from("direct:start") .to("bean-validator://x?group=AllChecks") .to("mock:end")
from("direct:start")
.to("bean-validator://x?group=AllChecks")
.to("mock:end")
And if you have to provide your own message interpolator, traversable resolver and constraint validator factory, you have to write a route like this
It's also possible to describe your constraints as XML and not as Java annotations. In this case, you have to provide the file
META-INF/validation.xml
which could looks like this
validation.xml
and the
constraints-car.xml
file
constraints-car.xml