io.vertx.ext.web.Router.mountSubRouter()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中io.vertx.ext.web.Router.mountSubRouter方法的一些代码示例,展示了Router.mountSubRouter的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.mountSubRouter方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:mountSubRouter

Router.mountSubRouter介绍

[英]Mount a sub router on this router
[中]在此路由器上安装一个子路由器

代码示例

代码示例来源:origin: vert-x3/vertx-web

@Test(expected = IllegalArgumentException.class)
public void testInvalidMountPoint1() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath*", subRouter);
}

代码示例来源:origin: vert-x3/vertx-web

@Test(expected = IllegalArgumentException.class)
public void testInvalidMountPoint2() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath/*", subRouter);
}

代码示例来源:origin: vert-x3/vertx-web

@Test(expected = IllegalArgumentException.class)
public void testSubRoutePattern() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/foo/:abc/bar", subRouter);
}

代码示例来源:origin: vert-x3/vertx-web

@Test(expected = IllegalArgumentException.class)
public void testInvalidMountPoint3() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("subpath", subRouter);
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testSubRouterNPE() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/", subRouter);
 testRequest(HttpMethod.GET, "foo", 404, "Not Found");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testUnhandledRuntimeException() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo").handler(rc -> {
  throw new RuntimeException("Balderdash!");
 });
 testRequest(HttpMethod.GET, "/subpath/foo", 500, "Internal Server Error");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
 public void testStackOverflow() throws Exception {

  router.get("/files/:id/info").handler(ctx -> ctx.response().end());

  router.mountSubRouter("/v1", router);

  testRequest(HttpMethod.GET, "/v1/files/some-file-id/info", 200, "OK");
  testRequest(HttpMethod.GET, "/v1/files//info", 404, "Not Found");
 }
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testRegexInSubRouter() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/api", subRouter);
 subRouter.routeWithRegex("\\/test").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/api/test", 200, "sausages");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testEmptySubrouter() throws Exception {
 Router subRouter1 = Router.router(vertx);
 router.mountSubRouter("/foo", subRouter1);
 testRequest(HttpMethod.GET, "/foo", 404, "Not Found");
 testRequest(HttpMethod.GET, "/foo/bar", 404, "Not Found");
 testRequest(HttpMethod.GET, "/foo/bar/wibble", 404, "Not Found");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testServerRelativeToPathAndMountPoint() throws Exception {
 router.clear();
 Router subRouter = Router.router(vertx);
 subRouter.route("/somedir/*").handler(stat);
 router.mountSubRouter("/mymount/", subRouter);
 testRequest(HttpMethod.GET, "/mymount/somedir/otherpage.html", 200, "OK", "<html><body>Other page</body></html>");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void tesHandledRuntimeException2() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo/*").handler(rc -> {
  throw new RuntimeException("Balderdash!");
 });
 subRouter.route("/foo/*").failureHandler(rc -> {
  assertEquals(-1, rc.statusCode());
  assertEquals("Balderdash!", rc.failure().getMessage());
  rc.response().setStatusCode(555).setStatusMessage("Badgers").end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo/bar", 555, "Badgers");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNormalised3() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/api", subRouter);
 subRouter.route("/").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/api/", 200, "sausages");
 testRequest(HttpMethod.GET, "/api", 200, "sausages");
 testRequest(HttpMethod.GET, "/api///", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//", 200, "sausages");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void tesHandledRuntimeException1() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo/*").handler(rc -> {
  throw new RuntimeException("Balderdash!");
 });
 router.route("/subpath/*").failureHandler(rc -> {
  assertEquals(-1, rc.statusCode());
  assertEquals("Balderdash!", rc.failure().getMessage());
  rc.response().setStatusCode(555).setStatusMessage("Badgers").end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo/bar", 555, "Badgers");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNormalised4() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/api/", subRouter);
 subRouter.route("/").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/api/", 200, "sausages");
 testRequest(HttpMethod.GET, "/api", 200, "sausages");
 testRequest(HttpMethod.GET, "/api///", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//", 200, "sausages");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNormalised1() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/api", subRouter);
 subRouter.route("/foo").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/api/foo", 200, "sausages");
 testRequest(HttpMethod.GET, "/api/foo/", 200, "sausages");
 testRequest(HttpMethod.GET, "/api/foo//", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//foo//", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//foo///", 200, "sausages");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNormalised2() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/api/", subRouter);
 subRouter.route("/foo").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/api/foo", 200, "sausages");
 testRequest(HttpMethod.GET, "/api/foo/", 200, "sausages");
 testRequest(HttpMethod.GET, "/api/foo//", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//foo//", 200, "sausages");
 testRequest(HttpMethod.GET, "//api//foo///", 200, "sausages");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testSimple() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo").handler(rc -> {
  assertEquals("/subpath", rc.mountPoint());
  rc.response().setStatusMessage(rc.request().path()).end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo", 200, "/subpath/foo");
 testRequest(HttpMethod.GET, "/subpath/", 404, "Not Found");
 testRequest(HttpMethod.GET, "/subpath/bar", 404, "Not Found");
 testRequest(HttpMethod.GET, "/otherpath", 404, "Not Found");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testTrailingSlash() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath/", subRouter);
 subRouter.route("/foo").handler(rc -> {
  assertEquals("/subpath", rc.mountPoint());
  rc.response().setStatusMessage(rc.request().path()).end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo", 200, "/subpath/foo");
 testRequest(HttpMethod.GET, "/subpath/", 404, "Not Found");
 testRequest(HttpMethod.GET, "/subpath/bar", 404, "Not Found");
 testRequest(HttpMethod.GET, "/otherpath", 404, "Not Found");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testFailCalled1() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo/*").handler(rc -> rc.fail(557));
 router.route("/subpath/*").failureHandler(rc -> {
  assertEquals(557, rc.statusCode());
  assertNull(rc.failure());
  rc.response().setStatusCode(rc.statusCode()).setStatusMessage("Chipmunks").end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo/bar", 557, "Chipmunks");
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testFailCalled2() throws Exception {
 Router subRouter = Router.router(vertx);
 router.mountSubRouter("/subpath", subRouter);
 subRouter.route("/foo/*").handler(rc -> rc.fail(557));
 router.route("/subpath/*").failureHandler(rc -> {
  assertEquals(557, rc.statusCode());
  assertNull(rc.failure());
  rc.response().setStatusCode(rc.statusCode()).setStatusMessage("Chipmunks").end();
 });
 testRequest(HttpMethod.GET, "/subpath/foo/bar", 557, "Chipmunks");
}

相关文章