Proxy changes

This commit is contained in:
Martin Stockhammer 2019-09-08 21:05:34 +02:00
parent 0fef7e9c5f
commit b072f6921d
26 changed files with 609 additions and 390 deletions

View File

@ -103,7 +103,7 @@ public class AbstractRepositoryConnectorConfiguration
* @param key
* @param value
*/
public void addPolicy( Object key, String value )
public void addPolicy( String key, String value )
{
getPolicies().put( key, value );
} //-- void addPolicy( Object, String )
@ -114,7 +114,7 @@ public class AbstractRepositoryConnectorConfiguration
* @param key
* @param value
*/
public void addProperty( Object key, String value )
public void addProperty( String key, String value )
{
getProperties().put( key, value );
} //-- void addProperty( Object, String )
@ -149,7 +149,7 @@ public class AbstractRepositoryConnectorConfiguration
*
* @return Map
*/
public java.util.Map getPolicies()
public java.util.Map<String, String> getPolicies()
{
if ( this.policies == null )
{
@ -164,7 +164,7 @@ public class AbstractRepositoryConnectorConfiguration
*
* @return Map
*/
public java.util.Map getProperties()
public java.util.Map<String, String> getProperties()
{
if ( this.properties == null )
{

View File

@ -69,11 +69,16 @@ public interface ProxyRegistry {
* Returns the list of all proxy connectors.
* @return
*/
public List<org.apache.archiva.proxy.model.ProxyConnector> getProxyConnectors();
List<org.apache.archiva.proxy.model.ProxyConnector> getProxyConnectors( );
/**
* Returns a map of connector lists with the source repository id as key
* @return A map with source repository ids as key and list of corresponding proxy connector objects as value.
*/
public Map<String, List<ProxyConnector>> getProxyConnectorAsMap();
Map<String, List<ProxyConnector>> getProxyConnectorAsMap( );
/**
* Reloads the proxies from the configuration.
*/
void reload();
}

View File

@ -19,10 +19,10 @@ package org.apache.archiva.proxy.model;
* under the License.
*/
import org.apache.archiva.policies.Policy;
import org.apache.archiva.policies.PolicyOption;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.connector.RepositoryConnector;
import java.util.Iterator;
@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map;
/**
* This represents a connector for a repository to repository proxy.
* This represents a connector for a repository to a remote repository that is proxied.
*/
public class ProxyConnector
implements RepositoryConnector
@ -47,9 +47,9 @@ public class ProxyConnector
private int order;
private Map<String, String> policies;
private Map<Policy, PolicyOption> policies;
private boolean disabled;
private boolean enabled;
private Map<String, String> properties;
@ -58,77 +58,148 @@ public class ProxyConnector
// no op
}
/**
* @see RepositoryConnector#isEnabled()
*/
@Override
public boolean isDisabled()
public boolean isEnabled()
{
return disabled;
return enabled;
}
/**
* @see RepositoryConnector#enable()
*/
@Override
public void setDisabled( boolean disabled )
public void enable()
{
this.disabled = disabled;
this.enabled = true;
}
/**
* @see RepositoryConnector#disable()
*/
@Override
public void disable( )
{
this.enabled = false;
}
/**
* @see RepositoryConnector#getBlacklist()
*/
@Override
public List<String> getBlacklist()
{
return blacklist;
}
/**
* Sets the blacklist. The list is a string of paths.
*
* @param blacklist List of paths.
*/
public void setBlacklist( List<String> blacklist )
{
this.blacklist = blacklist;
}
/**
* @see RepositoryConnector#getSourceRepository()
*/
@Override
public ManagedRepository getSourceRepository()
{
return sourceRepository;
}
/**
* Sets the source repository.
* @param sourceRepository The managed repository which is the local representation of the proxy.
*/
public void setSourceRepository( ManagedRepository sourceRepository )
{
this.sourceRepository = sourceRepository;
}
/**
* @see ProxyConnector#getTargetRepository()
*/
@Override
public RemoteRepository getTargetRepository()
{
return targetRepository;
}
/**
* Sets the target repository.
* @param targetRepository The remote repository, where the artifacts are downloaded from.
*/
public void setTargetRepository( RemoteRepository targetRepository )
{
this.targetRepository = targetRepository;
}
/**
* @see ProxyConnector#getWhitelist()
*/
@Override
public List<String> getWhitelist()
{
return whitelist;
}
/**
* Sets the list of paths that are proxied.
* @param whitelist List of paths.
*/
public void setWhitelist( List<String> whitelist )
{
this.whitelist = whitelist;
}
public Map<String, String> getPolicies()
/**
* Returns the policies that are defined
* @return
*/
public Map<Policy, PolicyOption> getPolicies()
{
return policies;
}
public void setPolicies( Map<String, String> policies )
/**
* Sets policies that set the behaviour of this proxy connector.
* @param policies A map of policies with each option.
*/
public void setPolicies( Map<Policy, PolicyOption> policies )
{
this.policies = policies;
}
/**
* Adds a new policy.
* @param policy The policy to add.
* @param option The option for the policy.
*/
public void addPolicy( Policy policy, PolicyOption option )
{
this.policies.put( policy, option );
}
/**
* Returns the id of this proxy connector.
* @return The id string.
*/
public String getProxyId()
{
return proxyId;
}
/**
* Sets the id of this proxy connector.
* @param proxyId A id string.
*/
public void setProxyId( String proxyId )
{
this.proxyId = proxyId;
@ -144,10 +215,10 @@ public class ProxyConnector
sb.append( " target: [remote] " ).append( this.targetRepository.getId() ).append( "\n" );
sb.append( " proxyId:" ).append( this.proxyId ).append( "\n" );
Iterator<String> keys = this.policies.keySet().iterator();
Iterator<Policy> keys = this.policies.keySet().iterator();
while ( keys.hasNext() )
{
String name = keys.next();
String name = keys.next().getId();
sb.append( " policy[" ).append( name ).append( "]:" );
sb.append( this.policies.get( name ) ).append( "\n" );
}
@ -157,26 +228,37 @@ public class ProxyConnector
return sb.toString();
}
public void setPolicy( String policyId, String policySetting )
{
this.policies.put( policyId, policySetting );
}
/**
* Returns a number that orders the proxy connectors numerically.
* @return The order number of this connector.
*/
public int getOrder()
{
return order;
}
/**
* Set the order number of this proxy connector.
*
* @param order The order number.
*/
public void setOrder( int order )
{
this.order = order;
}
/**
* Returns additional properties defined for this connector.
* @return Map of key, value pairs.
*/
public Map<String, String> getProperties() {
return properties;
}
/**
* Sets additional properties for this connector.
* @param properties Map of key, value pairs.
*/
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

View File

@ -20,8 +20,9 @@ package org.apache.archiva.proxy.model;
*/
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.Policy;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.storage.StorageAsset;
@ -29,76 +30,148 @@ import java.util.List;
import java.util.Map;
/**
* Handler for potential repository proxy connectors.
* A repository proxy handler is used to fetch remote artifacts from different remote repositories.
* A proxy handler is connected to one managed repository and a list of remote repositories.
*
* Repository proxies should not be confused with network proxies. Network are proxies for specific network protocols,
* like HTTP. A repository proxy delegates the repository requests to remote repositories and caches artifacts.
*
* If a artifact is requested for the managed repository and the artifact is not cached locally, the handler goes through
* the list of remotes and tries to download the artifact. If a download was successful the artifact is cached locally.
*
* The connection between managed and remote repositories is defined by list of {@link ProxyConnector} each defines a one-to-one relationship.
*
* A proxy connector defines specifics about the download behaviour:
* <ul>
* <li>Policies {@link org.apache.archiva.policies.Policy} define the behaviour for different cases (errors, not available, caching lifetime).</li>
* <li>Black- and Whitelists are used to ban or allow certain paths on the remote repositories.
* </ul>
*
* The policies and black- and whitelist are set on the {@link ProxyConnector}
*
* There may be network proxies needed to connect the remote repositories.
*
*/
public interface RepositoryProxyHandler
{
List<RepositoryType> supports();
List<RepositoryType> supports( );
/**
* Performs the artifact fetch operation against the target repositories
* of the provided source repository.
*
* <p>
* If the artifact is found, it is downloaded and placed into the source repository
* filesystem.
*
*
* @param repository the source repository to use. (must be a managed repository)
* @param artifact the artifact to fetch.
* @param artifact the artifact to fetch.
* @return the file that was obtained, or null if no content was obtained
* @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
*/
StorageAsset fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
throws ProxyDownloadException;
/**
* Performs the metadata fetch operation against the target repositories
* of the provided source repository.
*
* <p>
* If the metadata is found, it is downloaded and placed into the source repository
* filesystem.
*
* @param repository the source repository to use. (must be a managed repository)
*
* @param repository the source repository to use. (must be a managed repository)
* @param logicalPath the metadata to fetch.
* @return the file that was obtained, or null if no content was obtained
*/
ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath );
ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath );
/**
* Performs the fetch operation against the target repositories
* of the provided source repository.
*
* of the provided source repository by a specific path.
*
* @param managedRepository the source repository to use. (must be a managed repository)
* @param path the path of the resource to fetch
* @param path the path of the resource to fetch
* @return the file that was obtained, or null if no content was obtained
*/
StorageAsset fetchFromProxies( ManagedRepositoryContent managedRepository, String path );
StorageAsset fetchFromProxies( ManagedRepository managedRepository, String path );
/**
* Get the List of {@link ProxyConnector} objects of the source repository.
*
*
* @param repository the source repository to look for.
* @return the List of {@link ProxyConnector} objects.
*/
List<ProxyConnector> getProxyConnectors( ManagedRepositoryContent repository );
List<ProxyConnector> getProxyConnectors( ManagedRepository repository );
/**
* Tests to see if the provided repository is a source repository for
* any {@link ProxyConnector} objects.
*
*
* @param repository the source repository to look for.
* @return true if there are proxy connectors that use the provided
* repository as a source repository.
* @return true if there are proxy connectors that use the provided
* repository as a source repository.
*/
boolean hasProxies( ManagedRepositoryContent repository );
boolean hasProxies( ManagedRepository repository );
void setNetworkProxies(Map<String, NetworkProxy> proxies);
/**
* Sets network proxies (normally HTTP proxies) to access the remote repositories.
*
* @param networkProxies A map of (repository id, network proxy) where the repository id must be the id of an
* existing remote repository.
*/
void setNetworkProxies( Map<String, NetworkProxy> networkProxies );
Map<String, NetworkProxy> getNetworkProxies();
/**
* Adds a network proxy that is used to access the remote repository.
*
* @param id The repository id
* @param networkProxy The network proxy to use
*/
void addNetworkproxy( String id, NetworkProxy networkProxy);
NetworkProxy getNetworkProxy(String id);
/**
* Returns a map of the defined network proxies, or a empty map, if no proxy is defined.
*
* @return A map (repository id, network proxy). If none is defined, a empty map is returned.
*/
Map<String, NetworkProxy> getNetworkProxies( );
/**
* Returns the network proxy that is defined for the given repository id.
* @param id The remote repository id
* @return A network proxy or <code>null</code> if no one is defined for this id.
*/
NetworkProxy getNetworkProxy( String id );
/**
* Returns the proxy handler implementation. This can be used, if the underlying implementation for a specific
* repository type is needed.
*
* @param clazz The class to convert to
* @param <T> The type
* @return The handler
*/
<T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException;
/**
* Sets the policies that this handler should validate.
* @param policyList
*/
void setPolicies(List<Policy> policyList);
/**
* Adds a policy
* @param policy
*/
void addPolicy( Policy policy );
/**
* Removes a policy
* @param policy
*/
void removePolicy( Policy policy );
void addProxyConnector(ProxyConnector connector);
void setProxyConnectors( List<ProxyConnector> proxyConnectors );
}

View File

@ -20,6 +20,9 @@ package org.apache.archiva.proxy;
*/
import org.apache.archiva.configuration.*;
import org.apache.archiva.policies.Policy;
import org.apache.archiva.policies.PolicyOption;
import org.apache.archiva.policies.PolicyUtil;
import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
@ -31,6 +34,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -38,6 +42,7 @@ import java.util.stream.Collectors;
* proxy information.
*
*/
@SuppressWarnings( "SpringJavaInjectionPointsAutowiringInspection" )
@Service("proxyRegistry#default")
public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListener {
@ -49,6 +54,9 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
@Inject
List<RepositoryProxyHandler> repositoryProxyHandlers;
@Inject
List<Policy> policies;
@Inject
RepositoryRegistry repositoryRegistry;
@ -58,6 +66,7 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
private Map<String, List<ProxyConnector>> connectorMap = new HashMap<>();
private List<ProxyConnector> connectorList = new ArrayList<>();
private Map<Policy, PolicyOption> policyMap = new HashMap<>( );
@PostConstruct
@ -65,7 +74,9 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
if (repositoryProxyHandlers == null) {
repositoryProxyHandlers = new ArrayList<>();
}
archivaConfiguration.addListener( this );
updateHandler();
updateConnectors();
updateNetworkProxies();
}
@ -85,17 +96,18 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
proxy.setHost(networkProxyConfig.getHost());
proxy.setPort(networkProxyConfig.getPort());
proxy.setUsername(networkProxyConfig.getUsername());
proxy.setPassword(networkProxyConfig.getPassword().toCharArray());
proxy.setPassword(networkProxyConfig.getPassword()==null? new char[0] : networkProxyConfig.getPassword().toCharArray());
proxy.setUseNtlm(networkProxyConfig.isUseNtlm());
this.networkProxyMap.put(key, proxy);
}
for (RepositoryProxyHandler connectors : repositoryProxyHandlers) {
connectors.setNetworkProxies(this.networkProxyMap);
for (RepositoryProxyHandler proxyHandler : repositoryProxyHandlers) {
proxyHandler.setNetworkProxies(this.networkProxyMap);
}
}
private void updateHandler() {
private void updateHandler( ) {
for (RepositoryProxyHandler handler : repositoryProxyHandlers) {
List<RepositoryType> types = handler.supports();
for (RepositoryType type : types) {
@ -104,16 +116,27 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
}
handlerMap.get(type).add(handler);
}
handler.setPolicies( policies );
}
}
private void updateConnectors() {
List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
getArchivaConfiguration().getConfiguration().getProxyConnectors();
getArchivaConfiguration().getConfiguration().getProxyConnectors();
connectorList = proxyConnectorConfigurations.stream()
.map(configuration -> buildProxyConnector(configuration))
.sorted(comparator).collect(Collectors.toList());
connectorMap = connectorList.stream().collect(Collectors.groupingBy(a -> a.getSourceRepository().getId()));
for (RepositoryProxyHandler handler : repositoryProxyHandlers) {
handler.setProxyConnectors( connectorList );
}
}
private Map<Policy, PolicyOption> getPolicyMap(ProxyConnectorConfiguration configuration) {
Map<String, String> policyConfig = configuration.getPolicies( );
return policies.stream().collect( Collectors.toMap( Function.identity(), p -> PolicyUtil.findOption( policyConfig.get(p.getId()), p ) ) );
}
private ProxyConnector buildProxyConnector(ProxyConnectorConfiguration configuration) {
@ -121,8 +144,12 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
proxyConnector.setOrder(configuration.getOrder());
proxyConnector.setBlacklist(configuration.getBlackListPatterns());
proxyConnector.setWhitelist(configuration.getWhiteListPatterns());
proxyConnector.setDisabled(configuration.isDisabled());
proxyConnector.setPolicies(configuration.getPolicies());
if (configuration.isDisabled()) {
proxyConnector.disable();
} else {
proxyConnector.enable();
}
proxyConnector.setPolicies(getPolicyMap( configuration ));
proxyConnector.setProperties(configuration.getProperties());
proxyConnector.setProxyId(configuration.getProxyId());
ManagedRepository srcRepo = repositoryRegistry.getManagedRepository(configuration.getSourceRepoId());
@ -159,8 +186,7 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
@Override
public void configurationEvent(ConfigurationEvent event) {
log.debug("Config changed updating proxy list");
updateNetworkProxies();
updateConnectors();
init( );
}
@Override
@ -173,4 +199,10 @@ public class ArchivaProxyRegistry implements ProxyRegistry, ConfigurationListene
public Map<String, List<ProxyConnector>> getProxyConnectorAsMap() {
return connectorMap;
}
@Override
public void reload( )
{
init();
}
}

