use of java.nio.file.FileSystemException in project jetty.project by eclipse.
the class WebAppProviderTest method setupEnvironment.
@Before
public void setupEnvironment() throws Exception {
jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
jetty.addConfiguration("jetty-deploy-wars.xml");
// Setup initial context
jetty.copyWebapp("foo-webapp-1.war", "foo.war");
// Make symlink
Path pathWar3 = MavenTestingUtils.getTestResourcePathFile("webapps/foo-webapp-3.war");
Path pathBar = jetty.getJettyDir("webapps/bar.war").toPath();
try {
Files.createSymbolicLink(pathBar, pathWar3);
symlinkSupported = true;
} catch (UnsupportedOperationException | FileSystemException e) {
// if unable to create symlink, no point testing that feature
// this is the path that Microsoft Windows takes.
symlinkSupported = false;
}
// Should not throw an Exception
jetty.load();
// Start it
jetty.start();
}
use of java.nio.file.FileSystemException in project jetty.project by eclipse.
the class FileSystemResourceTest method testNonExistantSymlink.
@Test
public void testNonExistantSymlink() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
try {
Files.createSymbolicLink(bar, foo);
} catch (UnsupportedOperationException | FileSystemException e) {
// if unable to create symlink, no point testing the rest
// this is the path that Microsoft Windows takes.
assumeNoException(e);
}
try (Resource base = newResource(dir.toFile())) {
// FileResource does not pass this test!
assumeFalse(base instanceof FileResource);
Resource resFoo = base.addPath("foo");
Resource resBar = base.addPath("bar");
assertThat("resFoo.uri", resFoo.getURI(), is(foo.toUri()));
// Access to the same resource, but via a symlink means that they are not equivalent
assertThat("foo.equals(bar)", resFoo.equals(resBar), is(false));
assertThat("resource.alias", resFoo, hasNoAlias());
assertThat("resource.uri.alias", newResource(resFoo.getURI()), hasNoAlias());
assertThat("resource.file.alias", newResource(resFoo.getFile()), hasNoAlias());
assertThat("alias", resBar, isAliasFor(resFoo));
assertThat("uri.alias", newResource(resBar.getURI()), isAliasFor(resFoo));
assertThat("file.alias", newResource(resBar.getFile()), isAliasFor(resFoo));
}
}
use of java.nio.file.FileSystemException in project jetty.project by eclipse.
the class FileSystemResourceTest method testSymlink.
@Test
public void testSymlink() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
try {
Files.createFile(foo);
Files.createSymbolicLink(bar, foo);
} catch (UnsupportedOperationException | FileSystemException e) {
// if unable to create symlink, no point testing the rest
// this is the path that Microsoft Windows takes.
assumeNoException(e);
}
try (Resource base = newResource(dir.toFile())) {
if (OS.IS_WINDOWS && base instanceof FileResource)
// FileResource doesn't handle symlinks of Windows
return;
Resource resFoo = base.addPath("foo");
Resource resBar = base.addPath("bar");
assertThat("resFoo.uri", resFoo.getURI(), is(foo.toUri()));
// Access to the same resource, but via a symlink means that they are not equivalent
assertThat("foo.equals(bar)", resFoo.equals(resBar), is(false));
assertThat("resource.alias", resFoo, hasNoAlias());
assertThat("resource.uri.alias", newResource(resFoo.getURI()), hasNoAlias());
assertThat("resource.file.alias", newResource(resFoo.getFile()), hasNoAlias());
assertThat("alias", resBar, isAliasFor(resFoo));
assertThat("uri.alias", newResource(resBar.getURI()), isAliasFor(resFoo));
assertThat("file.alias", newResource(resBar.getFile()), isAliasFor(resFoo));
}
}
use of java.nio.file.FileSystemException in project elasticsearch by elastic.
the class StreamInput method readException.
public <T extends Exception> T readException() throws IOException {
if (readBoolean()) {
int key = readVInt();
switch(key) {
case 0:
final int ord = readVInt();
return (T) ElasticsearchException.readException(this, ord);
case 1:
String msg1 = readOptionalString();
String resource1 = readOptionalString();
return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this);
case 2:
String resource2 = readOptionalString();
int version2 = readInt();
int minVersion2 = readInt();
int maxVersion2 = readInt();
return (T) readStackTrace(new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this);
case 3:
String resource3 = readOptionalString();
if (readBoolean()) {
int version3 = readInt();
int minVersion3 = readInt();
int maxVersion3 = readInt();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this);
} else {
String version3 = readOptionalString();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this);
}
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this);
case 7:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 13:
final int subclass = readVInt();
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
// skip the msg - it's composed from file, other and reason
readOptionalString();
final Exception exception;
switch(subclass) {
case 0:
exception = new NoSuchFileException(file, other, reason);
break;
case 1:
exception = new NotDirectoryException(file);
break;
case 2:
exception = new DirectoryNotEmptyException(file);
break;
case 3:
exception = new AtomicMoveNotSupportedException(file, other, reason);
break;
case 4:
exception = new FileAlreadyExistsException(file, other, reason);
break;
case 5:
exception = new AccessDeniedException(file, other, reason);
break;
case 6:
exception = new FileSystemLoopException(file);
break;
case 7:
exception = new FileSystemException(file, other, reason);
break;
default:
throw new IllegalStateException("unknown FileSystemException with index " + subclass);
}
return (T) readStackTrace(exception, this);
case 14:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this);
case 15:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this);
case 16:
return (T) readStackTrace(new InterruptedException(readOptionalString()), this);
case 17:
return (T) readStackTrace(new IOException(readOptionalString(), readException()), this);
default:
assert false : "no such exception for id: " + key;
}
}
return null;
}
use of java.nio.file.FileSystemException in project neo4j by neo4j.
the class LoadCommandTest method shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.
@Test
public void shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws IOException, IncorrectUsage, IncorrectFormat {
doThrow(new FileSystemException("the-message")).when(loader).load(any(), any());
try {
execute(null);
fail("expected exception");
} catch (CommandFailed e) {
assertThat(e.getMessage(), equalTo("unable to load database: FileSystemException: the-message"));
}
}
Aggregations