Search in sources :

Example 1 with DownloadErrorPolicy

use of org.apache.archiva.policies.DownloadErrorPolicy 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);
}
Also used : PolicyConfigurationException(org.apache.archiva.policies.PolicyConfigurationException) DownloadErrorPolicy(org.apache.archiva.policies.DownloadErrorPolicy) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException)

Aggregations

DownloadErrorPolicy (org.apache.archiva.policies.DownloadErrorPolicy)1 PolicyConfigurationException (org.apache.archiva.policies.PolicyConfigurationException)1 ProxyDownloadException (org.apache.archiva.policies.ProxyDownloadException)1