perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Request.params() is emptied in filters #1150

Open mehdone opened 4 years ago

mehdone commented 4 years ago

I am trying to access URI params in filters and I'm getting zero sized map when calling Request.params(). The params() method works as expected in the route itself but not in before and after filters.

@Override
    public void handle(Request req, Response res) {
        if (req.uri().contains("/publish")) {
            if (NOTIFICATION.equals(req.params(":type").toLowerCase())) {
                Message m = JsonIterator.deserialize(req.body(), Message.class);
                req.attribute(PUBLISH_BODY, m);

                if (m == null || m.getN() == null)
                    Spark.halt(HttpStatus.SC_BAD_REQUEST);
            }
        }
    }

In the above example req.params(":type") returns null and req.params() is an empty map