public static interface Route.After
{
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");
});
}
Modifier and Type | Method and Description |
---|---|
void |
apply(Context ctx,
Object result,
Throwable failure)
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.
|
@Nonnull default Route.After then(@Nonnull Route.After next)
next
- Next filter.void apply(@Nonnull Context ctx, @Nullable Object result, @Nullable Throwable failure) throws Exception
ctx
- Web context.result
- Response generated by route handler.failure
- Uncaught exception generated by route handler.Exception
- If something goes wrong.Copyright © 2022. All rights reserved.