- Enclosing class:
- Route
public static interface Route.After
Execute application logic after a response has been generated by a route handler.
For functional handler the value is accessible and you are able to modify the response:
{
after((ctx, result) -> {
// Modify response
ctx.setResponseHeader("foo", "bar");
// do something with value:
log.info("{} produces {}", ctx, result);
});
get("/", ctx -> {
return "Functional value";
});
}
For side-effect handler (direct use of send methods, outputstream, writer, etc.) you are not
allowed to modify the response or access to the value (value is always null
):
{
after((ctx, result) -> {
// Always null:
assertNull(result);
// Response started is set to: true
assertTrue(ctx.isResponseStarted());
});
get("/", ctx -> {
return ctx.send("Side effect");
});
}
- Since:
- 2.0.0
- Author:
- edgar
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Execute application logic on a route response.default Route.After
then
(Route.After next) Chain this filter with next one and produces a new after filter.
-
Method Details
-
then
Chain this filter with next one and produces a new after filter.- Parameters:
next
- Next filter.- Returns:
- A new filter.
-
apply
void apply(@NonNull Context ctx, @Nullable Object result, @Nullable Throwable failure) throws Exception Execute application logic on a route response.- Parameters:
ctx
- Web context.result
- Response generated by route handler.failure
- Uncaught exception generated by route handler.- Throws:
Exception
- If something goes wrong.
-