Search in sources :

Example 51 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ContextHandlerGetResourceTest method testDeep.

@Test
public void testDeep() throws Exception {
    final String path = "/subdir/data.txt";
    Resource resource = context.getResource(path);
    assertEquals("data.txt", resource.getFile().getName());
    assertEquals(docroot, resource.getFile().getParentFile().getParentFile());
    assertTrue(resource.exists());
    URL url = context.getServletContext().getResource(path);
    assertEquals(docroot, new File(url.toURI()).getParentFile().getParentFile());
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 52 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ContextHandlerGetResourceTest method testSubdir.

@Test
public void testSubdir() throws Exception {
    final String path = "/subdir";
    Resource resource = context.getResource(path);
    assertEquals(docroot, resource.getFile().getParentFile());
    assertTrue(resource.exists());
    assertTrue(resource.isDirectory());
    assertTrue(resource.toString().endsWith("/"));
    URL url = context.getServletContext().getResource(path);
    assertEquals(docroot, new File(url.toURI()).getParentFile());
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 53 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ContextHandlerGetResourceTest method testGetUnknownDir.

@Test
public void testGetUnknownDir() throws Exception {
    final String path = "/unknown/";
    Resource resource = context.getResource(path);
    assertEquals("unknown", resource.getFile().getName());
    assertEquals(docroot, resource.getFile().getParentFile());
    assertFalse(resource.exists());
    URL url = context.getServletContext().getResource(path);
    assertNull(url);
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) URL(java.net.URL) Test(org.junit.Test)

Example 54 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ContextHandlerGetResourceTest method testSymlinkNested.

@Test
public void testSymlinkNested() throws Exception {
    Assume.assumeTrue(OS.IS_UNIX);
    try {
        allowSymlinks.set(true);
        final String path = "/web/logs/file.log";
        Resource resource = context.getResource(path);
        assertNotNull(resource);
        assertEquals("file.log", resource.getFile().getName());
        assertTrue(resource.exists());
    } finally {
        allowSymlinks.set(false);
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 55 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ContextHandlerGetResourceTest method testEncodedSlash.

@Test
public void testEncodedSlash() throws Exception {
    final String path = "/subdir%2Fdata.txt";
    Resource resource = context.getResource(path);
    assertEquals("subdir%2Fdata.txt", resource.getFile().getName());
    assertEquals(docroot, resource.getFile().getParentFile());
    assertFalse(resource.exists());
    URL url = context.getServletContext().getResource(path);
    assertNull(url);
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.jetty.util.resource.Resource)196 Test (org.junit.Test)79 File (java.io.File)46 URL (java.net.URL)39 ArrayList (java.util.ArrayList)38 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)28 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)18 JarResource (org.eclipse.jetty.util.resource.JarResource)16 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)16 Server (org.eclipse.jetty.server.Server)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 URI (java.net.URI)8 MalformedURLException (java.net.MalformedURLException)7 StringTokenizer (java.util.StringTokenizer)7 URISyntaxException (java.net.URISyntaxException)6 Properties (java.util.Properties)6 Set (java.util.Set)6