public static interface Route.Filter
Route.Handler
but it decided if the next route handler in the chain
can be executed or not. Example of filters are:
String token = req.header("token").value(); if (token != null) { // validate token... if (valid(token)) { chain.next(req, rsp); } } else { rsp.status(403); }
long start = System.currentTimeMillis(); chain.next(req, rsp); long end = System.currentTimeMillis(); log.info("Request: {} took {}ms", req.path(), end - start);NOTE: Don't forget to call
Route.Chain.next(Request, Response)
if next route handler
need to be executed.Modifier and Type | Method and Description |
---|---|
void |
handle(Request req,
Response rsp,
Route.Chain chain)
The
handle method of the Filter is called by the server each time a
request/response pair is passed through the chain due to a client request for a resource at
the end of the chain. |
void handle(Request req, Response rsp, Route.Chain chain) throws Exception
handle
method of the Filter is called by the server each time a
request/response pair is passed through the chain due to a client request for a resource at
the end of the chain.
The Route.Chain
passed in to this method allows the Filter to pass on the request and
response to the next entity in the chain.
A typical implementation of this method would follow the following pattern:
Route.Chain
object (chain.next(req, rsp)
),req
- A HTTP request.rsp
- A HTTP response.chain
- A route chain.Exception
- If something goes wrong.Copyright © 2015. All rights reserved.