簡體   English   中英

列出Vertx中所有已注冊的路線

[英]List all registered routes in Vertx

是否有任何方法(如在symfony應用程序中)列出vertx服務器上的所有可用/寄存器路由? 我正面臨一個問題,即我的注冊路線在運行的休息測試中返回404。

是的,但你必須編寫一些代碼才能實現這一目標。

// 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM