use of org.apache.archiva.policies.ProxyDownloadException in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchFromProxies.
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact) throws ProxyDownloadException {
Path localFile = toLocalFile(repository, artifact);
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "artifact");
requestProperties.setProperty("version", artifact.getVersion());
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
Map<String, Exception> previousExceptions = new LinkedHashMap<>();
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = targetRepository.toPath(artifact);
if (SystemUtils.IS_OS_WINDOWS) {
// toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
targetPath = FilenameUtils.separatorsToUnix(targetPath);
}
try {
Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, true);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Artifact {} not found on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (NotModifiedException e) {
log.debug("Artifact {} not updated on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (ProxyException | RepositoryAdminException e) {
validatePolicies(this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, targetRepository, localFile, e, previousExceptions);
}
}
if (!previousExceptions.isEmpty()) {
throw new ProxyDownloadException("Failures occurred downloading from some remote repositories", previousExceptions);
}
log.debug("Exhausted all target repositories, artifact {} not found.", Keys.toKey(artifact));
return null;
}
use of org.apache.archiva.policies.ProxyDownloadException in project archiva by apache.
the class DefaultRepositoryProxyConnectors method validatePolicies.
private void validatePolicies(Map<String, DownloadErrorPolicy> policies, Map<String, String> settings, Properties request, ArtifactReference artifact, RemoteRepositoryContent content, Path localFile, Exception exception, Map<String, Exception> previousExceptions) throws ProxyDownloadException {
boolean process = true;
for (Entry<String, ? extends DownloadErrorPolicy> entry : policies.entrySet()) {
// olamy with spring rolehint is now downloadPolicy#hint
// so substring after last # to get the hint as with plexus
String key = StringUtils.substringAfterLast(entry.getKey(), "#");
DownloadErrorPolicy policy = entry.getValue();
String defaultSetting = policy.getDefaultOption();
String setting = StringUtils.defaultString(settings.get(key), defaultSetting);
log.debug("Applying [{}] policy with [{}]", key, setting);
try {
// all policies must approve the exception, any can cancel
process = policy.applyPolicy(setting, request, localFile, exception, previousExceptions);
if (!process) {
break;
}
} catch (PolicyConfigurationException e) {
log.error(e.getMessage(), e);
}
}
if (process) {
// if the exception was queued, don't throw it
if (!previousExceptions.containsKey(content.getId())) {
throw new ProxyDownloadException("An error occurred in downloading from the remote repository, and the policy is to fail immediately", content.getId(), exception);
}
} else {
// if the exception was queued, but cancelled, remove it
previousExceptions.remove(content.getId());
}
log.warn("Transfer error from repository {} for artifact {} , continuing to next repository. Error message: {}", content.getRepository().getId(), Keys.toKey(artifact), exception.getMessage());
log.debug("Full stack trace", exception);
}
use of org.apache.archiva.policies.ProxyDownloadException in project archiva by apache.
the class ErrorHandlingTest method confirmFailures.
private void confirmFailures(String path, String[] ids) throws LayoutException {
wagonMockControl.replay();
// Attempt the proxy fetch.
Path downloadedFile = null;
try {
downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, managedDefaultRepository.toArtifactReference(path));
fail("Proxy should not have succeeded");
} catch (ProxyDownloadException e) {
assertEquals(ids.length, e.getFailures().size());
for (String id : ids) {
assertTrue(e.getFailures().keySet().contains(id));
}
}
wagonMockControl.verify();
assertNotDownloaded(downloadedFile);
}
use of org.apache.archiva.policies.ProxyDownloadException in project archiva by apache.
the class ArchivaDavResourceFactory method fetchContentFromProxies.
private boolean fetchContentFromProxies(ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource) throws DavException {
String path = resource.getPath();
if (repositoryRequest.isSupportFile(path)) {
Path proxiedFile = connectors.fetchFromProxies(managedRepository, path);
return (proxiedFile != null);
}
// Is it a Metadata resource?
if (repositoryRequest.isDefault(path) && repositoryRequest.isMetadata(path)) {
return connectors.fetchMetadataFromProxies(managedRepository, path).isModified();
}
// Is it an Archetype Catalog?
if (repositoryRequest.isArchetypeCatalog(path)) {
// FIXME we must implement a merge of remote archetype catalog from remote servers.
Path proxiedFile = connectors.fetchFromProxies(managedRepository, path);
return (proxiedFile != null);
}
// Not any of the above? Then it's gotta be an artifact reference.
try {
// Get the artifact reference in a layout neutral way.
ArtifactReference artifact = repositoryRequest.toArtifactReference(path);
if (artifact != null) {
String repositoryLayout = managedRepository.getRepository().getLayout();
RepositoryStorage repositoryStorage = this.applicationContext.getBean("repositoryStorage#" + repositoryLayout, RepositoryStorage.class);
repositoryStorage.applyServerSideRelocation(managedRepository, artifact);
Path proxiedFile = connectors.fetchFromProxies(managedRepository, artifact);
resource.setPath(managedRepository.toPath(artifact));
log.debug("Proxied artifact '{}:{}:{}'", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
return (proxiedFile != null);
}
} catch (LayoutException e) {
/* eat it */
} catch (ProxyDownloadException e) {
log.error(e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource.");
}
return false;
}
Aggregations