當前位置: 首頁>>代碼示例>>Java>>正文


Java Router.router方法代碼示例

本文整理匯總了Java中io.vertx.ext.web.Router.router方法的典型用法代碼示例。如果您正苦於以下問題:Java Router.router方法的具體用法?Java Router.router怎麽用?Java Router.router使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.ext.web.Router的用法示例。


在下文中一共展示了Router.router方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
	Router router = Router.router(vertx);
	int serverPort = Config.getIntValue("serverPort");
	
	router.route().handler(BodyHandler.create().setUploadsDirectory("files"));
	router.route().handler(CookieHandler.create());
	router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
	Routing.route(router, "com.planb.restful");
	
	router.route().handler(StaticHandler.create());
	new Parser().start();
	
	Log.info("Server Started At : " + serverPort);
	vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
 
開發者ID:JoMingyu,項目名稱:Bobsim-Server,代碼行數:17,代碼來源:MainVerticle.java

示例2: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
	Router router = Router.router(vertx);
	int serverPort = Config.getIntValue("serverPort");
	
	router.route().handler(BodyHandler.create().setUploadsDirectory("files"));
	router.route().handler(CookieHandler.create());
	router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
	router.route().handler(CORSHandler.create());
	router.route().handler(LogHandler.create());
	Routing.route(router, "com.planb.restful");
	
	router.route().handler(StaticHandler.create());
	
	Log.info("Server Started At : " + serverPort);
	vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
 
開發者ID:JoMingyu,項目名稱:Server-Quickstart-Vert.x,代碼行數:18,代碼來源:MainVerticle.java

示例3: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Before
public void start(TestContext context) {

	super.before(context);


	// 1. register handler to initialize User
	Router router = Router.router(vertx);
	router.route().handler(getUserHandler());

	// 2. REST with @RolesAllowed annotations
	TestAuthorizationRest testRest = new TestAuthorizationRest();
	RestRouter.register(router, testRest);

	vertx.createHttpServer()
		.requestHandler(router::accept)
		.listen(PORT);
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:19,代碼來源:RouteAuthorizationTest.java

示例4: callPresentContext

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Test
public void callPresentContext(TestContext context) {

	Router router = Router.router(vertx);
	router.route().handler(pushContextHandler());
	RestRouter.register(router, TestDefaultValueRest.class);

	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);

	// call and check response
	final Async async = context.async();


	client.getNow("/default/context", response -> {

		context.assertEquals(200, response.statusCode());

		response.handler(body -> {
			context.assertEquals("Context is test user", body.toString());
			async.complete();
		});
	});
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:26,代碼來源:DefaultValueTest.java

示例5: setUp

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

    vertx = Vertx.vertx();
    JsonObject config = vertx.getOrCreateContext().config();
    Router router = Router.router(vertx);
    configuration = new VertxConfiguration(config);
    configuration.put(SSL_CONFIGURATION_KEY, FALSE);
    configuration.put(SSL_JKS_PATH, TEST_JKS_PATH);
    configuration.put(SSL_JKS_SECRET, TEST_JKS_SECRET);
    configuration.put(HTTPS_PORT, DEFAULT_HTTPS_PORT);
    options = new HttpServerOptions();
    context = VertxContext.VertxContextBuilder.vertx(vertx)
            .router(router)
            .serverConfiguration(configuration)
            .vertxServiceDiscovery(new VertxServiceDiscovery(vertx)).build();
}
 
開發者ID:GwtDomino,項目名稱:domino,代碼行數:18,代碼來源:JksServerConfiguratorTest.java

