1package org.apache.archiva.policies;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.commons.lang.StringUtils;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25import org.springframework.stereotype.Service;
2627import java.io.File;
28import java.util.ArrayList;
29import java.util.List;
30import java.util.Map;
31import java.util.Properties;
3233/**34 * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.35 */36 @Service( "downloadErrorPolicy#propagate-errors" )
37publicclassPropagateErrorsDownloadPolicy38implementsDownloadErrorPolicy39 {
40private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
4142/**43 * Signifies any error should stop searching for other proxies.44 */45publicstaticfinal String STOP = "stop";
4647/**48 * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.49 */50publicstaticfinal String QUEUE = "queue error";
5152/**53 * Ignore errors and treat as if it were not found.54 */55publicstaticfinal String IGNORE = "ignore";
5657private List<String> options = new ArrayList<>( 3 );
5859publicPropagateErrorsDownloadPolicy()
60 {
61 options.add( STOP );
62 options.add( QUEUE );
63 options.add( IGNORE );
64 }
6566 @Override
67publicboolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
68 Map<String, Exception> previousExceptions )
69throwsPolicyConfigurationException70 {
71if ( !options.contains( policySetting ) )
72 {
73// Not a valid code.74thrownewPolicyConfigurationException( "Unknown error policy setting [" + policySetting +
75"], valid settings are [" + StringUtils.join(
76 options.iterator(), "," ) + "]" );
77 }
7879if ( IGNORE.equals( policySetting ) )
80 {
81// Ignore.82 log.debug( "Error policy set to IGNORE." );
83return false;
84 }
8586 String repositoryId = request.getProperty( "remoteRepositoryId" );
87if ( STOP.equals( policySetting ) )
88 {
89returntrue;
90 }
9192if ( QUEUE.equals( policySetting ) )
93 {
94 previousExceptions.put( repositoryId, exception );
95returntrue;
96 }
9798thrownewPolicyConfigurationException(
99"Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
100 }
101102 @Override
103public String getDefaultOption()
104 {
105return QUEUE;
106 }
107108 @Override
109public String getId()
110 {
111return"propagate-errors";
112 }
113114 @Override
115public String getName()
116 {
117return"On remote error";
118 }
119120 @Override
121public List<String> getOptions()
122 {
123return options;
124 }
125 }