public class RouteChain extends Object implements Route.Chain
Constructor and Description |
---|
RouteChain(RequestImpl req,
ResponseImpl rsp,
Route[] routes) |
Modifier and Type | Method and Description |
---|---|
void |
next(String prefix,
Request req,
Response rsp)
Invokes the next route in the chain where
Route.name() starts with the given prefix. |
List<Route> |
routes()
All the pending/next routes from pipeline.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
next
public RouteChain(RequestImpl req, ResponseImpl rsp, Route[] routes)
public void next(String prefix, Request req, Response rsp) throws Throwable
Route.Chain
Route.name()
starts with the given prefix.next
in interface Route.Chain
prefix
- Iterates over the route chain and keep routes that start with the given prefix.req
- A HTTP request.rsp
- A HTTP response.Throwable
- If invocation goes wrong.public List<Route> routes()
Route.Chain
use("*", (req, rsp, chain) -> {
List<Route> routes = chain.routes();
assertEquals(2, routes.size());
assertEquals("/r2", routes.get(0).name());
assertEquals("/r3", routes.get(1).name());
assertEquals("/786/:id", routes.get(routes.size() - 1).pattern());
chain.next(req, rsp);
}).name("r1");
use("/786/**", (req, rsp, chain) -> {
List<Route> routes = chain.routes();
assertEquals(1, routes.size());
assertEquals("/r3", routes.get(0).name());
assertEquals("/786/:id", routes.get(routes.size() - 1).pattern());
chain.next(req, rsp);
}).name("r2");
get("/786/:id", req -> {
return req.param("id").value();
}).name("r3");
routes
in interface Route.Chain
Copyright © 2017. All rights reserved.