Search in sources :

Example 1 with Repository

use of org.apache.maven.wagon.repository.Repository in project intellij-community by JetBrains.

the class Maven3ServerIndexFetcher method connect.

@Override
public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
    ArtifactRepository artifactRepository = myRepositorySystem.createArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null, null, null);
    final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(artifactRepository);
    String mirrorUrl = mirrorRepository.getUrl();
    String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
    Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
    try {
        myWagon = myWagonManager.getWagon(repository);
        myWagon.addTransferListener(myListener);
        myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
    } catch (AuthenticationException e) {
        IOException newEx = new IOException("Authentication exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    } catch (WagonException e) {
        IOException newEx = new IOException("Wagon exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    }
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) WagonException(org.apache.maven.wagon.WagonException)

Example 2 with Repository

use of org.apache.maven.wagon.repository.Repository in project intellij-community by JetBrains.

the class Maven2ServerIndexFetcher method connect.

public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
    final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(new DefaultArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null));
    String mirrorUrl = mirrorRepository.getUrl();
    String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
    Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
    try {
        myWagon = myWagonManager.getWagon(repository);
        myWagon.addTransferListener(myListener);
        myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
    } catch (AuthenticationException e) {
        IOException newEx = new IOException("Authentication exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    } catch (WagonException e) {
        IOException newEx = new IOException("Wagon exception connecting to " + repository);
        newEx.initCause(e);
        throw newEx;
    }
}
Also used : DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) WagonException(org.apache.maven.wagon.WagonException)

Example 3 with Repository

use of org.apache.maven.wagon.repository.Repository in project fabric8 by jboss-fuse.

the class ConfigurableHttpWagon method execute.

@Override
protected CloseableHttpResponse execute(HttpUriRequest httpMethod) throws HttpException, IOException {
    setHeaders(httpMethod);
    String userAgent = getUserAgent(httpMethod);
    if (userAgent != null) {
        httpMethod.setHeader(HTTP.USER_AGENT, userAgent);
    }
    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
    // WAGON-273: default the cookie-policy to browser compatible
    requestConfigBuilder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
    Repository repo = getRepository();
    ProxyInfo proxyInfo = getProxyInfo(repo.getProtocol(), repo.getHost());
    if (proxyInfo != null) {
        HttpHost proxy = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
        requestConfigBuilder.setProxy(proxy);
    }
    HttpMethodConfiguration config = getHttpConfiguration() == null ? null : getHttpConfiguration().getMethodConfiguration(httpMethod);
    if (config != null) {
        copyConfig(config, requestConfigBuilder);
    } else {
        requestConfigBuilder.setSocketTimeout(getReadTimeout());
        requestConfigBuilder.setConnectTimeout(getTimeout());
    }
    getLocalContext().setRequestConfig(requestConfigBuilder.build());
    if (config != null && config.isUsePreemptive()) {
        HttpHost targetHost = new HttpHost(repo.getHost(), repo.getPort(), repo.getProtocol());
        AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
        if (getCredentialsProvider().getCredentials(targetScope) != null) {
            BasicScheme targetAuth = new BasicScheme();
            targetAuth.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC preemptive"));
            getAuthCache().put(targetHost, targetAuth);
        }
    }
    if (proxyInfo != null) {
        if (proxyInfo.getHost() != null) {
            HttpHost proxyHost = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
            AuthScope proxyScope = getProxyBasicAuthScope().getScope(proxyHost);
            String proxyUsername = proxyInfo.getUserName();
            String proxyPassword = proxyInfo.getPassword();
            String proxyNtlmHost = proxyInfo.getNtlmHost();
            String proxyNtlmDomain = proxyInfo.getNtlmDomain();
            if (proxyUsername != null && proxyPassword != null) {
                Credentials creds;
                if (proxyNtlmHost != null || proxyNtlmDomain != null) {
                    creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain);
                } else {
                    creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
                }
                getCredentialsProvider().setCredentials(proxyScope, creds);
                BasicScheme proxyAuth = new BasicScheme();
                proxyAuth.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC preemptive"));
                getAuthCache().put(proxyHost, proxyAuth);
            }
        }
    }
    return client.execute(httpMethod, getLocalContext());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpMethodConfiguration(org.apache.maven.wagon.providers.http.HttpMethodConfiguration) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicHeader(org.apache.http.message.BasicHeader) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 4 with Repository

use of org.apache.maven.wagon.repository.Repository in project archiva by apache.

the class DefaultRepositoryProxyConnectors method connectToRepository.

/**
 * Using wagon, connect to the remote repository.
 *
 * @param connector        the connector configuration to utilize (for obtaining network proxy configuration from)
 * @param wagon            the wagon instance to establish the connection on.
 * @param remoteRepository the remote repository to connect to.
 * @return true if the connection was successful. false if not connected.
 */
private boolean connectToRepository(ProxyConnector connector, Wagon wagon, RemoteRepositoryContent remoteRepository) {
    boolean connected = false;
    final ProxyInfo networkProxy = connector.getProxyId() == null ? null : this.networkProxyMap.get(connector.getProxyId());
    if (log.isDebugEnabled()) {
        if (networkProxy != null) {
            // TODO: move to proxyInfo.toString()
            String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort() + " to connect to remote repository " + remoteRepository.getURL();
            if (networkProxy.getNonProxyHosts() != null) {
                msg += "; excluding hosts: " + networkProxy.getNonProxyHosts();
            }
            if (StringUtils.isNotBlank(networkProxy.getUserName())) {
                msg += "; as user: " + networkProxy.getUserName();
            }
            log.debug(msg);
        }
    }
    AuthenticationInfo authInfo = null;
    String username = "";
    String password = "";
    RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials();
    if (repCred != null && repCred instanceof PasswordCredentials) {
        PasswordCredentials pwdCred = (PasswordCredentials) repCred;
        username = pwdCred.getUsername();
        password = pwdCred.getPassword() == null ? "" : new String(pwdCred.getPassword());
    }
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
        log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getURL());
        authInfo = new AuthenticationInfo();
        authInfo.setUserName(username);
        authInfo.setPassword(password);
    }
    // Convert seconds to milliseconds
    long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis();
    // Set timeout  read and connect
    // FIXME olamy having 2 config values
    wagon.setReadTimeout((int) timeoutInMilliseconds);
    wagon.setTimeout((int) timeoutInMilliseconds);
    try {
        Repository wagonRepository = new Repository(remoteRepository.getId(), remoteRepository.getURL().toString());
        wagon.connect(wagonRepository, authInfo, networkProxy);
        connected = true;
    } catch (ConnectionException | AuthenticationException e) {
        log.warn("Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage());
        connected = false;
    }
    return connected;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) Repository(org.apache.maven.wagon.repository.Repository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 5 with Repository

use of org.apache.maven.wagon.repository.Repository in project archiva by apache.

the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.

@Override
public Boolean checkRemoteConnectivity(String repositoryId) throws ArchivaRestServiceException {
    try {
        RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId);
        if (remoteRepository == null) {
            log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId);
            return Boolean.FALSE;
        }
        NetworkProxy networkProxy = null;
        if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) {
            networkProxy = networkProxyAdmin.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId());
            if (networkProxy == null) {
                log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", remoteRepository.getRemoteDownloadNetworkProxyId());
            }
        }
        String wagonProtocol = new URL(remoteRepository.getUrl()).getProtocol();
        final Wagon wagon = wagonFactory.getWagon(// 
        new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
        // hardcoded value as it's a check of the remote repo connectivity
        wagon.setReadTimeout(checkReadTimeout);
        wagon.setTimeout(checkTimeout);
        if (wagon instanceof AbstractHttpClientWagon) {
            HttpMethodConfiguration httpMethodConfiguration = // 
            new HttpMethodConfiguration().setUsePreemptive(// 
            true).setReadTimeout(checkReadTimeout);
            HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration);
            AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
        }
        ProxyInfo proxyInfo = null;
        if (networkProxy != null) {
            proxyInfo = new ProxyInfo();
            proxyInfo.setType(networkProxy.getProtocol());
            proxyInfo.setHost(networkProxy.getHost());
            proxyInfo.setPort(networkProxy.getPort());
            proxyInfo.setUserName(networkProxy.getUsername());
            proxyInfo.setPassword(networkProxy.getPassword());
        }
        String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/");
        wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo);
        // MRM-1933, there are certain servers that do not allow browsing
        if (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || "/".equals(remoteRepository.getCheckPath()))) {
            return wagon.resourceExists(remoteRepository.getCheckPath());
        } else {
            // we only check connectivity as remote repo can be empty
            // MRM-1909: Wagon implementation appends a slash already
            wagon.getFileList("");
        }
        return Boolean.TRUE;
    } catch (TransferFailedException e) {
        log.info("TransferFailedException :{}", e.getMessage());
        return Boolean.FALSE;
    } catch (Exception e) {
        // This service returns either true or false, Exception cannot be handled by the clients
        log.debug("Exception occured on connectivity test.", e);
        log.info("Connection exception: {}", e.getMessage());
        return Boolean.FALSE;
    }
}
Also used : AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) Wagon(org.apache.maven.wagon.Wagon) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) URL(java.net.URL) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Aggregations

Repository (org.apache.maven.wagon.repository.Repository)13 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)5 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)5 IOException (java.io.IOException)4 Wagon (org.apache.maven.wagon.Wagon)4 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)4 Path (java.nio.file.Path)3 ConnectionException (org.apache.maven.wagon.ConnectionException)3 TransferFailedException (org.apache.maven.wagon.TransferFailedException)3 WagonException (org.apache.maven.wagon.WagonException)3 File (java.io.File)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)2 RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)2 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 UnsupportedProtocolException (org.apache.maven.wagon.UnsupportedProtocolException)2