Hi

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 <kartiksan...@gmail.com> 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: 
> 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.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Reply via email to