Hi,

In my Rest DSL route, I use the Validate DSL and mvel to validate data as it
goes through the pipeline. If there's a validation exception, I would like
to return back to the client both an HTTP_RESPONSE_CODE 400 as well as the
reason for the error in the body. I'm able to set the HTTP response code but
not sure how I can customize the reason for each validation exception.

For example, in my route below:

@Override
public void configure() throws Exception {
onException(org.apache.camel.processor.validation.PredicateValidationException.class).handled(true).transform().simple("Validation
failed").setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400));
        rest("system")
                .put("cancel-trade")
                .route()
                .validate().mvel("request.body.?extid > 0")
                .to("sql:select id from trades where outid = :#extid
?outputHeader=id&outputType=SelectOne")
                .validate().mvel("request.headers.?id != null")
                .to("mock:bean");

I currently only say "Validation failed" in the body in the case of a
PredicateValdiationException thrown. I would like to return a customized
human readable message though depending on each failure. So if the first
validate fails, I would like the reply to say "External ID must be greater
than 0" and if the second validate fails "Trade not found in trades table".

Is this possible with the Validate DSL?

Thanks



--
View this message in context: 
http://camel.465427.n5.nabble.com/Validate-DSL-and-message-returned-to-client-tp5768293.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to