本文整理了Java中io.vertx.ext.web.Router.route
方法的一些代码示例,展示了Router.route
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.route
方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:route
[英]Add a route with no matching criteria, i.e. it matches all requests or failures.
[中]添加没有匹配条件的路由,即它匹配所有请求或失败。
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(routingContext -> {
routingContext.response().putHeader("content-type", "text/html").end("Hello World!");
});
vertx.createHttpServer().requestHandler(router).listen(8080);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() {
Router router = Router.router(vertx);
// Serve the static pages
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router).listen(8080);
System.out.println("Server is started");
}
代码示例来源: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 testFailureUsingInvalidCharsInStatus() throws Exception {
String path = "/blah";
router.route(path).handler(rc -> rc.response().setStatusMessage("Hello\nWorld!").end());
testRequest(HttpMethod.GET, path, 500, "Internal Server Error");
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().blockingHandler(routingContext -> {
// Blocking handlers are allowed to block the calling thread
// So let's simulate a blocking action or long running operation
try {
Thread.sleep(5000);
} catch (Exception ignore) {
}
// Now call the next handler
routingContext.next();
}, false);
router.route().handler(routingContext -> {
routingContext.response().putHeader("content-type", "text/html").end("Hello World!");
});
vertx.createHttpServer().requestHandler(router).listen(8080);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
// Serve the static pages
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router).listen(configuration.httpPort());
}
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testPathParamsAreFulfilled() throws Exception {
router.route("/blah/:abc/quux/:def/eep/:ghi").handler(rc -> {
Map<String, String> params = rc.pathParams();
rc.response().setStatusMessage(params.get("abc") + params.get("def") + params.get("ghi")).end();
});
testPattern("/blah/tim/quux/julien/eep/nick", "timjuliennick");
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(routingContext -> {
Session session = routingContext.session();
Integer cnt = session.get("hitcount");
cnt = (cnt == null ? 0 : cnt) + 1;
session.put("hitcount", cnt);
routingContext.response().putHeader("content-type", "text/html")
.end("<html><body><h1>Hitcount: " + cnt + "</h1></body></html>");
});
vertx.createHttpServer().requestHandler(router).listen(8080);
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() {
setUpInitialData();
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/products/:productID").handler(this::handleGetProduct);
router.put("/products/:productID").handler(this::handleAddProduct);
router.get("/products").handler(this::handleListProducts);
vertx.createHttpServer().requestHandler(router).listen(8080);
}
代码示例来源: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-examples
router.route().handler(CookieHandler.create());
router.route().handler(BodyHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(UserSessionHandler.create(authProvider));
router.route("/private/*").handler(RedirectAuthHandler.create(authProvider, "/loginpage.html"));
router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"));
router.route("/loginhandler").handler(FormLoginHandler.create(authProvider));
router.route("/logout").handler(context -> {
context.clearUser();
context.response().putHeader("location", "/").setStatusCode(302).end();
});
router.route().handler(StaticHandler.create());
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() {
Router router = Router.router(vertx);
// Serve the dynamic pages
router.route("/dynamic/*")
.handler(ctx -> {
// put the context into the template render context
ctx.put("context", ctx);
ctx.next();
})
.handler(TemplateHandler.create(MVELTemplateEngine.create(vertx)));
// Serve the static pages
router.route().handler(StaticHandler.create());
vertx.createHttpServer().requestHandler(router).listen(8080);
}
代码示例来源: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-examples
router.route().handler(BodyHandler.create());
router.route("/").handler(routingContext -> {
routingContext.response().putHeader("content-type", "text/html").end(
"<form action=\"/form\" method=\"post\">\n" +
" <div>\n" +
router.post("/form").handler(ctx -> {
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
ctx.response().end("Hello " + ctx.request().getParam("name") + "!");
});
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
final Router router = Router.router(vertx);
// Populate context with data
router.route().handler(ctx -> {
ctx.put("title", "Vert.x Web Example Using Rocker");
ctx.put("name", "Rocker");
ctx.next();
});
// Render a custom template.
// Note: you need a compile-time generator for Rocker to work properly
// See the pom.xml for an example
router.route().handler(TemplateHandler.create(RockerTemplateEngine.create()));
vertx.createHttpServer().requestHandler(router).listen(8080);
}
}
代码示例来源: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-examples
router.route("/api/*").handler(JWTAuthHandler.create(jwt, "/api/newToken"));
router.get("/api/newToken").handler(ctx -> {
ctx.response().putHeader("Content-Type", "text/plain");
ctx.response().end(jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(60)));
});
router.get("/api/protected").handler(ctx -> {
ctx.response().putHeader("Content-Type", "text/plain");
ctx.response().end("a secret you should keep for yourself...");
});
router.route().handler(StaticHandler.create());
代码示例来源:origin: vert-x3/vertx-examples
@Validate
public void start() throws Exception {
setUpInitialData();
TcclSwitch.executeWithTCCLSwitch(() -> {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/products/:productID").handler(this::handleGetProduct);
router.put("/products/:productID").handler(this::handleAddProduct);
router.get("/products").handler(this::handleListProducts);
router.get("/assets/*").handler(StaticHandler.create("assets", this.getClass().getClassLoader()));
LOGGER.info("Creating HTTP server for vert.x web application");
HttpServer server = vertx.createHttpServer();
server.requestHandler(router).listen(8081);
});
}
代码示例来源: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-examples
router.route().handler(CookieHandler.create());
router.route().handler(BodyHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(UserSessionHandler.create(authProvider));
router.route("/private/*").handler(RedirectAuthHandler.create(authProvider, "/loginpage.html"));
router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"));
router.route("/loginhandler").handler(FormLoginHandler.create(authProvider));
router.route("/logout").handler(context -> {
context.clearUser();
context.response().putHeader("location", "/").setStatusCode(302).end();
});
router.route().handler(StaticHandler.create());
内容来源于网络,如有侵权,请联系作者删除!