You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2021/04/29 09:00:13 UTC

[jira] [Commented] (CAMEL-16560) Consider empty string in clientRequestValidation for REST HTTP body

    [ https://issues.apache.org/jira/browse/CAMEL-16560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17335266#comment-17335266 ] 

Claus Ibsen commented on CAMEL-16560:
-------------------------------------

Ah yeah good catch.

If a HTTP body is required, and its an empty string (spaces etc) then I see that as an empty body and therefore should fail the validation.

> Consider empty string in clientRequestValidation for REST HTTP body
> -------------------------------------------------------------------
>
>                 Key: CAMEL-16560
>                 URL: https://issues.apache.org/jira/browse/CAMEL-16560
>             Project: Camel
>          Issue Type: Improvement
>            Reporter: James Netherton
>            Priority: Major
>
> Small thing I noticed when configuring a REST route with clientRequestValidation = true with camel-platform-http-vertx. E.g like:
> {code:java}
> .post("/validation")
>     .clientRequestValidation(true)            
>     .param().name("foo").type(RestParamType.body).required(true).endParam()
>     .route()
>         .setBody(simple("Hello ${header.foo}"))
>     .endRest()
> {code}
> If I don't provide a body in the POST request, then I'd expect a 400 status code. But it actually returns 200 as the Vert.x body handler initialises an empty Buffer which when converted to String results in an empty String.
> [https://github.com/apache/camel/blob/80b92e3624ae5db59a1a24a441f1b10b39eaa1a5/core/camel-core-processor/src/main/java/org/apache/camel/processor/RestBindingAdvice.java#L270]
> Thus this condition is false and Camel thinks the request is valid:
> [https://github.com/apache/camel/blob/80b92e3624ae5db59a1a24a441f1b10b39eaa1a5/core/camel-core-processor/src/main/java/org/apache/camel/processor/RestBindingAdvice.java#L275]
> Maybe instead of checking for null it should do ObjectHelper.isEmpty? Not sure if that is a 'safe' thing to do or if there's some scenario where an empty string body has some kind of meaning?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)