use of org.apache.archiva.proxy.common.WagonFactoryException 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);
}
}
}
}
use of org.apache.archiva.proxy.common.WagonFactoryException in project archiva by apache.
the class MavenIndexManager method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
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());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
indexUpdater.fetchAndUpdateIndex(request);
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
use of org.apache.archiva.proxy.common.WagonFactoryException in project archiva by apache.
the class ArchivaIndexManagerMock method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
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());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
// indexUpdater.fetchAndUpdateIndex( request );
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
use of org.apache.archiva.proxy.common.WagonFactoryException in project archiva by apache.
the class ArchivaIndexManagerMock method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
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());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
// indexUpdater.fetchAndUpdateIndex( request );
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
Aggregations