use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class ProxyConnectorConfigurationOrderComparatorTest method createConnector.
private ProxyConnectorConfiguration createConnector(String id, int order) {
ProxyConnectorConfiguration proxy = new ProxyConnectorConfiguration();
proxy.setProxyId(id);
proxy.setOrder(order);
proxy.setSourceRepoId(id + "_m");
proxy.setTargetRepoId(id + "_r");
return proxy;
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class AbstractRepositoryServletProxiedTestCase method setupConnector.
private void setupConnector(String repoId, RemoteRepoInfo remoteRepo, String releasesPolicy, String snapshotsPolicy) {
ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
connector.setSourceRepoId(repoId);
connector.setTargetRepoId(remoteRepo.id);
connector.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, releasesPolicy);
connector.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotsPolicy);
connector.addPolicy(ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORE);
connector.addPolicy(ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO);
archivaConfiguration.getConfiguration().addProxyConnector(connector);
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class HttpProxyTransferTest method addConnector.
private void addConnector() {
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setProxyId(PROXY_ID);
connectorConfig.setSourceRepoId(MANAGED_ID);
connectorConfig.setTargetRepoId(PROXIED_ID);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.FIX);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ONCE);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.ONCE);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS, PropagateErrorsDownloadPolicy.QUEUE);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS_ON_UPDATE, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT);
int count = config.getConfiguration().getProxyConnectors().size();
config.getConfiguration().addProxyConnector(connectorConfig);
// Proper Triggering ...
String prefix = "proxyConnectors.proxyConnector(" + count + ")";
((MockConfiguration) config).triggerChange(prefix + ".sourceRepoId", connectorConfig.getSourceRepoId());
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration 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.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class RepositoryServletProxiedPluginSnapshotPolicyTest method assertGetProxiedSnapshotsArtifactWithPolicy.
private void assertGetProxiedSnapshotsArtifactWithPolicy(int expectation, String snapshotsPolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
// --- Setup
setupSnapshotsRemoteRepo();
setupCleanInternalRepo();
String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar";
String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents";
String expectedManagedContents = null;
Path remoteFile = populateRepo(remoteSnapshots, resourcePath, expectedRemoteContents);
if (hasManagedCopy) {
expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents";
Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
}
archivaConfiguration.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>(0));
setupSnapshotConnector(REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy);
saveConfiguration();
// --- Execution
// process the response code later, not via an exception.
// HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + resourcePath);
WebResponse response = getServletUnitClient().getResponse(request);
switch(expectation) {
case EXPECT_MANAGED_CONTENTS:
assertResponseOK(response);
assertTrue("Invalid Test Case: Can't expect managed contents with " + "test that doesn't have a managed copy in the first place.", hasManagedCopy);
assertEquals("Expected managed file contents", expectedManagedContents, response.getContentAsString());
break;
case EXPECT_REMOTE_CONTENTS:
assertResponseOK(response);
assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
break;
case EXPECT_NOT_FOUND:
assertResponseNotFound(response);
assertManagedFileNotExists(repoRootInternal, resourcePath);
break;
}
}
Aggregations