View File

@ -21,26 +21,36 @@ package org.apache.archiva.proxy;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksumUtil;
import org.apache.archiva.proxy.model.ProxyConnectorRuleType;
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.configuration.*;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.Keys;
import org.apache.archiva.policies.*;
import org.apache.archiva.policies.DownloadErrorPolicy;
import org.apache.archiva.policies.DownloadPolicy;
import org.apache.archiva.policies.Policy;
import org.apache.archiva.policies.PolicyConfigurationException;
import org.apache.archiva.policies.PolicyOption;
import org.apache.archiva.policies.PolicyViolationException;
import org.apache.archiva.policies.PostDownloadPolicy;
import org.apache.archiva.policies.PreDownloadPolicy;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.policies.urlcache.UrlFailureCache;
import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.redback.components.registry.Registry;
import org.apache.archiva.redback.components.registry.RegistryListener;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.storage.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.storage.StorageUtil;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.commons.collections4.CollectionUtils;
@ -56,41 +66,41 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHandler, RegistryListener {
public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHandler {
protected Logger log = LoggerFactory.getLogger( DefaultRepositoryProxyHandler.class );
@Inject
protected UrlFailureCache urlFailureCache;
@Inject
@Named(value = "archivaConfiguration#default")
private ArchivaConfiguration archivaConfiguration;
@Inject
@Named(value = "metadataTools#default")
private MetadataTools metadataTools;
@Inject
private Map<String, PreDownloadPolicy> preDownloadPolicies;
@Inject
private Map<String, PostDownloadPolicy> postDownloadPolicies;
@Inject
private Map<String, DownloadErrorPolicy> downloadErrorPolicies;
private Map<String, PreDownloadPolicy> preDownloadPolicies = new HashMap<>( );
private Map<String, PostDownloadPolicy> postDownloadPolicies = new HashMap<>( );
private Map<String, DownloadErrorPolicy> downloadErrorPolicies = new HashMap<>( );
private ConcurrentMap<String, List<ProxyConnector>> proxyConnectorMap = new ConcurrentHashMap<>();
@Inject
@Named(value = "archivaTaskScheduler#repository")
private ArchivaTaskScheduler<RepositoryTask> scheduler;
@Inject
private RepositoryRegistry repositoryRegistry;
private ArchivaConfiguration archivaConfiguration;
@Inject
@Named(value = "fileLockManager#default")
@ -102,113 +112,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
@PostConstruct
public void initialize()
{
initConnectors();
archivaConfiguration.addChangeListener( this );
checksumAlgorithms = ChecksumUtil.getAlgorithms(archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().getChecksumTypes());
}
@SuppressWarnings("unchecked")
private void initConnectors()
{
ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator();
this.proxyConnectorMap.clear();
Configuration configuration = archivaConfiguration.getConfiguration();
List<ProxyConnectorRuleConfiguration> allProxyConnectorRuleConfigurations =
configuration.getProxyConnectorRuleConfigurations();
List<ProxyConnectorConfiguration> proxyConfigs = configuration.getProxyConnectors();
for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs )
{
String key = proxyConfig.getSourceRepoId();
// Create connector object.
ProxyConnector connector = new ProxyConnector();
ManagedRepository repo = repositoryRegistry.getManagedRepository( proxyConfig.getSourceRepoId( ) );
if (repo==null) {
log.error("Cannot find source repository after config change "+proxyConfig.getSourceRepoId());
continue;
}
connector.setSourceRepository(repo);
RemoteRepository rRepo = repositoryRegistry.getRemoteRepository( proxyConfig.getTargetRepoId() );
if (rRepo==null) {
log.error("Cannot find target repository after config change "+proxyConfig.getSourceRepoId());
continue;
}
connector.setTargetRepository(rRepo);
connector.setProxyId( proxyConfig.getProxyId() );
connector.setPolicies( proxyConfig.getPolicies() );
connector.setOrder( proxyConfig.getOrder() );
connector.setDisabled( proxyConfig.isDisabled() );
// Copy any blacklist patterns.
List<String> blacklist = new ArrayList<>( 0 );
if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) )
{
blacklist.addAll( proxyConfig.getBlackListPatterns() );
}
connector.setBlacklist( blacklist );
// Copy any whitelist patterns.
List<String> whitelist = new ArrayList<>( 0 );
if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) )
{
whitelist.addAll( proxyConfig.getWhiteListPatterns() );
}
connector.setWhitelist( whitelist );
List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations =
findProxyConnectorRules( connector.getSourceRepository().getId(),
connector.getTargetRepository().getId(),
allProxyConnectorRuleConfigurations );
if ( !proxyConnectorRuleConfigurations.isEmpty() )
{
for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations )
{
if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(),
ProxyConnectorRuleType.BLACK_LIST.getRuleType() ) )
{
connector.getBlacklist().add( proxyConnectorRuleConfiguration.getPattern() );
}
if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(),
ProxyConnectorRuleType.WHITE_LIST.getRuleType() ) )
{
connector.getWhitelist().add( proxyConnectorRuleConfiguration.getPattern() );
}
}
}
// Get other connectors
List<ProxyConnector> connectors = this.proxyConnectorMap.get( key );
if ( connectors == null )
{
// Create if we are the first.
connectors = new ArrayList<>( 1 );
}
// Add the connector.
connectors.add( connector );
// Ensure the list is sorted.
Collections.sort( connectors, proxyOrderSorter );
// Set the key to the list of connectors.
this.proxyConnectorMap.put( key, connectors );
}
}
private List<ProxyConnectorRuleConfiguration> findProxyConnectorRules(String sourceRepository,
@ -232,23 +136,8 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return proxyConnectorRuleConfigurations;
}
private void updateNetworkProxies() {
Map<String, NetworkProxy> proxies = archivaConfiguration.getConfiguration().getNetworkProxies().stream().map(p -> {
NetworkProxy np = new NetworkProxy();
np.setId(p.getId());
np.setUseNtlm(p.isUseNtlm());
np.setUsername(p.getUsername());
np.setPassword(p.getPassword() == null ? new char[0] : p.getPassword().toCharArray());
np.setProtocol(p.getProtocol());
np.setHost(p.getHost());
np.setPort(p.getPort());
return np;
}).collect(Collectors.toMap(p -> p.getId(), p -> p));
setNetworkProxies(proxies);
}
@Override
public StorageAsset fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
public StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
throws ProxyDownloadException
{
StorageAsset localFile = toLocalFile( repository, artifact );
@ -262,7 +151,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
Map<String, Exception> previousExceptions = new LinkedHashMap<>();
for ( ProxyConnector connector : connectors )
{
if ( connector.isDisabled() )
if ( !connector.isEnabled() )
{
continue;
}
@ -281,7 +170,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
try
{
StorageAsset downloadedFile =
transferFile( connector, targetRepository.getContent(), targetPath, repository, localFile, requestProperties,
transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
true );
if ( fileExists(downloadedFile) )
@ -319,9 +208,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
@Override
public StorageAsset fetchFromProxies( ManagedRepositoryContent repository, String path )
public StorageAsset fetchFromProxies( ManagedRepository repository, String path )
{
StorageAsset localFile = repository.getRepository().getAsset( path );
StorageAsset localFile = repository.getAsset( path );
// no update policies for these paths
if ( localFile.exists() )
@ -336,7 +225,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
List<ProxyConnector> connectors = getProxyConnectors( repository );
for ( ProxyConnector connector : connectors )
{
if ( connector.isDisabled() )
if ( !connector.isEnabled() )
{
continue;
}
@ -349,7 +238,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
try
{
StorageAsset downloadedFile =
transferFile( connector, targetRepository.getContent(), targetPath, repository, localFile, requestProperties,
transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
false );
if ( fileExists( downloadedFile ) )
@ -387,9 +276,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath )
public ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath )
{
StorageAsset localFile = repository.getRepository().getAsset( logicalPath );
StorageAsset localFile = repository.getAsset( logicalPath );
Properties requestProperties = new Properties();
requestProperties.setProperty( "filetype", "metadata" );
@ -399,7 +288,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
List<ProxyConnector> connectors = new ArrayList<>( getProxyConnectors( repository ) );
for ( ProxyConnector connector : connectors )
{
if ( connector.isDisabled() )
if ( !connector.isEnabled() )
{
continue;
}
@ -411,7 +300,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
try
{
transferFile( connector, targetRepository.getContent(), logicalPath, repository, localRepoFile, requestProperties,
transferFile( connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties,
true );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
@ -451,7 +340,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
{
try
{
metadataTools.updateMetadata( repository, logicalPath );
metadataTools.updateMetadata( repository.getContent(), logicalPath );
}
catch ( RepositoryMetadataException e )
{
@ -489,18 +378,19 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return ( currentLastModified > originalLastModified );
}
private StorageAsset toLocalRepoFile( ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository,
private StorageAsset toLocalRepoFile( ManagedRepository repository, RemoteRepositoryContent targetRepository,
String targetPath )
{
String repoPath = metadataTools.getRepositorySpecificName( targetRepository, targetPath );
return repository.getRepository().getAsset( repoPath );
return repository.getAsset( repoPath );
}
/**
* Test if the provided ManagedRepositoryContent has any proxies configured for it.
* @param repository
*/
@Override
public boolean hasProxies( ManagedRepositoryContent repository )
public boolean hasProxies( ManagedRepository repository )
{
synchronized ( this.proxyConnectorMap )
{
@ -508,9 +398,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
}
private StorageAsset toLocalFile(ManagedRepositoryContent repository, ArtifactReference artifact )
private StorageAsset toLocalFile(ManagedRepository repository, ArtifactReference artifact )
{
return repository.toFile( artifact );
return repository.getContent().toFile( artifact );
}
/**
@ -550,12 +440,20 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
* the remote resource is not newer than the local File.
* @throws ProxyException if transfer was unsuccessful.
*/
protected StorageAsset transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, StorageAsset resource, Properties requestProperties,
protected StorageAsset transferFile( ProxyConnector connector, RemoteRepository remoteRepository, String remotePath,
ManagedRepository repository, StorageAsset resource, Properties requestProperties,
boolean executeConsumers )
throws ProxyException, NotModifiedException
{
String url = remoteRepository.getURL().getUrl();
String url = null;
try
{
url = remoteRepository.getLocation().toURL().toString();
}
catch ( MalformedURLException e )
{
throw new ProxyException( e.getMessage(), e );
}
if ( !url.endsWith( "/" ) )
{
url = url + "/";
@ -570,7 +468,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
if ( !matchesPattern( remotePath, connector.getWhitelist() ) )
{
log.debug( "Path [{}] is not part of defined whitelist (skipping transfer from repository [{}]).",
remotePath, remoteRepository.getRepository().getName() );
remotePath, remoteRepository.getId() );
return null;
}
}
@ -579,7 +477,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
if ( matchesPattern( remotePath, connector.getBlacklist() ) )
{
log.debug( "Path [{}] is part of blacklist (skipping transfer from repository [{}]).", remotePath,
remoteRepository.getRepository().getName() );
remoteRepository.getId() );
return null;
}
@ -666,9 +564,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return resource;
}
protected abstract void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository,
protected abstract void transferResources( ProxyConnector connector, RemoteRepository remoteRepository,
StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource, Path workingDirectory,
ManagedRepositoryContent repository ) throws ProxyException;
ManagedRepository repository ) throws ProxyException;
private void queueRepositoryTask(String repositoryId, StorageAsset localFile )
{
@ -716,7 +614,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
* @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(PolicyOption, Properties, StorageAsset)})
* @throws PolicyViolationException
*/
private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<Policy, PolicyOption> settings,
Properties request, StorageAsset localFile )
throws PolicyViolationException
{
@ -724,9 +622,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
{
// 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(), "#" );
String key = entry.getValue( ).getId( );
DownloadPolicy policy = entry.getValue();
PolicyOption option = PolicyUtil.findOption(settings.get(key), policy);
PolicyOption option = settings.containsKey(policy ) ? settings.get(policy) : policy.getDefaultOption();
log.debug( "Applying [{}] policy with [{}]", key, option );
try
@ -740,7 +638,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
}
private void validatePolicies( Map<String, DownloadErrorPolicy> policies, Map<String, String> settings,
private void validatePolicies( Map<String, DownloadErrorPolicy> policies, Map<Policy, PolicyOption> settings,
Properties request, ArtifactReference artifact, RemoteRepositoryContent content,
StorageAsset localFile, Exception exception, Map<String, Exception> previousExceptions )
throws ProxyDownloadException
@ -751,9 +649,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
// 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(), "#" );
String key = entry.getValue( ).getId( );
DownloadErrorPolicy policy = entry.getValue();
PolicyOption option = PolicyUtil.findOption(settings.get(key), policy);
PolicyOption option = settings.containsKey( policy ) ? settings.get(policy) : policy.getDefaultOption();
log.debug( "Applying [{}] policy with [{}]", key, option );
try
@ -799,7 +697,7 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
* @param repository
* @return file location of working directory
*/
private Path createWorkingDirectory( ManagedRepositoryContent repository )
private Path createWorkingDirectory( ManagedRepository repository )
{
try
{
@ -883,9 +781,10 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
/**
* TODO: Ensure that list is correctly ordered based on configuration. See MRM-477
* @param repository
*/
@Override
public List<ProxyConnector> getProxyConnectors( ManagedRepositoryContent repository )
public List<ProxyConnector> getProxyConnectors( ManagedRepository repository )
{
if ( !this.proxyConnectorMap.containsKey( repository.getId() ) )
@ -899,18 +798,6 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
@Override
public void afterConfigurationChange(Registry registry, String propertyName, Object propertyValue )
{
if ( ConfigurationNames.isManagedRepositories( propertyName ) //
|| ConfigurationNames.isRemoteRepositories( propertyName ) //
|| ConfigurationNames.isProxyConnector( propertyName ) ) //
{
initConnectors();
} else if (ConfigurationNames.isNetworkProxy(propertyName)) {
updateNetworkProxies();
}
}
protected String addParameters(String path, RemoteRepository remoteRepository )
{
@ -934,17 +821,6 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
return res.toString();
}
@Override
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
/* do nothing */
}
public ArchivaConfiguration getArchivaConfiguration()
{
return archivaConfiguration;
}
public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration )
{
this.archivaConfiguration = archivaConfiguration;
@ -1001,9 +877,9 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
@Override
public void setNetworkProxies(Map<String, NetworkProxy> proxies) {
public void setNetworkProxies(Map<String, NetworkProxy> networkProxies ) {
this.networkProxyMap.clear();
this.networkProxyMap.putAll(proxies);
this.networkProxyMap.putAll( networkProxies );
}
@Override
@ -1018,4 +894,77 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
@Override
public abstract List<RepositoryType> supports();
@Override
public void setPolicies( List<Policy> policyList )
{
preDownloadPolicies.clear();
postDownloadPolicies.clear();
downloadErrorPolicies.clear();
for (Policy policy : policyList) {
addPolicy( policy );
}
}
void addPolicy(PreDownloadPolicy policy) {
preDownloadPolicies.put( policy.getId( ), policy );
}
void addPolicy(PostDownloadPolicy policy) {
postDownloadPolicies.put( policy.getId( ), policy );
}
void addPolicy(DownloadErrorPolicy policy) {
downloadErrorPolicies.put( policy.getId( ), policy );
}
@Override
public void addPolicy( Policy policy )
{
if (policy instanceof PreDownloadPolicy) {
addPolicy( (PreDownloadPolicy)policy );
} else if (policy instanceof PostDownloadPolicy) {
addPolicy( (PostDownloadPolicy) policy );
} else if (policy instanceof DownloadErrorPolicy) {
addPolicy( (DownloadErrorPolicy) policy );
} else {
log.warn( "Policy not known: {}, {}", policy.getId( ), policy.getClass( ).getName( ) );
}
}
@Override
public void removePolicy( Policy policy )
{
final String id = policy.getId();
if (preDownloadPolicies.containsKey( id )) {
preDownloadPolicies.remove( id );
} else if (postDownloadPolicies.containsKey( id )) {
postDownloadPolicies.remove( id );
} else if (downloadErrorPolicies.containsKey( id )) {
downloadErrorPolicies.remove( id );
}
}
@Override
public void addProxyConnector( ProxyConnector connector )
{
final String sourceId = connector.getSourceRepository( ).getId( );
List<ProxyConnector> connectors;
if (proxyConnectorMap.containsKey( sourceId )) {
connectors = proxyConnectorMap.get( sourceId );
} else {
connectors = new ArrayList<>( );
proxyConnectorMap.put( sourceId, connectors );
}
connectors.add( connector );
}
@Override
public void setProxyConnectors( List<ProxyConnector> proxyConnectors )
{
proxyConnectorMap.clear();
for ( ProxyConnector connector : proxyConnectors )
{
addProxyConnector( connector );
}
}
}

View File

@ -32,15 +32,46 @@ import java.util.List;
*/
public interface RepositoryConnector
{
/**
* Returns the local repository that is connected to the remote.
* @return The local managed repository.
*/
ManagedRepository getSourceRepository();
/**
* Returns the remote repository that is connected to the local.
* @return The remote repository.
*/
RemoteRepository getTargetRepository();
/**
* Returns a list of paths that are not fetched from the remote repository.
* @return A list of paths.
*/
List<String> getBlacklist();
/**
* Returns a list of paths that are fetched from the remote repository, even if a
* parent path is in the blacklist.
*
* @return The list of paths.
*/
List<String> getWhitelist();
boolean isDisabled();
void setDisabled(boolean disabled);
/**
* Returns true, if this connector is enabled, otherwise false.
* @return True, if enabled.
*/
boolean isEnabled();
/**
* Enables this connector, if it was disabled before, otherwise does nothing.
*/
void enable();
/**
* Disables this connector, if it was enabled before, otherwise does nothing.
*/
void disable();
}

View File

@ -27,6 +27,7 @@ import org.apache.archiva.proxy.NotModifiedException;
import org.apache.archiva.proxy.ProxyException;
import org.apache.archiva.proxy.model.NetworkProxy;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang3.StringUtils;
@ -55,7 +56,7 @@ import java.util.concurrent.ConcurrentMap;
* TODO exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than
* your average brown onion
*/
@Service("repositoryProxyConnectors#maven")
@Service( "repositoryProxyHandler#maven" )
public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
private static final List<RepositoryType> REPOSITORY_TYPES = new ArrayList<>();
@ -76,7 +77,6 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
private void updateWagonProxyInfo(Map<String, NetworkProxy> proxyList) {
this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = getArchivaConfiguration().getConfiguration().getNetworkProxies();
for (Map.Entry<String, NetworkProxy> proxyEntry : proxyList.entrySet()) {
String key = proxyEntry.getKey();
NetworkProxy networkProxyDef = proxyEntry.getValue();
@ -94,9 +94,9 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
}
@Override
public void setNetworkProxies(Map<String, NetworkProxy> proxies) {
super.setNetworkProxies(proxies);
updateWagonProxyInfo(proxies);
public void setNetworkProxies(Map<String, NetworkProxy> networkProxies ) {
super.setNetworkProxies( networkProxies );
updateWagonProxyInfo( networkProxies );
}
/**
@ -112,13 +112,13 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @throws ProxyException
* @throws NotModifiedException
*/
protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository,
protected void transferResources( ProxyConnector connector, RemoteRepository remoteRepository,
StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource,
Path workingDirectory, ManagedRepositoryContent repository )
Path workingDirectory, ManagedRepository repository )
throws ProxyException, NotModifiedException {
Wagon wagon = null;
try {
RepositoryURL repoUrl = remoteRepository.getURL();
RepositoryURL repoUrl = remoteRepository.getContent().getURL();
String protocol = repoUrl.getProtocol();
NetworkProxy networkProxy = null;
String proxyId = connector.getProxyId();
@ -127,7 +127,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
networkProxy = getNetworkProxy(proxyId);
}
WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol,
remoteRepository.getRepository().getExtraHeaders());
remoteRepository.getExtraHeaders());
if (networkProxy == null) {
log.warn("No network proxy with id {} found for connector {}->{}", proxyId,
@ -180,8 +180,8 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
}
}
protected void transferArtifact(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, Path resource, Path tmpDirectory,
protected void transferArtifact(Wagon wagon, RemoteRepository remoteRepository, String remotePath,
ManagedRepository repository, Path resource, Path tmpDirectory,
StorageAsset destFile)
throws ProxyException {
transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile.getFilePath());
@ -200,11 +200,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param ext the type of checksum to transfer (example: ".md5" or ".sha1")
* @throws ProxyException if copying the downloaded file into place did not succeed.
*/
protected void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, Path resource, String ext,
protected void transferChecksum( Wagon wagon, RemoteRepository remoteRepository, String remotePath,
ManagedRepository repository, Path resource, String ext,
Path destFile )
throws ProxyException {
String url = remoteRepository.getURL().getUrl() + remotePath + ext;
String url = remoteRepository.getLocation().toString() + remotePath + ext;
// Transfer checksum does not use the policy.
if (urlFailureCache.hasFailedBefore(url)) {
@ -239,8 +239,8 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @param origFile the local file to save to
* @throws ProxyException if there was a problem moving the downloaded file into place.
*/
protected void transferSimpleFile(Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, Path origFile, Path destFile)
protected void transferSimpleFile(Wagon wagon, RemoteRepository remoteRepository, String remotePath,
ManagedRepository repository, Path origFile, Path destFile)
throws ProxyException {
assert (remotePath != null);
@ -249,16 +249,16 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
boolean success = false;
if (!Files.exists(origFile)) {
log.debug("Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName());
wagon.get(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile());
log.debug("Retrieving {} from {}", remotePath, remoteRepository.getId());
wagon.get(addParameters(remotePath, remoteRepository), destFile.toFile());
success = true;
// You wouldn't get here on failure, a WagonException would have been thrown.
log.debug("Downloaded successfully.");
} else {
log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName());
log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getId());
try {
success = wagon.getIfNewer(addParameters(remotePath, remoteRepository.getRepository()), destFile.toFile(),
success = wagon.getIfNewer(addParameters(remotePath, remoteRepository), destFile.toFile(),
Files.getLastModifiedTime(origFile).toMillis());
} catch (IOException e) {
throw new ProxyException("Failed to the modification time of " + origFile.toAbsolutePath());
@ -274,13 +274,13 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
}
} catch (ResourceDoesNotExistException e) {
throw new NotFoundException(
"Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(),
"Resource [" + remoteRepository.getLocation() + "/" + remotePath + "] does not exist: " + e.getMessage(),
e);
} catch (WagonException e) {
// TODO: shouldn't have to drill into the cause, but TransferFailedException is often not descriptive enough
String msg =
"Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:" + e.getMessage();
"Download failure on resource [" + remoteRepository.getLocation() + "/" + remotePath + "]:" + e.getMessage();
if (e.getCause() != null) {
msg += " (cause: " + e.getCause() + ")";
}
@ -297,7 +297,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
* @return true if the connection was successful. false if not connected.
*/
protected boolean connectToRepository(ProxyConnector connector, Wagon wagon,
RemoteRepositoryContent remoteRepository) {
RemoteRepository remoteRepository) {
boolean connected = false;
final ProxyInfo networkProxy =
@ -307,7 +307,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
if (networkProxy != null) {
// TODO: move to proxyInfo.toString()
String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort()
+ " to connect to remote repository " + remoteRepository.getURL();
+ " to connect to remote repository " + remoteRepository.getLocation();
if (networkProxy.getNonProxyHosts() != null) {
msg += "; excluding hosts: " + networkProxy.getNonProxyHosts();
}
@ -321,7 +321,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
AuthenticationInfo authInfo = null;
String username = "";
String password = "";
RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials();
RepositoryCredentials repCred = remoteRepository.getLoginCredentials();
if (repCred != null && repCred instanceof PasswordCredentials) {
PasswordCredentials pwdCred = (PasswordCredentials) repCred;
username = pwdCred.getUsername();
@ -329,7 +329,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
}
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getURL());
log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getLocation());
authInfo = new AuthenticationInfo();
authInfo.setUserName(username);
authInfo.setPassword(password);
@ -337,7 +337,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
// Convert seconds to milliseconds
long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis();
long timeoutInMilliseconds = remoteRepository.getTimeout().toMillis();
// Set timeout read and connect
// FIXME olamy having 2 config values
@ -346,11 +346,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
try {
Repository wagonRepository =
new Repository(remoteRepository.getId(), remoteRepository.getURL().toString());
new Repository(remoteRepository.getId(), remoteRepository.getLocation().toString());
wagon.connect(wagonRepository, authInfo, networkProxy);
connected = true;
} catch (ConnectionException | AuthenticationException e) {
log.warn("Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage());
log.warn("Could not connect to {}: {}", remoteRepository.getId(), e.getMessage());
connected = false;
}
@ -370,4 +370,20 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler {
public List<RepositoryType> supports() {
return REPOSITORY_TYPES;
}
@Override
public void addNetworkproxy( String id, NetworkProxy networkProxy )
{
}
@Override
public <T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException
{
if (clazz.isAssignableFrom( this.getClass() )) {
return (T)this;
} else {
throw new IllegalArgumentException( "This Proxy Handler is no subclass of " + clazz );
}
}
}

View File

@ -63,6 +63,9 @@ public abstract class AbstractProxyTestCase
@Inject
protected ApplicationContext applicationContext;
@Inject
private ProxyRegistry proxyRegistry;
@Inject
RepositoryRegistry repositoryRegistry;
@ -152,14 +155,16 @@ public abstract class AbstractProxyTestCase
// Setup the proxy handler.
//proxyHandler = applicationContext.getBean (RepositoryProxyHandler) lookup( RepositoryProxyHandler.class.getName() );
proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyHandler.class );
proxyHandler = applicationContext.getBean( "repositoryProxyHandler#test", RepositoryProxyHandler.class );
assertNotNull( proxyRegistry );
assertTrue(proxyRegistry.getAllHandler( ).get( RepositoryType.MAVEN).contains( proxyHandler ));
// Setup the wagon mock.
wagonMockControl = EasyMock.createNiceControl();
wagonMock = wagonMockControl.createMock( Wagon.class );
delegate = (WagonDelegate) applicationContext.getBean( "wagon#test", Wagon.class );
delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class );
delegate.setDelegate( wagonMock );

View File

@ -67,8 +67,8 @@ public class CacheFailuresTransferTest
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default" );
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default" );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
@ -84,14 +84,14 @@ public class CacheFailuresTransferTest
wagonMockControl.replay();
//noinspection UnusedAssignment
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
// Second attempt to download same artifact use cache
wagonMockControl.reset();
wagonMockControl.replay();
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
assertNotDownloaded( downloadedFile);
@ -111,8 +111,8 @@ public class CacheFailuresTransferTest
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default" );
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default" );
// Configure Connector (usually done within archiva.xml configuration)
@ -126,7 +126,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay();
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
@ -138,7 +138,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay();
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
@ -170,7 +170,7 @@ public class CacheFailuresTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
// Validate that file actually came from proxied2 (as intended).
Path proxied2File = Paths.get( REPOPATH_PROXIED2, path );

View File

@ -64,7 +64,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNull( downloadedFile );
}
@ -86,7 +86,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -112,7 +112,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -138,7 +138,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -163,7 +163,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -188,7 +188,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -213,7 +213,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null );
@ -236,7 +236,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -262,7 +262,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null );
@ -285,7 +285,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
// This is a success situation. No SHA1 with a Good MD5.
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
@ -311,7 +311,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null );
@ -334,7 +334,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -361,7 +361,7 @@ public class ChecksumTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -387,7 +387,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -413,7 +413,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -436,7 +436,7 @@ public class ChecksumTransferTest
assertFalse( Files.exists(expectedFile.getParent()) );
assertFalse( Files.exists(expectedFile) );
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "http://bad.machine.com/repo/", "default" );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
@ -453,7 +453,7 @@ public class ChecksumTransferTest
wagonMockControl.replay();
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
@ -490,7 +490,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
@ -517,7 +517,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
@ -545,7 +545,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );

View File

@ -526,14 +526,14 @@ public class ErrorHandlingTest
private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy )
{
saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" );
saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
CachedFailuresPolicy.NO, errorPolicy, false );
}
private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy )
{
saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" );
saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
}
@ -596,7 +596,7 @@ public class ErrorHandlingTest
StorageAsset downloadedFile = null;
try
{
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toArtifactReference( path ) );
fail( "Proxy should not have succeeded" );
}
@ -637,7 +637,7 @@ public class ErrorHandlingTest
wagonMockControl.replay();
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toArtifactReference( path ) );
wagonMockControl.verify();

View File

@ -30,11 +30,16 @@ import org.apache.archiva.policies.PropagateErrorsDownloadPolicy;
import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.proxy.maven.DefaultWagonFactory;
import org.apache.archiva.proxy.maven.WagonFactory;
import org.apache.archiva.proxy.maven.WagonFactoryRequest;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.providers.http.HttpWagon;
import org.assertj.core.api.Assertions;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConnectionFactory;
@ -80,8 +85,6 @@ public class HttpProxyTransferTest
private RepositoryProxyHandler proxyHandler;
private ArchivaConfiguration config;
private ManagedRepositoryContent managedDefaultRepository;
@Inject
@ -90,6 +93,12 @@ public class HttpProxyTransferTest
@Inject
private RepositoryRegistry repositoryRegistry;
@Inject
private ArchivaConfiguration config;
@Inject
private ProxyRegistry proxyRegistry;
private Server server;
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout )
@ -104,9 +113,7 @@ public class HttpProxyTransferTest
public void setUp()
throws Exception
{
proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyHandler.class );
config = applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class );
proxyHandler = applicationContext.getBean( "repositoryProxyHandler#test", RepositoryProxyHandler.class );
// clear from previous tests - TODO the spring context should be initialised per test instead, or the config
// made a complete mock
@ -180,6 +187,11 @@ public class HttpProxyTransferTest
config.getConfiguration().addRemoteRepository( repoConfig );
Wagon wagon = new HttpWagon( );
WagonDelegate delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class );
delegate.setDelegate( wagon );
proxyRegistry.reload();
repositoryRegistry.reload();
managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
@ -208,10 +220,11 @@ public class HttpProxyTransferTest
addConnector();
Path expectedFile = Paths.get( managedDefaultRepository.getRepoRoot() ).resolve( path );
Files.deleteIfExists( expectedFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path sourceFile = Paths.get( PROXIED_BASEDIR, path );
assertNotNull( "Expected File should not be null.", expectedFile );

View File

@ -65,7 +65,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, true );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNull( "File should not have been downloaded", downloadedFile );
}
@ -87,7 +87,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), sourceFile );
@ -111,7 +111,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), path );
Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
assertNotNull(downloadedFile);
@ -147,7 +147,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), expectedFile );
assertNoTempFiles( expectedFile );
@ -181,7 +181,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), path );
assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, originalModificationTime );
@ -227,7 +227,7 @@ public class ManagedDefaultTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, originalModificationTime );
@ -272,7 +272,7 @@ public class ManagedDefaultTransferTest
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -304,7 +304,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -328,7 +328,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
@ -359,7 +359,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
@ -383,7 +383,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception",
downloadedFile );
@ -403,7 +403,8 @@ public class ManagedDefaultTransferTest
assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "" +
"http://bad.machine.com/repo/", "default" );
wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) );
EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" ) );
@ -414,7 +415,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
wagonMockControl.verify();
@ -436,8 +437,8 @@ public class ManagedDefaultTransferTest
assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "http://dead.machine.com/repo/", "default" );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied1", false );
@ -453,7 +454,7 @@ public class ManagedDefaultTransferTest
wagonMockControl.replay();
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );

