Search in sources :

Example 1 with RepositoryURL

use of org.apache.archiva.model.RepositoryURL in project archiva by apache.

the class RepositoryURLTest method assertURL.

private void assertURL(String actualURL, String protocol, String username, String password, String hostname, String port, String path) {
    RepositoryURL url = new RepositoryURL(actualURL);
    assertEquals(protocol, url.getProtocol());
    assertEquals(username, url.getUsername());
    assertEquals(password, url.getPassword());
    assertEquals(hostname, url.getHost());
    assertEquals(port, url.getPort());
    assertEquals(path, url.getPath());
}
Also used : RepositoryURL(org.apache.archiva.model.RepositoryURL)

Example 2 with RepositoryURL

use of org.apache.archiva.model.RepositoryURL in project archiva by apache.

the class DefaultRepositoryProxyConnectors method transferResources.

/**
 * @param connector
 * @param remoteRepository
 * @param tmpMd5
 * @param tmpSha1
 * @param tmpResource
 * @param url
 * @param remotePath
 * @param resource
 * @param workingDirectory
 * @param repository
 * @throws ProxyException
 * @throws NotModifiedException
 * @throws org.apache.archiva.admin.model.RepositoryAdminException
 */
protected void transferResources(ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5, Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource, Path workingDirectory, ManagedRepositoryContent repository) throws ProxyException, NotModifiedException, RepositoryAdminException {
    Wagon wagon = null;
    try {
        RepositoryURL repoUrl = remoteRepository.getURL();
        String protocol = repoUrl.getProtocol();
        NetworkProxy networkProxy = null;
        if (StringUtils.isNotBlank(connector.getProxyId())) {
            networkProxy = networkProxyAdmin.getNetworkProxy(connector.getProxyId());
        }
        WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getRepository().getExtraHeaders()).networkProxy(networkProxy);
        wagon = wagonFactory.getWagon(wagonFactoryRequest);
        if (wagon == null) {
            throw new ProxyException("Unsupported target repository protocol: " + protocol);
        }
        if (wagon == null) {
            throw new ProxyException("Unsupported target repository protocol: " + protocol);
        }
        boolean connected = connectToRepository(connector, wagon, remoteRepository);
        if (connected) {
            transferArtifact(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, tmpResource);
            // TODO: these should be used to validate the download based on the policies, not always downloaded
            // to
            // save on connections since md5 is rarely used
            transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".sha1", tmpSha1);
            transferChecksum(wagon, remoteRepository, remotePath, repository, resource, workingDirectory, ".md5", tmpMd5);
        }
    } catch (NotFoundException e) {
        urlFailureCache.cacheFailure(url);
        throw e;
    } catch (NotModifiedException e) {
        // Do not cache url here.
        throw e;
    } catch (ProxyException e) {
        urlFailureCache.cacheFailure(url);
        throw e;
    } catch (WagonFactoryException e) {
        throw new ProxyException(e.getMessage(), e);
    } finally {
        if (wagon != null) {
            try {
                wagon.disconnect();
            } catch (ConnectionException e) {
                log.warn("Unable to disconnect wagon.", e);
            }
        }
    }
}
Also used : WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) WagonFactoryException(org.apache.archiva.proxy.common.WagonFactoryException) Wagon(org.apache.maven.wagon.Wagon) RepositoryURL(org.apache.archiva.model.RepositoryURL) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) ConnectionException(org.apache.maven.wagon.ConnectionException)

Aggregations

RepositoryURL (org.apache.archiva.model.RepositoryURL)2 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)1 WagonFactoryException (org.apache.archiva.proxy.common.WagonFactoryException)1 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)1 ConnectionException (org.apache.maven.wagon.ConnectionException)1 Wagon (org.apache.maven.wagon.Wagon)1