public static interface Route.After extends Route.Filter
{
after("GET", "*", (req, rsp, result) -> {
// your code goes here
return result;
});
}
You are allowed to modify the request, response and result objects. The handler returns a
Result
which can be the same or an entirely new Result
.
Please note that the after
handler is just syntax sugar for
Route.Filter
.
For example, the after
handler was implemented as:
{
use("GET", "*", (req, rsp, chain) -> {
chain.next(req, new Response.Forwarding(rsp) {
public void send(Result result) {
rsp.send(after(req, rsp, result);
}
});
});
}
Due after
is implemented by wrapping the Response
object. A
after
handler must to be registered before the actual handler you want to
intercept.
{
after("GET", "/path", (req, rsp, result) -> {
// your code goes here
return result;
});
get("/path", req -> {
return "hello";
});
}
If you reverse the order then it won't work.
Remember: routes are executed in the order they are defined and the pipeline is executed as long you don't generate a response.
Modifier and Type | Method and Description |
---|---|
Result |
handle(Request req,
Response rsp,
Result result)
Allows for customized response before send it.
|
default 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. |
default void handle(Request req, Response rsp, Route.Chain chain) throws Throwable
Route.Filter
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)
),handle
in interface Route.Filter
req
- A HTTP request.rsp
- A HTTP response.chain
- A route chain.Throwable
- If something goes wrong.Result handle(Request req, Response rsp, Result result) throws Exception
req
- Request.rsp
- Responseresult
- Result.Exception
- If something goes wrong.Copyright © 2018. All rights reserved.