Search code examples
helidon

Log every request in Helidon


I want to log something on every incoming request and then I used the .any() method in the routing and placed the logger there. However, this ruined the 404 not found behaviour. Is there another way to do this sort of enter/exit methods properly?


Solution

  • If you want to handle such “filter” like stuff, you should call req.next() - this will tell the server there is another handler. If nothing is found, 404 is returned as expected

    Routing.builder()
      .any((req, res) -> {
        System.out.println(“Request: ” + req.path());
        req.next();
      })
      .get(“/”, (req, res) -> res.send(“Hello World”))
    .build();