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

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

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

Route.last介绍

[英]Specify this is the last route for the router.
[中]指定这是路由器的最后一条路由。

代码示例

代码示例来源:origin: xenv/gushici

@Override
public void start(Future<Void> startFuture) {
  Router router = Router.router(vertx);
  router.route().handler(BodyHandler.create());
  router.get("/*").handler(this::log); // 全局日志处理,会执行 next() 到下一个
  router.get("/").handler(this::handleRoot); // 首页
  router.get("/favicon.ico").handler(c -> c.fail(404)); // 针对浏览器返回404
  router.get("/log").handler(this::showLog); // 显示日志
  router.routeWithRegex("/([a-z0-9/]*)\\.?(txt|json|png|svg|)")
    .handler(this::handleGushici); // 核心API调用
  router.route().last().handler(c -> c.fail(404)) // 其他返回404
    .failureHandler(this::returnError); // 对上面所有的错误进行处理
  vertx
    .createHttpServer()
    .requestHandler(router::accept)
    .listen(
      config().getInteger("http.port", 8080),
      result -> {
        if (result.succeeded()) {
          startFuture.complete();
        } else {
          startFuture.fail(result.cause());
        }
      }
    );
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Specify this is the last route for the router.
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.Route last() { 
 delegate.last();
 return this;
}

代码示例来源:origin: gentics/mesh

@Override
public InternalEndpointRoute last() {
  route.last();
  return this;
}

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

/**
 * Specify this is the last route for the router.
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.Route last() { 
 delegate.last();
 return this;
}

代码示例来源:origin: wang007/vertx-start

@Override
public Route last() {
  return delegate.last();
}

代码示例来源:origin: zandero/rest.vertx

private static void addLastHandler(Router router, String path, Handler<RoutingContext> notFoundHandler) {
  if (path == null) {
    router.route().last().handler(notFoundHandler);
  } else {
    router.routeWithRegex(path).last().handler(notFoundHandler);
  }
}

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

@Test
public void testLast() throws Exception {
 String path = "/blah";
 Route route = router.route(path);
 router.route(path).handler(rc -> {
  rc.response().setChunked(true);
  rc.response().write("oranges");
  rc.next();
 });
 router.route(path).handler(rc -> {
  rc.response().write("bananas");
  rc.next();
 });
 route.last();
 route.handler(rc -> {
  rc.response().write("apples");
  rc.response().end();
 });
 testRequest(HttpMethod.GET, path, 200, "OK", "orangesbananasapples");
}

代码示例来源:origin: dmart28/gcplot

public void init() {
  LOG.info("Starting Vert.x Dispatcher at [{}:{}]", host, port);
  httpServer = vertx.createHttpServer();
  router = Router.router(vertx);
  router.exceptionHandler(e -> LOG.error(e.getMessage(), e));
  router.route().order(0).handler(bodyHandler.setBodyLimit(maxUploadSize));
  router.route().last().handler(f -> {
    if (!f.response().ended() && f.response().bytesWritten() == 0) {
      f.response().end(ErrorMessages.buildJson(ErrorMessages.NOT_FOUND));
    }
  });
  CountDownLatch await = new CountDownLatch(1);
  httpServer.requestHandler(router::accept).listen(port, host, r -> await.countDown());
  try {
    if (!await.await(30, TimeUnit.SECONDS)) {
      throw new RuntimeException("Failed to start Vert.x server!");
    }
  } catch (Throwable t) {
    throw Exceptions.runtime(t);
  }
  isOpen = true;
}

代码示例来源:origin: gentics/mesh

public RootRouter(Vertx vertx, RouterStorage storage) {
  this.storage = storage;
  this.vertx = vertx;
  this.router = Router.router(vertx);
  // Root handlersA
  router.route().handler(LoggerHandler.create());
  // TODO add a dedicated error for api router that informs about
  // APPLICATION_JSON requirements. This may not be true for other
  // routes (eg. custom
  // routes)
  router.route().last().handler(DefaultNotFoundHandler.create());
  router.route().failureHandler(FailureHandler.create());
  this.apiRouter = new APIRouter(this);
  this.customRouter = new CustomRouter(this);
}

代码示例来源:origin: io.vertx/vertx-web

@Test
public void testLast() throws Exception {
 String path = "/blah";
 Route route = router.route(path);
 router.route(path).handler(rc -> {
  rc.response().setChunked(true);
  rc.response().write("oranges");
  rc.next();
 });
 router.route(path).handler(rc -> {
  rc.response().write("bananas");
  rc.next();
 });
 route.last();
 route.handler(rc -> {
  rc.response().write("apples");
  rc.response().end();
 });
 testRequest(HttpMethod.GET, path, 200, "OK", "orangesbananasapples");
}

相关文章