Search in sources :

Example 1 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException in project gradle by gradle.

the class RepositoryTransportDeployWagon method get.

@Override
public final void get(String resourceName, File destination) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    this.transferEventSupport.fireTransferInitiated(transferEvent(resource, TRANSFER_INITIATED, REQUEST_GET));
    this.transferEventSupport.fireTransferStarted(transferEvent(resource, TRANSFER_STARTED, REQUEST_GET));
    try {
        if (!destination.exists()) {
            destination.getParentFile().mkdirs();
            destination.createNewFile();
        }
        if (!getDelegate().getRemoteFile(destination, resourceName)) {
            throw new ResourceDoesNotExistException(String.format("Resource '%s' does not exist", resourceName));
        }
        this.transferEventSupport.fireTransferCompleted(transferEvent(resource, TRANSFER_COMPLETED, REQUEST_GET));
    } catch (ResourceDoesNotExistException e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_GET));
        throw e;
    } catch (Exception e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_GET));
        throw new TransferFailedException(String.format("Could not get resource '%s'", resourceName), e);
    }
}
Also used : Resource(org.apache.maven.wagon.resource.Resource) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) IOException(java.io.IOException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) GradleException(org.gradle.api.GradleException) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 2 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException in project archiva by apache.

the class MetadataTransferTest method testFetchFromTwoProxiesWhenFirstConnectionFails.

// TODO: same test for other fetch* methods
@Test
public void testFetchFromTwoProxiesWhenFirstConnectionFails() throws Exception {
    // Project metadata that does not exist locally, but has multiple versions in remote repos
    String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
    setupTestableManagedRepository(requestedResource);
    saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default");
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    assertResourceNotFound(requestedResource);
    assertNoRepoMetadata("badproxied1", requestedResource);
    assertNoRepoMetadata(ID_PROXIED2, requestedResource);
    // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
    Path expectedFile = managedDefaultDir.resolve(metadataTools.getRepositorySpecificName("badproxied1", requestedResource));
    wagonMock.get(EasyMock.eq(requestedResource), EasyMock.anyObject(File.class));
    EasyMock.expectLastCall().andThrow(new TransferFailedException("can't connect"));
    wagonMockControl.replay();
    assertFetchProjectOrGroup(requestedResource);
    wagonMockControl.verify();
    assertProjectMetadataContents(requestedResource, new String[] { "1.0.1" }, "1.0.1", "1.0.1");
    assertNoRepoMetadata("badproxied1", requestedResource);
    assertRepoProjectMetadata(ID_PROXIED2, requestedResource, new String[] { "1.0.1" });
}
Also used : Path(java.nio.file.Path) File(java.io.File) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Test(org.junit.Test)

Example 3 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException 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)

Example 4 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException in project maven-plugins by apache.

the class AbstractDeployMojo method configureWagon.

/**
 * Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
 *
 * @param wagon
 * @param repositoryId
 * @param settings
 * @param container
 * @param log
 * @throws TransferFailedException
 * @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
 */
private static void configureWagon(Wagon wagon, String repositoryId, Settings settings, PlexusContainer container, Log log) throws TransferFailedException {
    log.debug(" configureWagon ");
    // MSITE-25: Make sure that the server settings are inserted
    for (Server server : settings.getServers()) {
        String id = server.getId();
        log.debug("configureWagon server " + id);
        if (id != null && id.equals(repositoryId) && (server.getConfiguration() != null)) {
            final PlexusConfiguration plexusConf = new XmlPlexusConfiguration((Xpp3Dom) server.getConfiguration());
            ComponentConfigurator componentConfigurator = null;
            try {
                componentConfigurator = (ComponentConfigurator) container.lookup(ComponentConfigurator.ROLE, "basic");
                if (isMaven3OrMore()) {
                    componentConfigurator.configureComponent(wagon, plexusConf, container.getContainerRealm());
                } else {
                    configureWagonWithMaven2(componentConfigurator, wagon, plexusConf, container);
                }
            } catch (final ComponentLookupException e) {
                throw new TransferFailedException("While configuring wagon for \'" + repositoryId + "\': Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e);
            } catch (ComponentConfigurationException e) {
                throw new TransferFailedException("While configuring wagon for \'" + repositoryId + "\': Unable to apply wagon configuration.", e);
            } finally {
                if (componentConfigurator != null) {
                    try {
                        container.release(componentConfigurator);
                    } catch (ComponentLifecycleException e) {
                        log.error("Problem releasing configurator - ignoring: " + e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Server(org.apache.maven.settings.Server) ComponentConfigurator(org.codehaus.plexus.component.configurator.ComponentConfigurator) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ComponentLifecycleException(org.codehaus.plexus.component.repository.exception.ComponentLifecycleException) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 5 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException in project maven-plugins by apache.

the class AbstractDeployMojo method deploy.

private void deploy(final File directory, final Repository repository) throws MojoExecutionException {
    // TODO: work on moving this into the deployer like the other deploy methods
    final Wagon wagon = getWagon(repository, wagonManager);
    try {
        configureWagon(wagon, repository.getId(), settings, container, getLog());
    } catch (TransferFailedException e) {
        throw new MojoExecutionException("Unable to configure Wagon: '" + repository.getProtocol() + "'", e);
    }
    try {
        final ProxyInfo proxyInfo;
        if (!isMaven3OrMore()) {
            proxyInfo = getProxyInfo(repository, wagonManager);
        } else {
            try {
                SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class);
                proxyInfo = getProxy(repository, settingsDecrypter);
            } catch (ComponentLookupException cle) {
                throw new MojoExecutionException("Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle);
            }
        }
        push(directory, repository, wagon, proxyInfo, getLocales(), getDeployModuleDirectory());
        if (chmod) {
            chmod(wagon, repository, chmodOptions, chmodMode);
        }
    } finally {
        try {
            wagon.disconnect();
        } catch (ConnectionException e) {
            getLog().error("Error disconnecting wagon - ignored", e);
        }
    }
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) Wagon(org.apache.maven.wagon.Wagon) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ConnectionException(org.apache.maven.wagon.ConnectionException)

Aggregations

TransferFailedException (org.apache.maven.wagon.TransferFailedException)9 ConnectionException (org.apache.maven.wagon.ConnectionException)5 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)4 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)4 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)4 File (java.io.File)3 Wagon (org.apache.maven.wagon.Wagon)3 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)3 Resource (org.apache.maven.wagon.resource.Resource)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)2 Debug (org.apache.maven.wagon.observers.Debug)2 Repository (org.apache.maven.wagon.repository.Repository)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1