vert.xvertx4java-vertx-web

Vertx Web routers are "losing" request parameters


I am running a test Vertx application that is supposed to receive a POST request and process some JSON data. This is using Vertx V4.3.8.

The JSON data is being passed through the following Javascript code:

var countWords = function(toSend) {
    var data = { DataList : [toSend] };
    var json = JSON.stringify(data);
    var param = { theText: json };

    $.post(theURL+"/service/wordcount",param,
        function(ret,status) {
           if(status == "success") {
               var result = JSON.parse(ret);
               if(result.result == 0){
                   $("#wordcount").val(result.data[0]);
               }
               else {
                   alert("Failed to count words! "+result.failure);
               }
           }
           else {
               alert("FAILED to access the word counter service!");
           }
    });
};

The parameter, of course is named "theText". It should be noted that the above code passes this parameter to an existing Spring Boot application without problems. This application is testing my ability to create a similar application using Vertx.

On the server side, I perform a test using a basic Vertx Web router:

     route.route(HttpMethod.POST,"/service/*").blockingHandler(actx->{
        HttpServerRequest test = actx.request();
        
        MultiMap params = test.params();
        MultiMap headers = test.headers();
        Map<String,String> paths = actx.pathParams();
        MultiMap queries = actx.queryParams();
        log.info("Stopping Point!");
        
        log.info("Number of parameters: {}",params.size());
        log.info("Number of headers: {}",headers.size());
        log.info("Number of paths: {}",paths.size());
        log.info("Number of queries: {}",queries.size());
        
        actx.end();
     });

Note that I am temporarily using a blocking handler so I can do debugging. The behavior I am going to describe is the same whether I use handler() or blockingHandler().

When running my test, I get the following log entries:

Wed 02-22-2023 11:07 INFO net.factor3.blocks.testparam - Stopping Point!
Wed 02-22-2023 11:07 INFO net.factor3.blocks.testparam - Number of parameters: 0
Wed 02-22-2023 11:07 INFO net.factor3.blocks.testparam - Number of headers: 14
Wed 02-22-2023 11:07 INFO net.factor3.blocks.testparam - Number of paths: 1
Wed 02-22-2023 11:07 INFO net.factor3.blocks.testparam - Number of queries: 0

When I place a breakpoint at the "Stopping point" and examine the various parameters, I see that:

  1. the params map contains 16 null entries
  2. the headers map has what appear to be correct HTTP header entries
  3. The paths map has an entry representing the /service path
  4. The queries map has 16 null entries

It looks like there is some problem with the Vertx Web library that is causing it to "lose" parameters that are passed to it.

Have I found a bug in Vertx? Or is there some configuration of the Verticle I am using that is causing this problem?

Why are my parameters being lost by Vertx's request objects???

Someone please advise.


Solution

  • You should attach the body handler first on the router across all routes like router.router().handler(BodyHandler.create()

    After that - all your body data will be available

    If you have the body handler already attached - paste the larger server side code and I can check