James Netherton created CAMEL-16560:
---------------------------------------

             Summary: 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


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)

Reply via email to