Codota Logo
StaticHandler.setWebRoot
Code IndexAdd Codota to your IDE (free)

How to use
setWebRoot
method
in
io.vertx.ext.web.handler.StaticHandler

Best Java code snippets using io.vertx.ext.web.handler.StaticHandler.setWebRoot (Showing top 20 results out of 315)

  • Common ways to obtain StaticHandler
private void myMethod () {
StaticHandler s =
  • Codota IconString str;StaticHandler.create(str)
  • Smart code suggestions by Codota
}
origin: vert-x3/vertx-examples

router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"));
origin: vert-x3/vertx-examples

router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private"));
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 testServeFilesFromFilesystem() throws Exception {
 stat.setWebRoot("src/test/filesystemwebroot");
 testRequest(HttpMethod.GET, "/fspage.html", 200, "OK", "<html><body>File system page</body></html>");
}
origin: vert-x3/vertx-web

@Test
public void testCacheFilesFileDeleted() throws Exception {
 File webroot = new File(".vertx/webroot"), pageFile = new File(webroot, "deleted.html");
 if (!pageFile.exists()) {
  webroot.mkdirs();
  pageFile.createNewFile();
 }
 String page = '/' + pageFile.getName();
 stat.setFilesReadOnly(false);
 stat.setWebRoot(webroot.getPath());
 stat.setCacheEntryTimeout(3600 * 1000);
 long modified = Utils.secondsFactor(pageFile.lastModified());
 testRequest(HttpMethod.GET, page, req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), null, 304, "Not Modified", null);
 pageFile.delete();
 testRequest(HttpMethod.GET, page, 404, "Not Found");
 testRequest(HttpMethod.GET, page, req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), null, 404, "Not Found", null);
}
origin: vert-x3/vertx-web

