use of org.apache.archiva.proxy.model.ProxyConnector in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchFromProxies.
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact) throws ProxyDownloadException {
Path localFile = toLocalFile(repository, artifact);
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "artifact");
requestProperties.setProperty("version", artifact.getVersion());
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
Map<String, Exception> previousExceptions = new LinkedHashMap<>();
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = targetRepository.toPath(artifact);
if (SystemUtils.IS_OS_WINDOWS) {
// toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
targetPath = FilenameUtils.separatorsToUnix(targetPath);
}
try {
Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, true);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Artifact {} not found on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (NotModifiedException e) {
log.debug("Artifact {} not updated on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
} catch (ProxyException | RepositoryAdminException e) {
validatePolicies(this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, targetRepository, localFile, e, previousExceptions);
}
}
if (!previousExceptions.isEmpty()) {
throw new ProxyDownloadException("Failures occurred downloading from some remote repositories", previousExceptions);
}
log.debug("Exhausted all target repositories, artifact {} not found.", Keys.toKey(artifact));
return null;
}
use of org.apache.archiva.proxy.model.ProxyConnector in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchMetadataFromProxies.
@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath) {
Path localFile = Paths.get(repository.getRepoRoot(), logicalPath);
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "metadata");
boolean metadataNeedsUpdating = false;
long originalTimestamp = getLastModified(localFile);
List<ProxyConnector> connectors = new ArrayList<>(getProxyConnectors(repository));
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
Path localRepoFile = toLocalRepoFile(repository, targetRepository, logicalPath);
long originalMetadataTimestamp = getLastModified(localRepoFile);
try {
transferFile(connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties, true);
if (hasBeenUpdated(localRepoFile, originalMetadataTimestamp)) {
metadataNeedsUpdating = true;
}
} catch (NotFoundException e) {
log.debug("Metadata {} not found on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
} catch (NotModifiedException e) {
log.debug("Metadata {} not updated on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
} catch (ProxyException | RepositoryAdminException e) {
log.warn("Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), logicalPath, e.getMessage());
log.debug("Full stack trace", e);
}
}
if (hasBeenUpdated(localFile, originalTimestamp)) {
metadataNeedsUpdating = true;
}
if (metadataNeedsUpdating || !Files.exists(localFile)) {
try {
metadataTools.updateMetadata(repository, logicalPath);
} catch (RepositoryMetadataException e) {
log.warn("Unable to update metadata {}:{}", localFile.toAbsolutePath(), e.getMessage(), e);
}
}
if (fileExists(localFile)) {
return new ProxyFetchResult(localFile, metadataNeedsUpdating);
}
return new ProxyFetchResult(null, false);
}
use of org.apache.archiva.proxy.model.ProxyConnector in project archiva by apache.
the class DefaultRepositoryProxyConnectors method initConnectorsAndNetworkProxies.
@SuppressWarnings("unchecked")
private void initConnectorsAndNetworkProxies() {
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.getContent());
RemoteRepository rRepo = repositoryRegistry.getRemoteRepository(proxyConfig.getTargetRepoId());
if (rRepo == null) {
log.error("Cannot find target repository after config change " + proxyConfig.getSourceRepoId());
continue;
}
connector.setTargetRepository(rRepo.getContent());
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);
}
this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = archivaConfiguration.getConfiguration().getNetworkProxies();
for (NetworkProxyConfiguration networkProxyConfig : networkProxies) {
String key = networkProxyConfig.getId();
ProxyInfo proxy = new ProxyInfo();
proxy.setType(networkProxyConfig.getProtocol());
proxy.setHost(networkProxyConfig.getHost());
proxy.setPort(networkProxyConfig.getPort());
proxy.setUserName(networkProxyConfig.getUsername());
proxy.setPassword(networkProxyConfig.getPassword());
this.networkProxyMap.put(key, proxy);
}
}
use of org.apache.archiva.proxy.model.ProxyConnector in project archiva by apache.
the class DefaultRepositoryProxyConnectors method fetchFromProxies.
@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, String path) {
Path localFile = Paths.get(repository.getRepoRoot(), path);
// no update policies for these paths
if (Files.exists(localFile)) {
return null;
}
Properties requestProperties = new Properties();
requestProperties.setProperty("filetype", "resource");
requestProperties.setProperty("managedRepositoryId", repository.getId());
List<ProxyConnector> connectors = getProxyConnectors(repository);
for (ProxyConnector connector : connectors) {
if (connector.isDisabled()) {
continue;
}
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
String targetPath = path;
try {
Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, false);
if (fileExists(downloadedFile)) {
log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
return downloadedFile;
}
} catch (NotFoundException e) {
log.debug("Resource {} not found on repository \"{}\".", path, targetRepository.getRepository().getId());
} catch (NotModifiedException e) {
log.debug("Resource {} not updated on repository \"{}\".", path, targetRepository.getRepository().getId());
} catch (ProxyException e) {
log.warn("Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage());
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository \"{}" + "\" for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
} catch (RepositoryAdminException e) {
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Full stack trace", e);
}
}
log.debug("Exhausted all target repositories, resource {} not found.", path);
return null;
}
Aggregations