示例6: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {

  String wikiDbQueue = config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue");
  dbService = WikiDatabaseService.createProxy(vertx, wikiDbQueue);

  // tag::webClient[]
  webClient = WebClient.create(vertx, new WebClientOptions()
    .setSsl(true)
    .setUserAgent("vert-x3"));
  // end::webClient[]

  HttpServer server = vertx.createHttpServer();

  Router router = Router.router(vertx);
  router.get("/").handler(this::indexHandler);
  router.get("/backup").handler(this::backupHandler);
  router.get("/wiki/:page").handler(this::pageRenderingHandler);
  router.post().handler(BodyHandler.create());
  router.post("/save").handler(this::pageUpdateHandler);
  router.post("/create").handler(this::pageCreateHandler);
  router.post("/delete").handler(this::pageDeletionHandler);

  int portNumber = config().getInteger(CONFIG_HTTP_SERVER_PORT, 8080);
  server
    .requestHandler(router::accept)
    .listen(portNumber, ar -> {
      if (ar.succeeded()) {
        LOGGER.info("HTTP server running on port " + portNumber);
        startFuture.complete();
      } else {
        LOGGER.error("Could not start a HTTP server", ar.cause());
        startFuture.fail(ar.cause());
      }
    });
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:37,代碼來源:HttpServerVerticle.java

示例7: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get("/balance/:account").handler(this::getBalance);

    vertx.createHttpServer()
        .requestHandler(router::accept)
        .listen(9003);
}
 
開發者ID:cescoffier,項目名稱:various-vertx-demos,代碼行數:10,代碼來源:BalanceVerticle.java

示例8: setUp

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void setUp() throws Exception {
    super.setUp();
    this.router = Router.router(this.vertx);
    this.server = this.vertx.createHttpServer(getHttpServerOptions());
    this.client = this.vertx.createHttpClient(getHttpClientOptions());
    final CountDownLatch latch = new CountDownLatch(1);
    this.server.requestHandler(this.router::accept).listen(onSuccess(res -> latch.countDown()));
    awaitLatch(latch);
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:11,代碼來源:WebTestBase.java

示例9: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get("/")
        .handler(rc -> rc.response()
            .end("Bonjour Tourcoing"));

    router.get("/shopping").handler(this::getList);
    router.route().handler(BodyHandler.create());
    router.post("/shopping")
        .handler(this::addToList);
    router.delete("/shopping/:name").handler(this::deleteFromList);

    ServiceDiscovery.create(vertx, discovery -> {
        RedisDataSource.getRedisClient(discovery,
            svc -> svc.getName().equals("redis"),
            ar -> {
                if (ar.failed()) {
                    System.out.println("D'oh !");
                } else {
                    client = ar.result();
                    vertx.createHttpServer()
                        .requestHandler(router::accept)
                        .listen(8080);
                }
            });
    });

}
 
開發者ID:cescoffier,項目名稱:vertx-chtijug-2017,代碼行數:30,代碼來源:ShoppingBackend.java

示例10: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.get("/").handler(rc -> rc.response().end("Hello"));

    router.get("/shopping").handler(this::getList);
    router.route().handler(BodyHandler.create());
    router.post("/shopping").handler(this::addToList);
    router.delete("/shopping/:name").handler(this::removeFromList);

    ServiceDiscovery.create(vertx, discovery -> {
        RedisDataSource.getRedisClient(discovery,
            svc -> svc.getName().equals("redis"),
            ar -> {
                if (ar.failed()) {
                    System.out.println("D'oh !");
                } else {
                    client = ar.result();
                    vertx.createHttpServer()
                        .requestHandler(router::accept)
                        .listen(8080);
                }
            });
    });


}
 
開發者ID:cescoffier,項目名稱:vertx-rhsummit-2017,代碼行數:28,代碼來源:ShoppingListVerticle.java

示例11: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
    Router router = Router.router(vertx);

    router.get("/prices/:name").handler(rc -> {
        String name = rc.pathParam("name");
        Double price = prices.computeIfAbsent(name, k -> (double) random.nextInt(50));
        rc.response().end(new JsonObject().put("name", name).put("price", price).encodePrettily());
    });

    router.route().handler(BodyHandler.create());
    router.post("/prices").handler(rc -> {
        if (slow) {
            vertx.setTimer(5000, l -> computeResponse(rc));
        } else {
            computeResponse(rc);
        }
    });

    router.get("/health").handler(rc -> rc.response().end("OK"));

    router.get("/toggle").handler(rc -> {
        slow = ! slow;
        rc.response().end((slow ? "Slow" : "Normal") + " mode enabled");
    });

    router.get("/assets*").handler(StaticHandler.create());

    vertx.createHttpServer()
        .requestHandler(router::accept)
        .listen(8080);
}
 
