Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16560

Consider empty string in clientRequestValidation for REST HTTP body

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.10.0
    • None
    • None
    • Unknown

    Description

      Small thing I noticed when configuring a REST route with clientRequestValidation = true with camel-platform-http-vertx. E.g like:

      .post("/validation")
          .clientRequestValidation(true)            
          .param().name("foo").type(RestParamType.body).required(true).endParam()
          .route()
              .setBody(simple("Hello ${header.foo}"))
          .endRest()
      

      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?

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jamesnetherton James Netherton
            jamesnetherton James Netherton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment