Search in sources :

Example 1 with PolicyConfigurationException

use of org.apache.archiva.policies.PolicyConfigurationException in project archiva by apache.

the class DefaultRepositoryProxyConnectors method validatePolicies.

/**
 * Apply the policies.
 *
 * @param policies  the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects)
 * @param settings  the map of settings for the policies to execute. (Map of String policy keys, to String policy
 *                  setting)
 * @param request   the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, Path)}
 *                  )
 * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, Path)})
 * @throws PolicyViolationException
 */
private void validatePolicies(Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings, Properties request, Path localFile) throws PolicyViolationException {
    for (Entry<String, ? extends DownloadPolicy> 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(), "#");
        DownloadPolicy policy = entry.getValue();
        String defaultSetting = policy.getDefaultOption();
        String setting = StringUtils.defaultString(settings.get(key), defaultSetting);
        log.debug("Applying [{}] policy with [{}]", key, setting);
        try {
            policy.applyPolicy(setting, request, localFile);
        } catch (PolicyConfigurationException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : PolicyConfigurationException(org.apache.archiva.policies.PolicyConfigurationException) PreDownloadPolicy(org.apache.archiva.policies.PreDownloadPolicy) PostDownloadPolicy(org.apache.archiva.policies.PostDownloadPolicy) DownloadPolicy(org.apache.archiva.policies.DownloadPolicy)

Example 2 with PolicyConfigurationException

use of org.apache.archiva.policies.PolicyConfigurationException 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

PolicyConfigurationException (org.apache.archiva.policies.PolicyConfigurationException)2 DownloadErrorPolicy (org.apache.archiva.policies.DownloadErrorPolicy)1 DownloadPolicy (org.apache.archiva.policies.DownloadPolicy)1 PostDownloadPolicy (org.apache.archiva.policies.PostDownloadPolicy)1 PreDownloadPolicy (org.apache.archiva.policies.PreDownloadPolicy)1 ProxyDownloadException (org.apache.archiva.policies.ProxyDownloadException)1