本文整理了Java中io.vertx.ext.web.Router.clear
方法的一些代码示例,展示了Router.clear
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.clear
方法的具体详情如下:
包路径:io.vertx.ext.web.Router
类名称:Router
方法名:clear
[英]Remove all the routes from this router
[中]删除此路由器的所有路由
代码示例来源:origin: vert-x3/vertx-web
@Test(expected = IllegalArgumentException.class)
public void testAccessToRootPath() throws Exception {
router.clear();
File file = File.createTempFile("vertx", "tmp");
file.deleteOnExit();
// remap stat to the temp dir
stat = StaticHandler.create().setWebRoot(file.getParent());
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testServerRelativeToPath() throws Exception {
router.clear();
router.route("/somedir/*").handler(stat);
testRequest(HttpMethod.GET, "/somedir/otherpage.html", 200, "OK", "<html><body>Other page</body></html>");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testFileUploadOtherUploadsDir() throws Exception {
router.clear();
File dir = tempUploads.newFolder();
router.route().handler(BodyHandler.create().setUploadsDirectory(dir.getPath()));
testFileUpload(dir.getPath(), 5000);
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testBodyHandlerCreateTrueWorks() throws Exception
{
router.clear();
router.route().handler(BodyHandler.create(true));
testFormURLEncoded();
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testServeFilesFromFilesystemWebRootConstructor() throws Exception {
stat = StaticHandler.create("src/test/filesystemwebroot");
router.clear();
router.route().handler(stat);
testRequest(HttpMethod.GET, "/fspage.html", 200, "OK", "<html><body>File system page</body></html>");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testGetDirectoryOnSubdirMount() throws Exception {
router.clear();
router.route("/c/*").handler(stat);
testRequest(HttpMethod.GET, "/c/a/b/", req -> req.putHeader("Accept", "text/html"), null, 200, "OK", "<html>\n" +
"<body>\n" +
"<h1>Custom Index of /c/a/b/</h1>\n" +
"<a href=\"/c/a/\">..</a>\n" +
"<ul id=\"files\"><li><a href=\"/c/a/b/test.txt\" title=\"test.txt\">test.txt</a></li></ul>\n" +
"</body>\n" +
"</html>");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testGetDirectoryOnPrefixMount() throws Exception {
router.clear();
router.route("/c*").handler(stat);
// even though the prefix is matched only the prefix is ignored from the file system match
// webroot/annot/a/b will not be found
testRequest(HttpMethod.GET, "/cannot/a/b/", req -> req.putHeader("Accept", "text/html"), null, 404, "Not Found", null);
}
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testFormMultipartFormDataMergeAttributes() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setMergeFormAttributes(true));
testFormMultipartFormData(true);
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testServerRelativeToPathAndMountPoint() throws Exception {
router.clear();
Router subRouter = Router.router(vertx);
subRouter.route("/somedir/*").handler(stat);
router.mountSubRouter("/mymount/", subRouter);
testRequest(HttpMethod.GET, "/mymount/somedir/otherpage.html", 200, "OK", "<html><body>Other page</body></html>");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testFormMultipartFormDataNoMergeAttributes() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setMergeFormAttributes(false));
testFormMultipartFormData(false);
}
代码示例来源:origin: vert-x3/vertx-web
private void testRouteNoPathWithMethod(HttpMethod meth) throws Exception {
router.clear();
router.route().method(meth).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end());
testNoPath(meth);
for (HttpMethod m : METHODS) {
if (m != meth) {
testRequest(m, "/whatever", 404, "Not Found");
}
}
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testBodyLimitWithHandleFileUploadsFalse() throws Exception
{
router.clear();
BodyHandler bodyHandler = BodyHandler.create(false).setBodyLimit(2048);
router.route().handler(bodyHandler);
Buffer fileData = TestUtils.randomBuffer(4096);
router.route().handler(rc -> {
rc.response().end();
});
sendFileUploadRequest(fileData, 413, "Request Entity Too Large");
}
代码示例来源:origin: vert-x3/vertx-web
private void testFileUploadFileRemoval(Handler<RoutingContext> requestHandler, boolean deletedUploadedFilesOnEnd,
int statusCode, String statusMessage) throws Exception {
String uploadsDirectory = tempUploads.newFolder().getPath();
router.clear();
router.route().handler(BodyHandler.create()
.setDeleteUploadedFilesOnEnd(deletedUploadedFilesOnEnd)
.setUploadsDirectory(uploadsDirectory));
router.route().handler(requestHandler);
sendFileUploadRequest(TestUtils.randomBuffer(50), statusCode, statusMessage);
int uploadedFilesAfterEnd = deletedUploadedFilesOnEnd ? 0 : 1;
assertWaitUntil(() -> uploadedFilesAfterEnd == vertx.fileSystem().readDirBlocking(uploadsDirectory).size());
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testFileUploadTooBig() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setBodyLimit(20000));
Buffer fileData = TestUtils.randomBuffer(50000);
router.route().handler(rc -> fail("Should not be called"));
sendFileUploadRequest(fileData, 413, "Request Entity Too Large");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testFileUploadTooBig2() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setBodyLimit(20000));
Buffer fileData = TestUtils.randomBuffer(50000);
router.route().handler(rc -> fail("Should not be called"));
sendFileUploadRequest(fileData, 413, "Request Entity Too Large");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testNoUploadDirFormURLEncoded() throws Exception
{
String dirName = getNotCreatedTemporaryFolderName();
router.clear();
router.route().handler(BodyHandler.create(false).setUploadsDirectory(dirName));
testFormURLEncoded();
assertFalse("Upload directory must not be created.", vertx.fileSystem().existsBlocking(dirName));
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testNoUploadDirMultiPartFormData() throws Exception
{
String dirName = getNotCreatedTemporaryFolderName();
router.clear();
router.route().handler(BodyHandler.create(false).setUploadsDirectory(dirName));
Buffer fileData = TestUtils.randomBuffer(50);
router.route().handler(rc -> {
rc.response().end();
assertFalse("Upload directory must not be created.", vertx.fileSystem().existsBlocking(dirName));
});
sendFileUploadRequest(fileData, 200, "OK");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testSendRequiresAuthorityHasAuthority() throws Exception {
sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")));
router.clear();
router.route().handler(CookieHandler.create());
SessionStore store = LocalSessionStore.create(vertx);
router.route().handler(SessionHandler.create(store));
JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig));
addLoginHandler(router, authProvider);
router.route("/eventbus/*").handler(sockJSHandler);
testSend("foo");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testBodyTooBig() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setBodyLimit(5000));
Buffer buff = TestUtils.randomBuffer(10000);
router.route().handler(rc -> fail("Should not be called"));
testRequest(HttpMethod.POST, "/", req -> {
req.setChunked(true);
req.write(buff);
}, 413, "Request Entity Too Large", null);
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testBodyTooBig2() throws Exception {
router.clear();
router.route().handler(BodyHandler.create().setBodyLimit(500));
Buffer buff = TestUtils.randomBuffer(1000);
router.route().handler(rc -> fail("Should not be called"));
testRequest(HttpMethod.POST, "/", req -> {
req.setChunked(true);
req.write(buff);
}, 413, "Request Entity Too Large", null);
}
内容来源于网络,如有侵权,请联系作者删除!