本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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();
});
});
}
示例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();
}
示例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());
}
});
}
示例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);
}
示例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);
}
示例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);
}
});
});
}
示例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);
}
});
});
}
示例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);
}
示例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()));
}
示例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());
}));
}
示例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();
});
}
示例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;
}