@Test
public void testLinkPreload() throws Exception {
 List<Http2PushMapping> mappings = new ArrayList<>();
 mappings.add(new Http2PushMapping("style.css", "style", false));
 mappings.add(new Http2PushMapping("coin.png", "image", false));
 stat.setHttp2PushMapping(mappings)
   .setWebRoot("webroot/somedir3");
 testRequest(HttpMethod.GET, "/testLinkPreload.html", null, res -> {
  List<String> linkHeaders = res.headers().getAll("Link");
  assertTrue(linkHeaders.contains("<style.css>; rel=preload; as=style"));
  assertTrue(linkHeaders.contains("<coin.png>; rel=preload; as=image"));
 }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testNoLinkPreload() throws Exception {
 stat.setWebRoot("webroot/somedir3");
 testRequest(HttpMethod.GET, "/testLinkPreload.html", null, res -> {
  List<String> linkHeaders = res.headers().getAll("Link");
  assertTrue(linkHeaders.isEmpty());
 }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testServerFileSystemPath() throws Exception {
 router.clear();
 File file = File.createTempFile("vertx", "tmp");
 file.deleteOnExit();
 // remap stat to the temp dir
 try {
  stat = StaticHandler.create(file.getParent());
  fail();
 } catch (IllegalArgumentException e) {
  // expected
 }
 stat = StaticHandler.create().setAllowRootFileSystemAccess(true).setWebRoot(file.getParent());
 router.route().handler(stat);
 testRequest(HttpMethod.GET, "/" + file.getName(), 200, "OK", "");
}
origin: io.vertx/vertx-rx-java

/**
 * Set the web root
 * @param webRoot the web root
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.handler.StaticHandler setWebRoot(String webRoot) { 
 delegate.setWebRoot(webRoot);
 return this;
}
origin: vert-x3/vertx-web

@Test
public void testCacheFilesEntryCached() throws Exception {
 stat.setFilesReadOnly(false);
 stat.setWebRoot("src/test/filesystemwebroot");
 File resource = new File("src/test/filesystemwebroot", "fspage.html");
 long modified = resource.lastModified();
 testRequest(HttpMethod.GET, "/fspage.html", null, res -> {
  String lastModified = res.headers().get("last-modified");
  assertEquals(modified, toDateTime(lastModified));
  // Now update the web resource
  resource.setLastModified(modified + 1000);
 }, 200, "OK", "<html><body>File system page</body></html>");
 // But it should still return not modified as the entry is cached
 testRequest(HttpMethod.GET, "/fspage.html", req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), null, 304, "Not Modified", null);
}
origin: vert-x3/vertx-rx

/**
 * Set the web root
 * @param webRoot the web root
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.handler.StaticHandler setWebRoot(String webRoot) { 
 delegate.setWebRoot(webRoot);
 return this;
}
origin: vert-x3/vertx-web

@Test
public void testCacheFilesNotReadOnly() throws Exception {
 stat.setFilesReadOnly(false);
 stat.setWebRoot("src/test/filesystemwebroot");
 long modified = Utils.secondsFactor(new File("src/test/filesystemwebroot", "fspage.html").lastModified());
 testRequest(HttpMethod.GET, "/fspage.html", null, res -> {
  String lastModified = res.headers().get("last-modified");
  assertEquals(modified, toDateTime(lastModified));
 }, 200, "OK", "<html><body>File system page</body></html>");
 testRequest(HttpMethod.GET, "/fspage.html", req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), null, 304, "Not Modified", null);
}
origin: vert-x3/vertx-web

@Test
public void testCacheFilesEntryOld() throws Exception {
 String webroot = "src/test/filesystemwebroot", page = "/fspage.html";
 File resource = new File(webroot + page);
 String html = new String(Files.readAllBytes(resource.toPath()));
 int cacheEntryTimeout = 100;
 stat.setFilesReadOnly(false);
 stat.setWebRoot(webroot);
 stat.setCacheEntryTimeout(cacheEntryTimeout);
 long modified = Utils.secondsFactor(resource.lastModified());
 testRequest(HttpMethod.GET, page, null, res -> {
  String lastModified = res.headers().get("last-modified");
  assertEquals(modified, toDateTime(lastModified));
  // Now update the web resource
  resource.setLastModified(modified + 1000);
 }, 200, "OK", html);
 // But it should return a new entry as the entry is now old
 Thread.sleep(cacheEntryTimeout + 1);
 testRequest(HttpMethod.GET, page, req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), res -> {
  String lastModified = res.headers().get("last-modified");
  assertEquals(modified + 1000, toDateTime(lastModified));
 }, 200, "OK", html);
 // 304 must still work when cacheEntry.isOutOfDate() == true, https://github.com/vert-x3/vertx-web/issues/726
 Thread.sleep(cacheEntryTimeout + 1);
 testRequest(HttpMethod.GET, page, req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified + 1000)), 304, "Not Modified", null);
}
origin: vert-x3/vertx-web

mappings.add(new Http2PushMapping("coin.png", "image", false));
stat.setHttp2PushMapping(mappings)
  .setWebRoot("webroot/somedir3");
router.route().handler(stat);
HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions()
origin: vert-x3/vertx-web

@Test
public void testNoHttp2Push() throws Exception {
 stat.setWebRoot("webroot/somedir3");
 router.route().handler(stat);
 HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions()
  .setUseAlpn(true)
  .setSsl(true)
  .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
 http2Server.requestHandler(router).listen(8443);
 HttpClientOptions options = new HttpClientOptions()
  .setSsl(true)
  .setUseAlpn(true)
  .setProtocolVersion(HttpVersion.HTTP_2)
  .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
 HttpClient client = vertx.createHttpClient(options);
 HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", onSuccess(resp -> {
  assertEquals(200, resp.statusCode());
  assertEquals(HttpVersion.HTTP_2, resp.version());
  resp.bodyHandler(this::assertNotNull);
  testComplete();
 }));
 request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
  fail();
 }));
 request.end();
 await();
}
origin: io.vertx/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: io.vertx/vertx-web

@Test
public void testServeFilesFromFilesystem() throws Exception {
 stat.setWebRoot("src/test/filesystemwebroot");
 testRequest(HttpMethod.GET, "/fspage.html", 200, "OK", "<html><body>File system page</body></html>");
}
origin: io.vertx/vertx-web

@Test
public void testLinkPreload() throws Exception {
 List<Http2PushMapping> mappings = new ArrayList<>();
 mappings.add(new Http2PushMapping("style.css", "style", false));
 mappings.add(new Http2PushMapping("coin.png", "image", false));
 stat.setHttp2PushMapping(mappings)
   .setWebRoot("webroot/somedir3");
 testRequest(HttpMethod.GET, "/testLinkPreload.html", null, res -> {
  List<String> linkHeaders = res.headers().getAll("Link");
  assertTrue(linkHeaders.contains("<style.css>; rel=preload; as=style"));
  assertTrue(linkHeaders.contains("<coin.png>; rel=preload; as=image"));
 }, 200, "OK", null);
}
origin: io.vertx/vertx-web

@Test
public void testNoLinkPreload() throws Exception {
 stat.setWebRoot("webroot/somedir3");
 testRequest(HttpMethod.GET, "/testLinkPreload.html", null, res -> {
  List<String> linkHeaders = res.headers().getAll("Link");
  assertTrue(linkHeaders.isEmpty());
 }, 200, "OK", null);
}
origin: io.vertx/vertx-web

@Test
public void testCacheFilesNotReadOnly() throws Exception {
 stat.setFilesReadOnly(false);
 stat.setWebRoot("src/test/filesystemwebroot");
 long modified = Utils.secondsFactor(new File("src/test/filesystemwebroot", "fspage.html").lastModified());
 testRequest(HttpMethod.GET, "/fspage.html", null, res -> {
  String lastModified = res.headers().get("last-modified");
  assertEquals(modified, toDateTime(lastModified));
 }, 200, "OK", "<html><body>File system page</body></html>");
 testRequest(HttpMethod.GET, "/fspage.html", req -> req.putHeader("if-modified-since", dateTimeFormatter.format(modified)), null, 304, "Not Modified", null);
}
io.vertx.ext.web.handlerStaticHandlersetWebRoot

Javadoc

Set the web root

Popular methods of StaticHandler

  • create
    Create a handler, specifying web-root and a classloader used to load the resources.
  • setCachingEnabled
    Set whether cache header handling is enabled
  • setDirectoryListing
    Set whether directory listing is enabled
  • setIndexPage
    Set the index page
  • setAllowRootFileSystemAccess
    Enable/Disable access to the root of the filesystem
  • setHttp2PushMapping
    Set the file mapping for http2push and link preload
  • setAlwaysAsyncFS
    Set whether async filesystem access should always be used
  • setCacheEntryTimeout
    Set the server cache entry timeout when caching is enabled
  • setDefaultContentEncoding
    Set the default content encoding for text related files. This allows overriding the system settings
  • setDirectoryTemplate
    Set the directory template to be used when directory listing
  • setEnableRangeSupport
    Set whether range requests (resumable downloads; media streaming) should be enabled.
  • setFilesReadOnly
    Set whether files are read-only and will never change
  • setEnableRangeSupport,
  • setFilesReadOnly,
  • setIncludeHidden,
  • setMaxAgeSeconds,
  • setMaxAvgServeTimeNs,
  • skipCompressionForMediaTypes,
  • skipCompressionForSuffixes,
  • handle,
  • setEnableFSTuning

Popular in Java

  • Making http post requests using okhttp
  • addToBackStack (FragmentTransaction)
  • putExtra (Intent)
  • getApplicationContext (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • Logger (org.slf4j)
    The main user interface to logging. It is expected that logging takes place through concrete impleme
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now