简体   繁体   English

列出Vertx中所有已注册的路线

[英]List all registered routes in Vertx

Is there any way (like in a symfony application) to list down all the available/register routes on a vertx server? 是否有任何方法(如在symfony应用程序中)列出vertx服务器上的所有可用/寄存器路由? I am facing an issue that my registered route is returning a 404 on running restassure tests. 我正面临一个问题,即我的注册路线在运行的休息测试中返回404。

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());
}

This will result in: 这将导致:

[GET]/
[GET]/users
[POST]/users

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM