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);
}
}
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" });
}
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;
}
}
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());
}
}
}
}
}
}
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);
}
}
}
Aggregations