camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Validate DSL and message returned to client
Date Tue, 16 Jun 2015 07:18:41 GMT

No the validate dsl will use a predicate that returns true or false.
If it returns false, then an exception is thrown.

If you want to do some kind of custom error message etc. Then calling
a bean is simpler.

But we could consider adding some way of allowing validate dsl to use
an expression that can generate the exception message.

On Tue, Jun 16, 2015 at 5:49 AM, Karts <> wrote:
> 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:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:

View raw message