Search in sources :

Example 11 with ProxyConnectorConfiguration

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;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 12 with ProxyConnectorConfiguration

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);
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 13 with ProxyConnectorConfiguration

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());
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 14 with ProxyConnectorConfiguration

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);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) Configuration(org.apache.archiva.configuration.Configuration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector)

Example 15 with ProxyConnectorConfiguration

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;
    }
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Aggregations

ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)23 Configuration (org.apache.archiva.configuration.Configuration)9 ArrayList (java.util.ArrayList)7 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)4 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)4 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.ProxyConnectorRuleConfiguration)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)4 Path (java.nio.file.Path)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)3 WagonFactory (org.apache.archiva.proxy.common.WagonFactory)3 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)3 Wagon (org.apache.maven.wagon.Wagon)3 Before (org.junit.Before)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)2 HashMap (java.util.HashMap)1 List (java.util.List)1