Hello,

I am using bean-validator component to validate the content of some fields:

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
 return new RouteBuilder() {
@Override
public void configure() throws Exception {
 DataFormat jaxbDataFormat = new
JaxbDataFormat("com.mycompany.model.entities.weather");
 onException(BeanValidationException.class)
.handled(true)
.process(new Processor() {
 public void process(Exchange exchange) throws Exception {
String station = ((WeatherCurrent) exchange.getIn().getBody()).getStation();
 System.out.println("Weather station '" + station + "' does not meet
validation constraints. Skipping.");
}
 });

from("file:src/test/resources/weather/observation?fileName=observation_si_latest.xml&noop=true")
 .split()
.tokenizeXML("metData")
.unmarshal(jaxbDataFormat)
 .to("bean-validator://x")
.to("mock:meteo");
 }
};
}

Running this test route nicely prints out the weather station which do not
meet the validation criteria:

Weather station 'Bilje pri Novi Gorici' does not meet validation
constraints. Skipping.
Weather station 'Lisca' does not meet validation constraints. Skipping.
Weather station 'Novo mesto' does not meet validation constraints. Skipping.

Now I wanted to print the cause of the validation error, so I added the
exception message in the process method:

String exceptionMessage = exchange.getException().getMessage();
System.out.println("Weather station '" + station + "' does not meet
validation constraints(" + exceptionMessage + "). Skipping.");

and suddenly hell broke loose

[2012/03/28 08:37:48.648] ERROR [o.a.c.p.FatalFallbackErrorHandler:done]:
Exception occurred while trying to handle previously thrown exception on
exchangeId: ID-BOBB-54461-1332916666871-0-3 using:
[Channel[Wrap[com.mycompany.datarobot.weather.WeatherCurrentValidateConditionNotEmptyTest$1$1@15e92d7]
->
com.mycompany.datarobot.weather.WeatherCurrentValidateConditionNotEmptyTest$1$1@15e92d7]].
The previous and the new exception will be logged in the following.
[2012/03/28 08:37:48.653] ERROR [o.a.c.p.FatalFallbackErrorHandler:done]:
\--> Previous exception on exchangeId: ID-BOBB-54461-1332916666871-0-3
org.apache.camel.component.bean.validator.BeanValidationException:
Validation failed for:
com.mycompany.model.entities.weather.WeatherCurrent@1a4c5b4 errors:
[property: conditions; value: jasna; constraint: must match "jasno|pretežno
jasno|rahlo oblačno|delno oblačno|zmerno oblačno|pretežno
oblačno|oblačno|megla"; ]. Exchange[null] at
org.apache.camel.component.bean.validator.BeanValidator.process(BeanValidator.java:54)
~[camel-bean-validator-2.9.1.jar:2.9.1] at
org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:101)
~[camel-core-2.9.1.jar:2.9.1]
...
FAILED: testNumberOfWeatherStations
java.lang.AssertionError: mock://meteo Received message count. Expected:
<6> but was: <12>
...


What gives?

-borut

Reply via email to