View File

@ -128,7 +128,7 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@ -145,7 +145,7 @@ public class MetadataTransferTest
String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
setupTestableManagedRepository( requestedResource );
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
@ -991,7 +991,7 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@ -1017,7 +1017,7 @@ public class MetadataTransferTest
Path expectedFile = managedDefaultDir.resolve(requestedResource);
ProjectReference metadata = createProjectReference( requestedResource );
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@ -1038,7 +1038,7 @@ public class MetadataTransferTest
VersionedReference metadata = createVersionedReference( requestedResource );
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();
@ -1064,7 +1064,7 @@ public class MetadataTransferTest
Path expectedFile = managedDefaultDir.resolve(requestedResource);
VersionedReference metadata = createVersionedReference( requestedResource );
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
managedDefaultRepository.toMetadataPath(
metadata ) ).getFile();

View File

@ -91,6 +91,7 @@ public class MockConfiguration
registryListeners.add( listener );
}
@Override
public void removeChangeListener( RegistryListener listener )
{
@ -123,6 +124,10 @@ public class MockConfiguration
e.printStackTrace();
}
}
for (ConfigurationListener listener : configListeners) {
listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.CHANGED ) );
}
}
@Override

View File

@ -60,7 +60,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
@ -81,7 +81,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -104,7 +104,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -129,7 +129,7 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
// Attempt to download.
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
// Should not have downloaded as managed is newer than remote.
assertNotDownloaded( downloadedFile );
@ -221,7 +221,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
@ -245,7 +245,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, expectedTimestamp );
@ -271,7 +271,7 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -294,7 +294,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
@ -321,7 +321,7 @@ public class SnapshotTransferTest
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );

