列出 Vertx 中所有注册的路由 [英] List all registered routes in Vertx
本文介绍了列出 Vertx 中所有注册的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法(比如在 symfony 应用程序中)列出 vertx 服务器上的所有可用/注册路由?我遇到了一个问题,即我注册的路由在运行恢复测试时返回 404.
Is there any way (like in a symfony application) to list down all the available/register routes on a vertx server? I am facing an issue that my registered route is returning a 404 on running restassure tests.
推荐答案
是的,但您必须编写一些代码才能实现这一点.
Yes, but you have to write a bit of code to achieve that.
// Example router setup
Router router = Router.router(vertx);
router.route(HttpMethod.GET, "/").handler(routingContext -> {
routingContext.response().end("Root");
});
router.route(HttpMethod.GET, "/users").handler(routingContext -> {
routingContext.response().end("Post");
});
router.route(HttpMethod.POST, "/users").handler(routingContext -> {
routingContext.response().end("Post");
});
// Getting the routes
for (Route r : router.getRoutes()) {
// Path is public, but methods are not. We change that
Field f = r.getClass().getDeclaredField("methods");
f.setAccessible(true);
Set<HttpMethod> methods = (Set<HttpMethod>) f.get(r);
System.out.println(methods.toString() + r.getPath());
}
这将导致:
[GET]/
[GET]/users
[POST]/users
这篇关于列出 Vertx 中所有注册的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文