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();
}
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();
}
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);
}
}
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;
}
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);
}
}
Aggregations