use of org.apache.archiva.admin.model.beans.RemoteRepository 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.archiva.admin.model.beans.RemoteRepository in project archiva by apache.
the class RemoteRepositoriesServiceTest method listRemoteRepositoriesKarma.
@Test
public void listRemoteRepositoriesKarma() throws Exception {
RemoteRepositoriesService service = getRemoteRepositoriesService();
WebClient.client(service).header("Authorization", authorizationHeader);
WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
List<RemoteRepository> repos = service.getRemoteRepositories();
assertFalse(repos.isEmpty());
log.info("repos {}", repos);
}
use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.
the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.
@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
String indexBase = indexBaseDir.toString();
FileUtils.deleteQuietly(indexBaseDir);
if (!Files.exists(indexBaseDir)) {
Files.createDirectories(indexBaseDir);
}
String id = Long.toString(System.currentTimeMillis());
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(indexBase + "/index-" + id);
managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + id);
ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RepositoriesService repositoriesService = getRepositoriesService();
repositoriesService.scanRepositoryNow(id, true);
// wait a bit to ensure index is finished
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
Thread.sleep(500);
timeout -= 500;
}
RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
String repoGroupId = "test-group";
if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
repositoryGroupService.deleteRepositoryGroup(repoGroupId);
}
RepositoryGroup repositoryGroup = new RepositoryGroup();
repositoryGroup.setId(repoGroupId);
String path = ".fooooo";
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroup.setMergedIndexPath(path);
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
managedRepository.setIndexDirectory(indexBaseDir + "/index-" + id);
managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
String remoteId = Long.toString(System.currentTimeMillis());
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId(remoteId);
remoteRepository.setName(remoteId);
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar2");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId(remoteId);
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
// wait the end
while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
Thread.sleep(500);
log.debug("still running remote download");
}
SearchService searchService = getSearchService();
SearchRequest request = new SearchRequest();
request.setRepositories(Arrays.asList(id));
request.setGroupId("org.apache.felix");
List<Artifact> artifacts = searchService.searchArtifacts(request);
assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.
the class RemoteRepositoryConnectivityCheckTest method checkRemoteConnectivity.
@Test
public void checkRemoteConnectivity() throws Exception {
Server repoServer = buildStaticServer(Paths.get(System.getProperty("basedir"), "src/test/repositories/test-repo"));
ServerConnector serverConnector = new ServerConnector(repoServer, new HttpConnectionFactory());
repoServer.addConnector(serverConnector);
repoServer.start();
RemoteRepositoriesService service = getRemoteRepositoriesService();
WebClient.client(service).header("Authorization", authorizationHeader);
try {
int repoServerPort = serverConnector.getLocalPort();
RemoteRepository repo = getRemoteRepository();
repo.setUrl("http://localhost:" + repoServerPort);
service.addRemoteRepository(repo);
assertThat(service.checkRemoteConnectivity(repo.getId())).isTrue();
} finally {
service.deleteRemoteRepository("id-new");
repoServer.stop();
}
}
use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.
the class DownloadRemoteIndexTaskTest method getRemoteRepository.
protected RemoteRepository getRemoteRepository() throws IOException {
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
Path indexDirectory = Paths.get(FileUtils.getBasedir(), "target/index/test-" + Long.toString(System.currentTimeMillis()));
Files.createDirectories(indexDirectory);
indexDirectory.toFile().deleteOnExit();
remoteRepository.setName("foo");
remoteRepository.setIndexDirectory(indexDirectory.toAbsolutePath().toString());
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setId("test-repo-re");
remoteRepository.setUrl("http://localhost:" + port);
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/index-updates/");
return remoteRepository;
}
Aggregations