use of org.apache.archiva.proxy.base.ProxyException in project archiva by apache.
the class MavenRepositoryProxyHandler method transferResources.
/**
* @param connector
* @param remoteRepository
* @param tmpResource
* @param checksumFiles
* @param url
* @param remotePath
* @param resource
* @param workingDirectory
* @param repository
* @throws ProxyException
* @throws NotModifiedException
*/
@Override
protected void transferResources(ProxyConnector connector, RemoteRepository remoteRepository, StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource, Path workingDirectory, ManagedRepository repository) throws ProxyException, NotModifiedException {
Wagon wagon = null;
try {
URI repoUrl = remoteRepository.getLocation();
String protocol = repoUrl.getScheme();
NetworkProxy networkProxy = null;
String proxyId = connector.getProxyId();
if (StringUtils.isNotBlank(proxyId)) {
networkProxy = getNetworkProxy(proxyId);
}
WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getExtraHeaders());
if (networkProxy == null) {
log.warn("No network proxy with id {} found for connector {}->{}", proxyId, connector.getSourceRepository().getId(), connector.getTargetRepository().getId());
} else {
wagonFactoryRequest = wagonFactoryRequest.networkProxy(networkProxy);
}
wagon = wagonFactory.getWagon(wagonFactoryRequest);
if (wagon == null) {
throw new ProxyException("Unsupported target repository protocol: " + protocol);
}
boolean connected = connectToRepository(connector, wagon, remoteRepository);
if (connected) {
transferArtifact(wagon, remoteRepository, remotePath, resource.getFilePath(), tmpResource);
// save on connections since md5 is rarely used
for (StorageAsset checksumFile : checksumFiles) {
String ext = "." + StringUtils.substringAfterLast(checksumFile.getName(), ".");
transferChecksum(wagon, remoteRepository, remotePath, resource.getFilePath(), ext, checksumFile.getFilePath());
}
}
} 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);
}
}
}
}
use of org.apache.archiva.proxy.base.ProxyException in project archiva by apache.
the class MavenRepositoryProxyHandler method transferSimpleFile.
/**
* Perform the transfer of the remote file to the local file specified.
*
* @param wagon the wagon instance to use.
* @param remoteRepository the remote repository to use
* @param remotePath the remote path to attempt to get
* @param origFile the local file to save to
* @throws ProxyException if there was a problem moving the downloaded file into place.
*/
protected void transferSimpleFile(Wagon wagon, RemoteRepository remoteRepository, String remotePath, Path origFile, Path destFile) throws ProxyException {
assert (remotePath != null);
// Transfer the file.
try {
if (!Files.exists(origFile)) {
log.debug("Retrieving {} from {}", remotePath, remoteRepository.getId());
wagon.get(addParameters(remotePath, remoteRepository), destFile.toFile());
// You wouldn't get here on failure, a WagonException would have been thrown.
log.debug("Downloaded successfully.");
} else {
boolean success;
log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getId());
try {
success = wagon.getIfNewer(addParameters(remotePath, remoteRepository), destFile.toFile(), Files.getLastModifiedTime(origFile).toMillis());
} catch (IOException e) {
throw new ProxyException("Failed to the modification time of " + origFile.toAbsolutePath());
}
if (!success) {
throw new NotModifiedException("Not downloaded, as local file is newer than remote side: " + origFile.toAbsolutePath());
}
if (Files.exists(destFile)) {
log.debug("Downloaded successfully.");
}
}
} catch (ResourceDoesNotExistException e) {
throw new NotFoundException("Resource [" + remoteRepository.getLocation() + "/" + remotePath + "] does not exist: " + e.getMessage(), e);
} catch (WagonException e) {
// TODO: shouldn't have to drill into the cause, but TransferFailedException is often not descriptive enough
String msg = "Download failure on resource [" + remoteRepository.getLocation() + "/" + remotePath + "]:" + e.getMessage();
if (e.getCause() != null) {
msg += " (cause: " + e.getCause() + ")";
}
throw new ProxyException(msg, e);
}
}
Aggregations