Search in sources :

Example 36 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultBrowseService method getArtifactContentEntries.

@Override
public List<ArtifactContentEntry> getArtifactContentEntries(String groupId, String artifactId, String version, String classifier, String type, String path, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    try {
        for (String repoId : selectedRepos) {
            ManagedRepositoryContent managedRepositoryContent = getManagedRepositoryContent(repoId);
            ArchivaArtifact archivaArtifact = new ArchivaArtifact(groupId, artifactId, version, classifier, StringUtils.isEmpty(type) ? "jar" : type, repoId);
            Path file = managedRepositoryContent.toFile(archivaArtifact);
            if (Files.exists(file)) {
                return readFileEntries(file, path, repoId);
            }
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } catch (RepositoryNotFoundException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) RepositoryNotFoundException(org.apache.archiva.repository.RepositoryNotFoundException)

Example 37 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultBrowseService method getArtifactContentText.

@Override
public ArtifactContent getArtifactContentText(String groupId, String artifactId, String version, String classifier, String type, String path, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    try {
        for (String repoId : selectedRepos) {
            ManagedRepositoryContent managedRepositoryContent = null;
            try {
                managedRepositoryContent = getManagedRepositoryContent(repoId);
            } catch (RepositoryException e) {
                log.error("No repository content found for " + repoId);
                continue;
            }
            ArchivaArtifact archivaArtifact = new ArchivaArtifact(groupId, artifactId, version, classifier, StringUtils.isEmpty(type) ? "jar" : type, repoId);
            Path file = managedRepositoryContent.toFile(archivaArtifact);
            if (!Files.exists(file)) {
                log.debug("file: {} not exists for repository: {} try next repository", file, repoId);
                continue;
            }
            if (StringUtils.isNotBlank(path)) {
                // zip entry of the path -> path must a real file entry of the archive
                JarFile jarFile = new JarFile(file.toFile());
                ZipEntry zipEntry = jarFile.getEntry(path);
                try (InputStream inputStream = jarFile.getInputStream(zipEntry)) {
                    return new ArtifactContent(IOUtils.toString(inputStream, ARTIFACT_CONTENT_ENCODING), repoId);
                } finally {
                    closeQuietly(jarFile);
                }
            }
            return new ArtifactContent(new String(Files.readAllBytes(file), ARTIFACT_CONTENT_ENCODING), repoId);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    log.debug("artifact: {}:{}:{}:{}:{} not found", groupId, artifactId, version, classifier, type);
    // 404 ?
    return new ArtifactContent();
}
Also used : Path(java.nio.file.Path) ArtifactContent(org.apache.archiva.rest.api.model.ArtifactContent) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 38 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultManagedRepositoriesService method createSnippet.

private String createSnippet(ManagedRepository repo) throws ArchivaRestServiceException {
    try {
        StringBuilder snippet = new StringBuilder();
        snippet.append("<project>\n");
        snippet.append("  ...\n");
        snippet.append("  <distributionManagement>\n");
        String distRepoName = "repository";
        if (repo.isSnapshots()) {
            distRepoName = "snapshotRepository";
        }
        snippet.append("    <").append(distRepoName).append(">\n");
        snippet.append("      <id>").append(repo.getId()).append("</id>\n");
        snippet.append("      <url>");
        snippet.append(getBaseUrl() + "/repository");
        snippet.append("/").append(repo.getId()).append("/").append("</url>\n");
        if (!"default".equals(repo.getLayout())) {
            snippet.append("      <layout>").append(repo.getLayout()).append("</layout>");
        }
        snippet.append("    </").append(distRepoName).append(">\n");
        snippet.append("  </distributionManagement>\n");
        snippet.append("\n");
        snippet.append("  <repositories>\n");
        snippet.append("    <repository>\n");
        snippet.append("      <id>").append(repo.getId()).append("</id>\n");
        snippet.append("      <name>").append(repo.getName()).append("</name>\n");
        snippet.append("      <url>");
        snippet.append(getBaseUrl() + "/repository");
        snippet.append("/").append(repo.getId()).append("/");
        snippet.append("</url>\n");
        if (!"default".equals(repo.getLayout())) {
            snippet.append("      <layout>").append(repo.getLayout()).append("</layout>\n");
        }
        snippet.append("      <releases>\n");
        snippet.append("        <enabled>").append(Boolean.valueOf(repo.isReleases())).append("</enabled>\n");
        snippet.append("      </releases>\n");
        snippet.append("      <snapshots>\n");
        snippet.append("        <enabled>").append(Boolean.valueOf(repo.isSnapshots())).append("</enabled>\n");
        snippet.append("      </snapshots>\n");
        snippet.append("    </repository>\n");
        snippet.append("  </repositories>\n");
        snippet.append("  <pluginRepositories>\n");
        snippet.append("    <pluginRepository>\n");
        snippet.append("      <id>").append(repo.getId()).append("</id>\n");
        snippet.append("      <name>").append(repo.getName()).append("</name>\n");
        snippet.append("      <url>");
        snippet.append(getBaseUrl() + "/repository");
        snippet.append("/").append(repo.getId()).append("/");
        snippet.append("</url>\n");
        if (!"default".equals(repo.getLayout())) {
            snippet.append("      <layout>").append(repo.getLayout()).append("</layout>\n");
        }
        snippet.append("      <releases>\n");
        snippet.append("        <enabled>").append(Boolean.valueOf(repo.isReleases())).append("</enabled>\n");
        snippet.append("      </releases>\n");
        snippet.append("      <snapshots>\n");
        snippet.append("        <enabled>").append(Boolean.valueOf(repo.isSnapshots())).append("</enabled>\n");
        snippet.append("      </snapshots>\n");
        snippet.append("    </pluginRepository>\n");
        snippet.append("  </pluginRepositories>\n");
        snippet.append("  ...\n");
        snippet.append("</project>\n");
        return StringEscapeUtils.escapeXml(snippet.toString());
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 39 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultSystemStatusService method clearCache.

@Override
public Boolean clearCache(String cacheKey) throws ArchivaRestServiceException {
    Cache cache = caches.get(cacheKey);
    if (cache == null) {
        throw new ArchivaRestServiceException("no cache for key: " + cacheKey, Response.Status.BAD_REQUEST.getStatusCode(), null);
    }
    cache.clear();
    return Boolean.TRUE;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) Cache(org.apache.archiva.redback.components.cache.Cache)

Example 40 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultArchivaAdministrationService method getInvalidContentAdminRepositoryConsumers.

@Override
public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers() throws ArchivaRestServiceException {
    try {
        AddAdminRepoConsumerClosure addAdminRepoConsumer = new AddAdminRepoConsumerClosure(archivaAdministration.getInvalidContentConsumers());
        IterableUtils.forEach(repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer);
        List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
        invalidContentConsumers.sort(AdminRepositoryConsumerComparator.getInstance());
        return invalidContentConsumers;
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : AddAdminRepoConsumerClosure(org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) AdminRepositoryConsumer(org.apache.archiva.rest.api.model.AdminRepositoryConsumer) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)44 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)16 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)15 RepositoryException (org.apache.archiva.repository.RepositoryException)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)11 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 Path (java.nio.file.Path)8 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)7 Artifact (org.apache.archiva.maven2.model.Artifact)6 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)5 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)5 ArtifactReference (org.apache.archiva.model.ArtifactReference)5 SearchResults (org.apache.archiva.indexer.search.SearchResults)4 ArchivaArtifact (org.apache.archiva.model.ArchivaArtifact)4 RepositoryNotFoundException (org.apache.archiva.repository.RepositoryNotFoundException)4