@Test public void testDirectoryListingHtml() throws Exception { stat.setDirectoryListing(true); testDirectoryListingHtmlCustomTemplate("META-INF/vertx/web/vertx-web-directory.html"); }
@Test public void testDirectoryListingText() throws Exception { stat.setDirectoryListing(true); Set<String> expected = new HashSet<>(Arrays.asList(".hidden.html", "a", "foo.json", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", null, resp -> { resp.bodyHandler(buff -> { String sBuff = buff.toString(); String[] elems = sBuff.split("\n"); assertEquals(expected.size(), elems.length); for (String elem : elems) { assertTrue(expected.contains(elem)); } }); }, 200, "OK", null); }
@Test public void testCustomDirectoryListingHtml() throws Exception { stat.setDirectoryListing(true); String dirTemplate = "custom_dir_template.html"; stat.setDirectoryTemplate(dirTemplate); testDirectoryListingHtmlCustomTemplate(dirTemplate); }
/** * Set whether directory listing is enabled * @param directoryListing true if enabled * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.StaticHandler setDirectoryListing(boolean directoryListing) { delegate.setDirectoryListing(directoryListing); return this; }
/** * Set whether directory listing is enabled * @param directoryListing true if enabled * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.StaticHandler setDirectoryListing(boolean directoryListing) { delegate.setDirectoryListing(directoryListing); return this; }
@Test public void testDirectoryListingTextNoHidden() throws Exception { stat.setDirectoryListing(true); stat.setIncludeHidden(false); Set<String> expected = new HashSet<>(Arrays.asList("foo.json", "a", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", null, resp -> { resp.bodyHandler(buff -> { assertEquals("text/plain", resp.headers().get("content-type")); String sBuff = buff.toString(); String[] elems = sBuff.split("\n"); assertEquals(expected.size(), elems.length); for (String elem: elems) { assertTrue(expected.contains(elem)); } }); }, 200, "OK", null); }
@Override public void setUp() throws Exception { super.setUp(); stat = StaticHandler.create("webroot").setDirectoryListing(true).setDirectoryTemplate("custom_dir_template.html"); router.route().handler(stat); }
@Test public void testDirectoryListingJson() throws Exception { stat.setDirectoryListing(true); Set<String> expected = new HashSet<>(Arrays.asList(".hidden.html", "foo.json", "index.html", "otherpage.html", "a", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", req -> { req.putHeader("accept", "application/json"); }, resp -> { resp.bodyHandler(buff -> { assertEquals("application/json", resp.headers().get("content-type")); String sBuff = buff.toString(); JsonArray arr = new JsonArray(sBuff); assertEquals(expected.size(), arr.size()); for (Object elem: arr) { assertTrue(expected.contains(elem)); } testComplete(); }); }, 200, "OK", null); await(); }
private void testDirectoryListingHtmlCustomTemplate(String dirTemplateFile) throws Exception { stat.setDirectoryListing(true); String directoryTemplate = Utils.readResourceToBuffer(dirTemplateFile).toString(); String parentLink = "<a href=\"/\">..</a>"; String files = "<ul id=\"files\"><li><a href=\"/somedir2/foo2.json\" title=\"foo2.json\">foo2.json</a></li>" + "<li><a href=\"/somedir2/somepage.html\" title=\"somepage.html\">somepage.html</a></li>" + "<li><a href=\"/somedir2/somepage2.html\" title=\"somepage2.html\">somepage2.html</a></li></ul>"; String expected = directoryTemplate.replace("{directory}", "/somedir2/").replace("{parent}", parentLink).replace("{files}", files); testRequest(HttpMethod.GET, "/somedir2", req -> req.putHeader("accept", "text/html"), resp -> resp.bodyHandler(buff -> { assertEquals("text/html", resp.headers().get("content-type")); String sBuff = buff.toString(); assertEquals(expected, sBuff); testComplete(); }), 200, "OK", null); await(); }
@Test public void testDirectoryListingJsonNoHidden() throws Exception { stat.setDirectoryListing(true); stat.setIncludeHidden(false); Set<String> expected = new HashSet<>(Arrays.asList("foo.json", "a", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", req -> { req.putHeader("accept", "application/json"); }, resp -> { resp.bodyHandler(buff -> { assertEquals("application/json", resp.headers().get("content-type")); String sBuff = buff.toString(); JsonArray arr = new JsonArray(sBuff); assertEquals(expected.size(), arr.size()); for (Object elem: arr) { assertTrue(expected.contains(elem)); } testComplete(); }); }, 200, "OK", null); await(); }
@Test public void testDirectoryListingHtml() throws Exception { stat.setDirectoryListing(true); testDirectoryListingHtmlCustomTemplate("META-INF/vertx/web/vertx-web-directory.html"); }
public void addStaticHandler() { StaticHandler staticHandler = StaticHandler.create("elastichead"); staticHandler.setDirectoryListing(false); staticHandler.setCachingEnabled(false); staticHandler.setIndexPage("index.html"); route("/*").method(GET).handler(staticHandler); }
@Test public void testDirectoryListingText() throws Exception { stat.setDirectoryListing(true); Set<String> expected = new HashSet<>(Arrays.asList(".hidden.html", "a", "foo.json", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", null, resp -> { resp.bodyHandler(buff -> { String sBuff = buff.toString(); String[] elems = sBuff.split("\n"); assertEquals(expected.size(), elems.length); for (String elem : elems) { assertTrue(expected.contains(elem)); } }); }, 200, "OK", null); }
@Test public void testCustomDirectoryListingHtml() throws Exception { stat.setDirectoryListing(true); String dirTemplate = "custom_dir_template.html"; stat.setDirectoryTemplate(dirTemplate); testDirectoryListingHtmlCustomTemplate(dirTemplate); }
@Test public void testDirectoryListingTextNoHidden() throws Exception { stat.setDirectoryListing(true); stat.setIncludeHidden(false); Set<String> expected = new HashSet<>(Arrays.asList("foo.json", "a", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", null, resp -> { resp.bodyHandler(buff -> { assertEquals("text/plain", resp.headers().get("content-type")); String sBuff = buff.toString(); String[] elems = sBuff.split("\n"); assertEquals(expected.size(), elems.length); for (String elem: elems) { assertTrue(expected.contains(elem)); } }); }, 200, "OK", null); }
@Override public void setUp() throws Exception { super.setUp(); stat = StaticHandler.create("webroot").setDirectoryListing(true).setDirectoryTemplate("custom_dir_template.html"); router.route().handler(stat); }
@Test public void testDirectoryListingJson() throws Exception { stat.setDirectoryListing(true); Set<String> expected = new HashSet<>(Arrays.asList(".hidden.html", "foo.json", "index.html", "otherpage.html", "a", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", req -> { req.putHeader("accept", "application/json"); }, resp -> { resp.bodyHandler(buff -> { assertEquals("application/json", resp.headers().get("content-type")); String sBuff = buff.toString(); JsonArray arr = new JsonArray(sBuff); assertEquals(expected.size(), arr.size()); for (Object elem: arr) { assertTrue(expected.contains(elem)); } testComplete(); }); }, 200, "OK", null); await(); }
private void testDirectoryListingHtmlCustomTemplate(String dirTemplateFile) throws Exception { stat.setDirectoryListing(true); String directoryTemplate = Utils.readResourceToBuffer(dirTemplateFile).toString(); String parentLink = "<a href=\"/\">..</a>"; String files = "<ul id=\"files\"><li><a href=\"/somedir2/foo2.json\" title=\"foo2.json\">foo2.json</a></li>" + "<li><a href=\"/somedir2/somepage.html\" title=\"somepage.html\">somepage.html</a></li>" + "<li><a href=\"/somedir2/somepage2.html\" title=\"somepage2.html\">somepage2.html</a></li></ul>"; String expected = directoryTemplate.replace("{directory}", "/somedir2/").replace("{parent}", parentLink).replace("{files}", files); testRequest(HttpMethod.GET, "/somedir2", req -> req.putHeader("accept", "text/html"), resp -> resp.bodyHandler(buff -> { assertEquals("text/html", resp.headers().get("content-type")); String sBuff = buff.toString(); assertEquals(expected, sBuff); testComplete(); }), 200, "OK", null); await(); }
@Test public void testDirectoryListingJsonNoHidden() throws Exception { stat.setDirectoryListing(true); stat.setIncludeHidden(false); Set<String> expected = new HashSet<>(Arrays.asList("foo.json", "a", "index.html", "otherpage.html", "somedir", "somedir2", "somedir3", "testCompressionSuffix.html", "file with spaces.html")); testRequest(HttpMethod.GET, "/", req -> { req.putHeader("accept", "application/json"); }, resp -> { resp.bodyHandler(buff -> { assertEquals("application/json", resp.headers().get("content-type")); String sBuff = buff.toString(); JsonArray arr = new JsonArray(sBuff); assertEquals(expected.size(), arr.size()); for (Object elem: arr) { assertTrue(expected.contains(elem)); } testComplete(); }); }, 200, "OK", null); await(); }
@Override public void registerEndPoints() { secureAll(); InternalEndpointRoute queryEndpoint = createRoute(); queryEndpoint.method(POST); queryEndpoint.exampleRequest(graphqlExamples.createQueryRequest()); queryEndpoint.exampleResponse(OK, graphqlExamples.createResponse(), "Basic GraphQL response."); queryEndpoint.description("Endpoint which accepts GraphQL queries."); queryEndpoint.path("/"); queryEndpoint.blockingHandler(rc -> { GraphQLContext gc = new GraphQLContextImpl(rc); String body = gc.getBodyAsString(); queryHandler.handleQuery(gc, body); }, false); StaticHandler staticHandler = StaticHandler.create("graphiql"); staticHandler.setDirectoryListing(false); staticHandler.setCachingEnabled(false); staticHandler.setIndexPage("index.html"); // Redirect handler route("/browser").method(GET).handler(rc -> { if (rc.request().path().endsWith("/browser")) { rc.response().setStatusCode(302); rc.response().headers().set("Location", rc.request().path() + "/"); rc.response().end(); } else { rc.next(); } }); route("/browser/*").method(GET).handler(staticHandler); }