Search in sources :

Example 1 with FileSystemException

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();
}
Also used : Path(java.nio.file.Path) FileSystemException(java.nio.file.FileSystemException) XmlConfiguredJetty(org.eclipse.jetty.deploy.test.XmlConfiguredJetty) Before(org.junit.Before)

Example 2 with FileSystemException

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));
    }
}
Also used : Path(java.nio.file.Path) FileSystemException(java.nio.file.FileSystemException) Test(org.junit.Test)

Example 3 with FileSystemException

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));
    }
}
Also used : Path(java.nio.file.Path) FileSystemException(java.nio.file.FileSystemException) Test(org.junit.Test)

Example 4 with FileSystemException

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;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) NotDirectoryException(java.nio.file.NotDirectoryException) FileSystemException(java.nio.file.FileSystemException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) GeoPoint(org.elasticsearch.common.geo.GeoPoint) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchFileException(java.nio.file.NoSuchFileException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) FileSystemLoopException(java.nio.file.FileSystemLoopException) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) FileSystemException(java.nio.file.FileSystemException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) AccessDeniedException(java.nio.file.AccessDeniedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 5 with FileSystemException

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"));
    }
}
Also used : FileSystemException(java.nio.file.FileSystemException) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Aggregations

FileSystemException (java.nio.file.FileSystemException)14 Path (java.nio.file.Path)9 IOException (java.io.IOException)5 Test (org.junit.Test)5 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 File (java.io.File)1