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

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

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

Route.failureHandler介绍

[英]Append a failure handler to the route failure handlers list. The router routes failures to failurehandlers depending on whether the various criteria such as method, path, etc match. When method, path, etc are the same for different routes, You should add multiple failure handlers to the same route object rather than creating two different routes objects with one failure handler for route
[中]将故障处理程序附加到路由故障处理程序列表。路由器根据方法、路径等各种条件是否匹配,将故障路由到FailureHandler。当不同路由的方法、路径等相同时,应向同一路由对象添加多个故障处理程序,而不是为路由创建两个不同的路由对象,并使用一个故障处理程序

代码示例

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

})).failureHandler(routingContext -> {
 SQLConnection conn = routingContext.get("conn");
 if (conn != null) {

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

.failureHandler((routingContext) -> {
 Throwable failure = routingContext.failure();
 if (failure instanceof ValidationException) {

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

@Override
public Router mountSubRouter(String mountPoint, Router subRouter) {
 if (mountPoint.endsWith("*")) {
  throw new IllegalArgumentException("Don't include * when mounting subrouter");
 }
 if (mountPoint.contains(":")) {
  throw new IllegalArgumentException("Can't use patterns in subrouter mounts");
 }
 route(mountPoint + "*").handler(subRouter::handleContext).failureHandler(subRouter::handleFailure);
 return this;
}

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

@Test
public void testFailureinHandlingFailure() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> {
  throw new RuntimeException("ouch!");
 }).failureHandler(frc -> {
  throw new RuntimeException("super ouch!");
 });
 testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}

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

@Override
public void setUp() throws Exception {
 super.setUp();
 router.route().failureHandler(ErrorHandler.create());
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void init(Router router) {
 router.routeWithRegex(PATTERN_ANY).handler(CookieHandler.create());
 router.routeWithRegex(PATTERN_ANY).handler(createBodyHandler());
 router.routeWithRegex(PATTERN_ANY).failureHandler(this::onFailure).handler(this::onRequest);
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void init(Router router) {
 router.route().handler(CookieHandler.create());
 router.route().handler(createBodyHandler());
 router.route().failureHandler(this::failureHandler).handler(this::onRequest);
}

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

@Test
public void testFailureinHandlingFailureWithInvalidStatusMessage() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> {
  throw new RuntimeException("ouch!");
 }).failureHandler(frc -> frc.response().setStatusMessage("Hello\nWorld").end());
 testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}

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

@Test
public void testFailureHandler1() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> {
  throw new RuntimeException("ouch!");
 }).failureHandler(frc -> frc.response().setStatusCode(555).setStatusMessage("oh dear").end());
 testRequest(HttpMethod.GET, path, 555, "oh dear");
}

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

@Test
public void testFailureHandlerNoMatch() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> {
  throw new RuntimeException("ouch!");
 });
 router.route("/other").failureHandler(frc -> frc.response().setStatusCode(555).setStatusMessage("oh dear").end());
 // Default failure response
 testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}

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

@Test
public void testFailureHandler2() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> {
  throw new RuntimeException("ouch!");
 });
 router.route("/bl*").failureHandler(frc -> frc.response().setStatusCode(555).setStatusMessage("oh dear").end());
 testRequest(HttpMethod.GET, path, 555, "oh dear");
}

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

@Test
public void testSubRouteRegex() throws Exception {
 Router subRouter = Router.router(vertx);
 router.routeWithRegex("/foo/.*").handler(subRouter::handleContext).failureHandler(subRouter::handleFailure);
 subRouter.route("/blah").handler(rc -> rc.response().setStatusMessage("sausages").end());
 testRequest(HttpMethod.GET, "/foo/blah", 500, "Internal Server Error");
}

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

@Test
public void testFailureWithThrowable() throws Exception {
 String path = "/blah";
 Throwable failure = new Throwable();
 router.route(path).handler(rc -> rc.fail(failure)).failureHandler(frc -> {
  assertEquals(-1, frc.statusCode());
  assertSame(failure, frc.failure());
  frc.response().setStatusCode(500).setStatusMessage("Internal Server Error").end();
 });
 testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}

代码示例来源: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 testFailureHandler1CallFail() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> rc.fail(400)).failureHandler(frc -> {
  assertEquals(400, frc.statusCode());
  frc.response().setStatusCode(400).setStatusMessage("oh dear").end();
 });
 testRequest(HttpMethod.GET, path, 400, "oh dear");
}

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

@Test
public void testChangeOrderAfterActive2() throws Exception {
 String path = "/blah";
 Route route = router.route(path).failureHandler(rc -> {
  rc.response().write("apples");
  rc.next();
 });
 try {
  route.order(23);
  fail();
 } catch (IllegalStateException e) {
  // OK
 }
}

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

@Test
public void testFailureHandler2CallFail() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> rc.fail(400));
 router.route("/bl*").failureHandler(frc -> {
  assertEquals(400, frc.statusCode());
  frc.response().setStatusCode(400).setStatusMessage("oh dear").end();
 });
 testRequest(HttpMethod.GET, path, 400, "oh dear");
}

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

@Test
public void testFailureWithNullThrowable() throws Exception {
 String path = "/blah";
 router.route(path).handler(rc -> rc.fail(null)).failureHandler(frc -> {
  assertEquals(-1, frc.statusCode());
  assertTrue(frc.failure() instanceof NullPointerException);
  frc.response().setStatusCode(500).setStatusMessage("Internal Server Error").end();
 });
 testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}

代码示例来源: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");
}

相关文章