Search in sources :

Example 11 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class MediaTypeFilter method accept.

@Override
public boolean accept(VirtualFile file) {
    try (InputStream content = file.getContent()) {
        TikaConfig tikaConfig = new TikaConfig();
        MediaType mimeType = tikaConfig.getDetector().detect(content, new Metadata());
        if (excludedMediaTypes.contains(mimeType) || excludedTypes.contains(mimeType.getType())) {
            return true;
        }
        return false;
    } catch (TikaException | ForbiddenException | ServerException | IOException e) {
        return true;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) TikaException(org.apache.tika.exception.TikaException) ServerException(org.eclipse.che.api.core.ServerException) TikaConfig(org.apache.tika.config.TikaConfig) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) MediaType(org.apache.tika.mime.MediaType) IOException(java.io.IOException)

Example 12 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class HashSumsCounter method visit.

@Override
public void visit(VirtualFile virtualFile) throws ServerException {
    if (virtualFile.isFile()) {
        try (InputStream in = virtualFile.getContent()) {
            final Hasher hasher = hashFunction.newHasher();
            ByteStreams.copy(in, asOutputStream(hasher));
            final String hexHash = hasher.hash().toString();
            hashSums.add(Pair.of(hexHash, virtualFile.getPath().subPath(folder.getPath()).toString()));
        } catch (IOException e) {
            throw new ServerException(e);
        } catch (ForbiddenException e) {
            throw new ServerException(e.getServiceError());
        }
    } else {
        for (VirtualFile child : virtualFile.getChildren()) {
            child.accept(this);
        }
    }
}
Also used : Hasher(com.google.common.hash.Hasher) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 13 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class TarArchiver method addTarEntry.

private void addTarEntry(VirtualFile virtualFile, TarArchiveOutputStream tarOutputStream) throws ServerException {
    try {
        TarArchiveEntry tarEntry = new TarArchiveEntry(getTarEntryName(virtualFile));
        if (virtualFile.isFolder()) {
            tarEntry.setModTime(0);
            tarOutputStream.putArchiveEntry(tarEntry);
        } else {
            tarEntry.setSize(virtualFile.getLength());
            tarEntry.setModTime(virtualFile.getLastModificationDate());
            tarOutputStream.putArchiveEntry(tarEntry);
            try (InputStream content = virtualFile.getContent()) {
                ByteStreams.copy(content, tarOutputStream);
            }
        }
        tarOutputStream.closeArchiveEntry();
    } catch (ForbiddenException e) {
        throw new ServerException(e.getServiceError());
    } catch (IOException e) {
        throw new ServerException(e.getMessage(), e);
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) NotClosableInputStream(org.eclipse.che.api.vfs.util.NotClosableInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 14 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class DefaultFileWatcherNotificationHandler method convertToVirtualFile.

private VirtualFile convertToVirtualFile(File root, String subPath, boolean isDir) {
    try {
        LocalVirtualFileSystem virtualFileSystem = (LocalVirtualFileSystem) virtualFileSystemProvider.getVirtualFileSystem(true);
        Path vfsPath = Path.of(subPath);
        VirtualFile virtualFile = virtualFileSystem.getRoot().getChild(vfsPath);
        if (virtualFile == null) {
            virtualFile = new DeletedLocalVirtualFile(new File(root, subPath), ROOT.newPath(vfsPath), virtualFileSystem, isDir);
        }
        return virtualFile;
    } catch (ServerException e) {
        LOG.warn(e.getMessage());
    }
    return null;
}
Also used : Path(org.eclipse.che.api.vfs.Path) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) File(java.io.File) VirtualFile(org.eclipse.che.api.vfs.VirtualFile)

Example 15 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ProjectManagerWriteTest method registerImporter.

private void registerImporter(String importType, InputStream zip) throws Exception {
    final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
    importerRegistry.register(new ProjectImporter() {

        @Override
        public String getId() {
            return importType;
        }

        @Override
        public boolean isInternal() {
            return false;
        }

        @Override
        public String getDescription() {
            return "importer";
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
            importSources(baseFolder, storage, LineConsumerFactory.NULL);
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
            // Don't really use location in this test.
            baseFolder.getVirtualFile().unzip(zip, true, 0);
            folderHolder.set(baseFolder);
        }

        @Override
        public ImporterCategory getCategory() {
            return ProjectImporter.ImporterCategory.ARCHIVE;
        }
    });
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8