use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class AbstractRepositoryServletTestCase method createRemoteRepository.
protected RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String url) {
RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
repo.setId(id);
repo.setName(name);
repo.setUrl(url);
return repo;
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RepositoryProviderMock method getRemoteConfiguration.
@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId(remoteRepository.getId());
configuration.setName(remoteRepository.getName());
configuration.setDescription(remoteRepository.getDescription());
configuration.setLayout(remoteRepository.getLayout());
configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
configuration.setCheckPath(remoteRepository.getCheckPath());
configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
configuration.setExtraParameters(remoteRepository.getExtraParameters());
configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
if (creds != null) {
PasswordCredentials pwdCreds = (PasswordCredentials) creds;
configuration.setUsername(pwdCreds.getUsername());
configuration.setPassword(new String(pwdCreds.getPassword()));
}
configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
return configuration;
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class HttpProxyTransferTest method setUp.
@Before
public void setUp() throws Exception {
proxyHandler = applicationContext.getBean("repositoryProxyHandler#test", RepositoryProxyHandler.class);
// clear from previous tests - TODO the spring context should be initialised per test instead, or the config
// made a complete mock
config.getConfiguration().getProxyConnectors().clear();
// Setup source repository (using default layout)
String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
Path destRepoDir = Paths.get(repoPath);
// Cleanout destination dirs.
if (Files.exists(destRepoDir)) {
FileUtils.deleteDirectory(destRepoDir.toFile());
}
// Make the destination dir.
Files.createDirectories(destRepoDir);
Handler handler = new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
};
server = new Server();
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory());
server.addConnector(serverConnector);
server.setHandler(handler);
server.start();
int port = serverConnector.getLocalPort();
NetworkProxyConfiguration proxyConfig = new NetworkProxyConfiguration();
proxyConfig.setHost("localhost");
proxyConfig.setPort(port);
proxyConfig.setProtocol("http");
proxyConfig.setId(PROXY_ID);
config.getConfiguration().addNetworkProxy(proxyConfig);
((MockConfiguration) config).triggerChange("networkProxies.networkProxy(0).host", "localhost");
// Setup target (proxied to) repository.
RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
repoConfig.setId(PROXIED_ID);
repoConfig.setName("Proxied Repository 1");
repoConfig.setLayout("default");
repoConfig.setUrl("http://www.example.com/");
config.getConfiguration().addRemoteRepository(repoConfig);
Wagon wagon = new HttpWagon();
WagonDelegate delegate = (WagonDelegate) applicationContext.getBean("wagon#http", Wagon.class);
delegate.setDelegate(wagon);
proxyRegistry.reload();
repositoryRegistry.reload();
managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class MavenRepositoryProvider method getRemoteConfiguration.
@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
if (!(remoteRepository instanceof MavenRemoteRepository)) {
log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
}
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
cfg.setType(remoteRepository.getType().toString());
cfg.setId(remoteRepository.getId());
cfg.setName(remoteRepository.getName());
cfg.setDescription(remoteRepository.getDescription());
cfg.setUrl(remoteRepository.getLocation().toString());
cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
cfg.setCheckPath(remoteRepository.getCheckPath());
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
if (creds != null) {
if (creds instanceof PasswordCredentials) {
PasswordCredentials pCreds = (PasswordCredentials) creds;
cfg.setPassword(new String(pCreds.getPassword()));
cfg.setUsername(pCreds.getUsername());
}
}
cfg.setLayout(remoteRepository.getLayout());
cfg.setExtraParameters(remoteRepository.getExtraParameters());
cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class);
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class);
if (remoteIndexFeature.getIndexUri() == null) {
cfg.setRemoteIndexUrl("");
} else {
cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
}
cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
if (StringUtils.isEmpty(remoteIndexFeature.getProxyId())) {
cfg.setRemoteDownloadNetworkProxyId("");
} else {
cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
}
return cfg;
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandler method newInstancesFromConfig.
@Override
public Map<String, RemoteRepository> newInstancesFromConfig() {
try {
List<RemoteRepositoryConfiguration> remoteRepoConfigs = new ArrayList<>(getConfigurationHandler().getBaseConfiguration().getRemoteRepositories());
if (remoteRepoConfigs == null) {
return Collections.emptyMap();
}
Map<String, RemoteRepository> result = new HashMap<>();
for (RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs) {
RemoteRepository repo = newInstance(repoConfig);
result.put(repo.getId(), repo);
}
return result;
} catch (Throwable e) {
log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
return new HashMap<>();
}
}
Aggregations