1 package org.apache.archiva.policies;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.repository.storage.StorageAsset;
23 import org.apache.commons.lang3.StringUtils;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.stereotype.Service;
28 import java.util.ArrayList;
29 import java.util.List;
31 import java.util.Properties;
34 * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
36 @Service( "downloadErrorPolicy#propagate-errors" )
37 public class PropagateErrorsDownloadPolicy
38 implements DownloadErrorPolicy
40 private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
43 * Signifies any error should stop searching for other proxies.
45 public static final String STOP = "stop";
48 * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
50 public static final String QUEUE = "queue error";
53 * Ignore errors and treat as if it were not found.
55 public static final String IGNORE = "ignore";
57 private List<String> options = new ArrayList<>( 3 );
59 public PropagateErrorsDownloadPolicy()
63 options.add( IGNORE );
67 public boolean applyPolicy( String policySetting, Properties request, StorageAsset localFile, Exception exception,
68 Map<String, Exception> previousExceptions )
69 throws PolicyConfigurationException
71 if ( !options.contains( policySetting ) )
74 throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting +
75 "], valid settings are [" + StringUtils.join(
76 options.iterator(), "," ) + "]" );
79 if ( IGNORE.equals( policySetting ) )
82 log.debug( "Error policy set to IGNORE." );
86 String repositoryId = request.getProperty( "remoteRepositoryId" );
87 if ( STOP.equals( policySetting ) )
92 if ( QUEUE.equals( policySetting ) )
94 previousExceptions.put( repositoryId, exception );
98 throw new PolicyConfigurationException(
99 "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
103 public String getDefaultOption()
109 public String getId()
111 return "propagate-errors";
115 public String getName()
117 return "On remote error";
121 public List<String> getOptions()