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