001package org.apache.archiva.proxy.model; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.model.ArtifactReference; 023import org.apache.archiva.policies.Policy; 024import org.apache.archiva.policies.ProxyDownloadException; 025import org.apache.archiva.repository.ManagedRepository; 026import org.apache.archiva.repository.RepositoryType; 027import org.apache.archiva.repository.storage.StorageAsset; 028 029import java.util.List; 030import java.util.Map; 031 032/** 033 * A repository proxy handler is used to fetch remote artifacts from different remote repositories. 034 * A proxy handler is connected to one managed repository and a list of remote repositories. 035 * 036 * Repository proxies should not be confused with network proxies. Network are proxies for specific network protocols, 037 * like HTTP. A repository proxy delegates the repository requests to remote repositories and caches artifacts. 038 * 039 * If a artifact is requested for the managed repository and the artifact is not cached locally, the handler goes through 040 * the list of remotes and tries to download the artifact. If a download was successful the artifact is cached locally. 041 * 042 * The connection between managed and remote repositories is defined by list of {@link ProxyConnector} each defines a one-to-one relationship. 043 * 044 * A proxy connector defines specifics about the download behaviour: 045 * <ul> 046 * <li>Policies {@link org.apache.archiva.policies.Policy} define the behaviour for different cases (errors, not available, caching lifetime).</li> 047 * <li>Black- and Whitelists are used to ban or allow certain paths on the remote repositories. 048 * </ul> 049 * 050 * The policies and black- and whitelist are set on the {@link ProxyConnector} 051 * 052 * There may be network proxies needed to connect the remote repositories. 053 * 054 */ 055public interface RepositoryProxyHandler 056{ 057 058 List<RepositoryType> supports( ); 059 060 /** 061 * Performs the artifact fetch operation against the target repositories 062 * of the provided source repository. 063 * <p> 064 * If the artifact is found, it is downloaded and placed into the source repository 065 * filesystem. 066 * 067 * @param repository the source repository to use. (must be a managed repository) 068 * @param artifact the artifact to fetch. 069 * @return the file that was obtained, or null if no content was obtained 070 * @throws ProxyDownloadException if there was a problem fetching the content from the target repositories. 071 */ 072 StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact ) 073 throws ProxyDownloadException; 074 075 /** 076 * Performs the metadata fetch operation against the target repositories 077 * of the provided source repository. 078 * <p> 079 * If the metadata is found, it is downloaded and placed into the source repository 080 * filesystem. 081 * 082 * @param repository the source repository to use. (must be a managed repository) 083 * @param logicalPath the metadata to fetch. 084 * @return the file that was obtained, or null if no content was obtained 085 */ 086 ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath ); 087 088 /** 089 * Performs the fetch operation against the target repositories 090 * of the provided source repository by a specific path. 091 * 092 * @param managedRepository the source repository to use. (must be a managed repository) 093 * @param path the path of the resource to fetch 094 * @return the file that was obtained, or null if no content was obtained 095 */ 096 StorageAsset fetchFromProxies( ManagedRepository managedRepository, String path ); 097 098 /** 099 * Get the List of {@link ProxyConnector} objects of the source repository. 100 * 101 * @param repository the source repository to look for. 102 * @return the List of {@link ProxyConnector} objects. 103 */ 104 List<ProxyConnector> getProxyConnectors( ManagedRepository repository ); 105 106 /** 107 * Tests to see if the provided repository is a source repository for 108 * any {@link ProxyConnector} objects. 109 * 110 * @param repository the source repository to look for. 111 * @return true if there are proxy connectors that use the provided 112 * repository as a source repository. 113 */ 114 boolean hasProxies( ManagedRepository repository ); 115 116 /** 117 * Sets network proxies (normally HTTP proxies) to access the remote repositories. 118 * 119 * @param networkProxies A map of (repository id, network proxy) where the repository id must be the id of an 120 * existing remote repository. 121 */ 122 void setNetworkProxies( Map<String, NetworkProxy> networkProxies ); 123 124 /** 125 * Adds a network proxy that is used to access the remote repository. 126 * 127 * @param id The repository id 128 * @param networkProxy The network proxy to use 129 */ 130 void addNetworkproxy( String id, NetworkProxy networkProxy); 131 132 /** 133 * Returns a map of the defined network proxies, or a empty map, if no proxy is defined. 134 * 135 * @return A map (repository id, network proxy). If none is defined, a empty map is returned. 136 */ 137 Map<String, NetworkProxy> getNetworkProxies( ); 138 139 /** 140 * Returns the network proxy that is defined for the given repository id. 141 * @param id The remote repository id 142 * @return A network proxy or <code>null</code> if no one is defined for this id. 143 */ 144 NetworkProxy getNetworkProxy( String id ); 145 146 /** 147 * Returns the proxy handler implementation. This can be used, if the underlying implementation for a specific 148 * repository type is needed. 149 * 150 * @param clazz The class to convert to 151 * @param <T> The type 152 * @return The handler 153 */ 154 <T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException; 155 156 /** 157 * Sets the policies that this handler should validate. 158 * @param policyList 159 */ 160 void setPolicies(List<Policy> policyList); 161 162 /** 163 * Adds a policy 164 * @param policy 165 */ 166 void addPolicy( Policy policy ); 167 168 /** 169 * Removes a policy 170 * @param policy 171 */ 172 void removePolicy( Policy policy ); 173 174 void addProxyConnector(ProxyConnector connector); 175 176 void setProxyConnectors( List<ProxyConnector> proxyConnectors ); 177}