View File

@ -269,11 +269,11 @@ public class WagonDelegate
try
{
Files.createDirectories(destination.getParent());
if ( contentToGet == null )
if ( contentToGet == null && !Files.exists(destination))
{
Files.createFile(destination);
}
else
else if (contentToGet != null)
{
org.apache.archiva.common.utils.FileUtils.writeStringToFile(destination, Charset.defaultCharset(), contentToGet);
}
@ -283,4 +283,8 @@ public class WagonDelegate
throw new RuntimeException( e.getMessage(), e );
}
}
public void cleanup() {
}
}

View File

@ -50,11 +50,13 @@
<bean name="repositoryContentProvider#mocked" class="org.apache.archiva.repository.mock.RepositoryContentProviderMock" />
<bean name="repositoryProxyConnectors#test" class="org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler">
<bean name="repositoryProxyHandler#test" class="org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler">
<property name="archivaConfiguration" ref="archivaConfiguration#mock"/>
<property name="metadataTools" ref="metadataTools#mocked"/>
</bean>
<alias name="repositoryProxyHandler#test" alias="repositoryProxyHandler#maven"/>
<bean name="metadataTools#default" class="org.apache.archiva.repository.metadata.MetadataTools">
<property name="configuration" ref="archivaConfiguration#mock"/>
</bean>
@ -79,7 +81,7 @@
<property name="timeToLiveSeconds" value="1800"/>
</bean>
<bean name="wagon#test" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/>
<bean name="wagon#http" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/>
<bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
<alias name="userConfiguration#redback" alias="userConfiguration#default"/>

