Vertx-web: Request Body Handling - body always null

Created on 23 Jun 2016  路  2Comments  路  Source: vert-x3/vertx-web

Version

  • vert.x core: 3.2.1
  • vert.x web: 3.2.1

    Context

The following documentation http://vertx.io/docs/vertx-web/groovy/#_request_body_handling is not completelly clear. Turns out that BodyHandler must be defined before any route definitions, but the documentation only advices to define it as soon as possible.

You should make sure a body handler is on a matching route for any requests that require this functionality.
The usage of this handler requires that it is installed as soon as possible in the router since it needs to install handlers to consume the HTTP request body and this must be done before executing any async call.

Or is this a bug?

Do you have a reproducer?

The following is a gist with reproducible code.

Steps to reproduce

  1. Create the router
    def router = Router.router(vertx)
  2. Define the route(s)
    def route = router.route(HttpMethod.POST,"/method")
  3. Create the body handler
    router.route().handler(BodyHandler.create())
  4. Body will always be null

Most helpful comment

Yes I know the order is what makes or break, that's what I demonstrated and what I mean by "the documentation is not clear".

Anyways, at least it is clarified somewhere so I'm closing.

All 2 comments

That will not work because of the order you're setting:

  1. you run your handler
  2. you parse the body

even though you write the handler code in the end you registered the route before the body handler so it will be invoked first.

Yes I know the order is what makes or break, that's what I demonstrated and what I mean by "the documentation is not clear".

Anyways, at least it is clarified somewhere so I'm closing.

Was this page helpful?
0 / 5 - 0 ratings