開發者ID:cescoffier,項目名稱:vertx-openshift-shopping-hol,代碼行數:33,代碼來源:PricerVerticle.java

示例12: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start(Future<Void> future) throws Exception {
    Router router = Router.router(vertx);
    router.get().handler(rc -> rc.response().end("OK"));
    router.post().handler(BodyHandler.create());
    router.post().handler(this::handle);

    vertx.createHttpServer()
        .requestHandler(router::accept)
        .listen(config().getInteger("port", 8080),
            ar -> future.handle(ar.mapEmpty()));
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:13,代碼來源:CurrencyService.java

示例13: testCircuitBreakerLookupFail

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Test
public void testCircuitBreakerLookupFail(TestContext ctx) throws Exception {
  Async async = ctx.async();
  Router router = Router.router(vertx);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Flow flow = Flow.flow(vertx)
    .withDiscovery(discovery)
    .withBreaker(new CircuitBreakerOptions());
  flow.route(router.get("/foo"), httpFlow -> {
    httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertFailure(v1 -> {
      publishBackend(ctx, v2 -> {
        httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertSuccess(req -> {
          req.send(ctx.asyncAssertSuccess(resp -> {
            ctx.assertEquals(200, resp.statusCode());
            httpFlow.response().end(resp.body());
            async.complete();
          }));
        }));
      });
    }));
  });
  Async listenAsync = ctx.async();
  server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
  listenAsync.awaitSuccess(10000);
  startBackendBlocking(ctx);
  client
    .get(8080, "localhost", "/foo")
    .send(ctx.asyncAssertSuccess(resp -> {
      ctx.assertEquals(200, resp.statusCode());
      ctx.assertEquals("Hello World", resp.bodyAsString());
    }));
}
 
開發者ID:vietj,項目名稱:vertx-service-flow,代碼行數:33,代碼來源:FlowTest.java

示例14: start

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
@Override
public void start() throws Exception {

    JsonObject config = config();
    JsonArray urls = config.getJsonArray(CommonConstants.HE_RSS_URL_LIST_ENV);
    urls.iterator().forEachRemaining(o -> {
        String url = (String) o;
        HEEndpointModel model = new HEEndpointModel();
        String label = stripAndFormatSuffix(url);
        model.setLabel(label);
        model.setUrl(url);
        model.setPollingPeriod(30000);
        model.setActive(false);
        endpoints.put(label, model);
    });

    Router router = Router.router(vertx);

    HealthCheckHandler healthCheckHandler = HealthCheckHandler.create(vertx).register("server-online",
            fut -> fut.complete(online ? Status.OK() : Status.KO()));

    router.get("/api/health/readiness").handler(rc -> rc.response().end(CommonConstants.OK));
    router.get("/api/health/liveness").handler(healthCheckHandler);
    router.get("/api/get/count/:term").handler(this::getIncidentCountsForType);
    router.get("/api/get/count/:term/:id").handler(this::getIncidentCountsForTypeWithId);
    router.get("/api/get/detail/:term/:id").handler(this::getIncidentDetailsById);
    router.get("/api/config/endpoint/all").handler(this::getEndpointStatus);
    router.get("/api/config/endpoint/:label").handler(this::getEndpointStatusById);
    router.get("/*").handler(StaticHandler.create());

    router.post("/api/config/endpoint/:label/:state").handler(this::setEndpointStatusById);

    HttpServer server = vertx.createHttpServer().requestHandler(router::accept)
            .listen(config().getInteger("http.port", 8080), ar -> {
                online = ar.succeeded();
            });
}
 
開發者ID:benemon,項目名稱:he-rss-poll,代碼行數:38,代碼來源:UIServiceVerticle.java

示例15: dependenciesRouter

import io.vertx.ext.web.Router; //導入方法依賴的package包/類
private Router dependenciesRouter() {
  Router router = Router.router(vertx);
  router.get("/dependencies").handler(dependencyResource::findAll);
  return router;
}
 
開發者ID:vert-x3,項目名稱:vertx-starter,代碼行數:6,代碼來源:WebVerticle.java


注:本文中的io.vertx.ext.web.Router.router方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。