View File

@ -558,7 +558,7 @@ public class Maven2RepositoryStorage
}
@Override
public void applyServerSideRelocation(ManagedRepositoryContent managedRepository, ArtifactReference artifact)
public void applyServerSideRelocation(ManagedRepository managedRepository, ArtifactReference artifact)
throws ProxyDownloadException {
if ("pom".equals(artifact.getType())) {
return;
@ -571,7 +571,7 @@ public class Maven2RepositoryStorage
pomReference.setVersion(artifact.getVersion());
pomReference.setType("pom");
RepositoryType repositoryType = managedRepository.getRepository().getType();
RepositoryType repositoryType = managedRepository.getType();
if (!proxyRegistry.hasHandler(repositoryType)) {
throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
}
@ -582,7 +582,7 @@ public class Maven2RepositoryStorage
proxyHandler.fetchFromProxies(managedRepository, pomReference);
// Open and read the POM from the managed repo
StorageAsset pom = managedRepository.toFile(pomReference);
StorageAsset pom = managedRepository.getContent().toFile(pomReference);
if (!pom.exists()) {
return;

View File

@ -949,13 +949,13 @@ public class DefaultBrowseService
String path = managedRepositoryContent.toPath( archivaArtifact );
file = proxyHandler.fetchFromProxies( managedRepositoryContent, path );
file = proxyHandler.fetchFromProxies( managedRepositoryContent.getRepository(), path );
if ( file != null && file.exists() )
{
// download pom now
String pomPath = StringUtils.substringBeforeLast( path, ".jar" ) + ".pom";
proxyHandler.fetchFromProxies( managedRepositoryContent, pomPath );
proxyHandler.fetchFromProxies( managedRepositoryContent.getRepository(), pomPath );
return true;
}
}

View File

@ -28,6 +28,7 @@ import org.apache.archiva.metadata.repository.storage.*;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
@ -101,7 +102,7 @@ public class MockBeanServices
}
@Override
public void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
throws ProxyDownloadException
{

View File

@ -598,7 +598,7 @@ public class ArchivaDavResourceFactory
{
boolean previouslyExisted = repoAsset.exists();
boolean fromProxy = fetchContentFromProxies( managedRepositoryContent, request, logicalResource );
boolean fromProxy = fetchContentFromProxies( managedRepository, request, logicalResource );
StorageAsset resourceAsset=null;
// At this point the incoming request can either be in default or
@ -753,16 +753,16 @@ public class ArchivaDavResourceFactory
return resource;
}
private boolean fetchContentFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request,
private boolean fetchContentFromProxies( ManagedRepository managedRepository, DavServletRequest request,
LogicalResource resource )
throws DavException
{
String path = resource.getPath();
if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+managedRepository.getRepository().getType());
if (!proxyRegistry.hasHandler(managedRepository.getType())) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+managedRepository.getType());
}
RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRepository().getRequestInfo();
RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getRepository().getType()).get(0);
RepositoryRequestInfo repositoryRequestInfo = managedRepository.getRequestInfo();
RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getType()).get(0);
if ( repositoryRequestInfo.isSupportFile( path ) )
{
StorageAsset proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path );
@ -793,7 +793,7 @@ public class ArchivaDavResourceFactory
if ( artifact != null )
{
String repositoryLayout = managedRepository.getRepository().getLayout();
String repositoryLayout = managedRepository.getLayout();
RepositoryStorage repositoryStorage =
this.applicationContext.getBean( "repositoryStorage#" + repositoryLayout, RepositoryStorage.class );
@ -801,7 +801,7 @@ public class ArchivaDavResourceFactory
StorageAsset proxiedFile = proxyHandler.fetchFromProxies( managedRepository, artifact );
resource.setPath( managedRepository.toPath( artifact ) );
resource.setPath( managedRepository.getContent().toPath( artifact ) );
log.debug( "Proxied artifact '{}:{}:{}'", artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );

View File

@ -21,13 +21,11 @@ package org.apache.archiva.webdav;
import org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.io.FileUtils;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
class OverridingRepositoryProxyHandler
extends MavenRepositoryProxyHandler
@ -39,9 +37,9 @@ class OverridingRepositoryProxyHandler
}
@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath )
public ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath )
{
StorageAsset target = repository.getRepository().getAsset( logicalPath );
StorageAsset target = repository.getAsset( logicalPath );
try
{
FileUtils.copyFile( archivaDavResourceFactoryTest.getProjectBase().resolve( "target/test-classes/maven-metadata.xml" ).toFile(), target.getFilePath().toFile() );

View File

@ -25,6 +25,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.filter.Filter;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.xml.XMLException;
@ -70,7 +71,7 @@ public interface RepositoryStorage
* @param artifact the artifact reference
* @throws org.apache.archiva.policies.ProxyDownloadException
*/
void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
throws ProxyDownloadException;
/**

View File

@ -34,6 +34,7 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataN
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.archiva.xml.XMLException;
@ -105,7 +106,7 @@ public class MockRepositoryStorage
}
@Override
public void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
public void applyServerSideRelocation( ManagedRepository managedRepository, ArtifactReference artifact )
throws ProxyDownloadException
{