use of java.net.MalformedURLException in project jetty.project by eclipse.
the class WebAppContext method getResource.
/* ------------------------------------------------------------ */
@Override
public Resource getResource(String uriInContext) throws MalformedURLException {
if (uriInContext == null || !uriInContext.startsWith(URIUtil.SLASH))
throw new MalformedURLException(uriInContext);
IOException ioe = null;
Resource resource = null;
int loop = 0;
while (uriInContext != null && loop++ < 100) {
try {
resource = super.getResource(uriInContext);
if (resource != null && resource.exists())
return resource;
uriInContext = getResourceAlias(uriInContext);
} catch (IOException e) {
LOG.ignore(e);
if (ioe == null)
ioe = e;
}
}
if (ioe != null && ioe instanceof MalformedURLException)
throw (MalformedURLException) ioe;
return resource;
}
use of java.net.MalformedURLException in project jetty.project by eclipse.
the class ResourceAliasTest method testNullCharEndingFilename.
/* ------------------------------------------------------------ */
@Test
public void testNullCharEndingFilename() throws Exception {
File file = new File(__dir, "test.txt");
Assert.assertFalse(file.exists());
Assert.assertTrue(file.createNewFile());
Assert.assertTrue(file.exists());
File file0 = new File(__dir, "test.txt\0");
if (!file0.exists())
// this file system does not suffer this problem
return;
// This is an alias!
Assert.assertTrue(file0.exists());
Resource dir = Resource.newResource(__dir);
// Test not alias paths
Resource resource = Resource.newResource(file);
Assert.assertTrue(resource.exists());
Assert.assertNull(resource.getAlias());
resource = Resource.newResource(file.getAbsoluteFile());
Assert.assertTrue(resource.exists());
Assert.assertNull(resource.getAlias());
resource = Resource.newResource(file.toURI());
Assert.assertTrue(resource.exists());
Assert.assertNull(resource.getAlias());
resource = Resource.newResource(file.toURI().toString());
Assert.assertTrue(resource.exists());
Assert.assertNull(resource.getAlias());
resource = dir.addPath("test.txt");
Assert.assertTrue(resource.exists());
Assert.assertNull(resource.getAlias());
// Test alias paths
resource = Resource.newResource(file0);
Assert.assertTrue(resource.exists());
Assert.assertNotNull(resource.getAlias());
resource = Resource.newResource(file0.getAbsoluteFile());
Assert.assertTrue(resource.exists());
Assert.assertNotNull(resource.getAlias());
resource = Resource.newResource(file0.toURI());
Assert.assertTrue(resource.exists());
Assert.assertNotNull(resource.getAlias());
resource = Resource.newResource(file0.toURI().toString());
Assert.assertTrue(resource.exists());
Assert.assertNotNull(resource.getAlias());
try {
resource = dir.addPath("test.txt\0");
Assert.assertTrue(resource.exists());
Assert.assertNotNull(resource.getAlias());
} catch (MalformedURLException e) {
Assert.assertTrue(true);
}
}
use of java.net.MalformedURLException in project jetty.project by eclipse.
the class FileSystemResourceTest method testAddRootPath.
@Test
public void testAddRootPath() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Path subdir = dir.resolve("sub");
Files.createDirectories(subdir);
String readableRootDir = findRootDir(dir.getFileSystem());
assumeThat("Readable Root Dir found", readableRootDir, notNullValue());
try (Resource base = newResource(dir.toFile())) {
Resource sub = base.addPath("sub");
assertThat("sub", sub.isDirectory(), is(true));
try {
Resource rrd = sub.addPath(readableRootDir);
// valid path for unix and OSX
assertThat("Readable Root Dir", rrd.exists(), is(false));
} catch (MalformedURLException | InvalidPathException e) {
// valid path on Windows
}
}
}
use of java.net.MalformedURLException in project elasticsearch by elastic.
the class InstallPluginCommandTests method testMalformedUrlNotMaven.
public void testMalformedUrlNotMaven() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
// has two colons, so it appears similar to maven coordinates
MalformedURLException e = expectThrows(MalformedURLException.class, () -> installPlugin("://host:1234", env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}
use of java.net.MalformedURLException in project vert.x by eclipse.
the class NestedJarFileResolverTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// This folder is inside the embedded jar file called nested.jar, inside webroot4.jar
webRoot = "webroot4";
prevCL = Thread.currentThread().getContextClassLoader();
URL webroot4URL = prevCL.getResource("webroot4.jar");
ClassLoader loader = new ClassLoader(prevCL = Thread.currentThread().getContextClassLoader()) {
@Override
public URL getResource(String name) {
try {
if (name.startsWith("lib/")) {
return new URL("jar:" + webroot4URL + "!/" + name);
} else if (name.startsWith("webroot4")) {
return new URL("jar:" + webroot4URL + "!/lib/nested.jar!/" + name.substring(7));
}
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
return super.getResource(name);
}
};
Thread.currentThread().setContextClassLoader(loader);
}
Aggregations