use of org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin in project archiva by apache.
the class RepositoryServlet method initServers.
public synchronized void initServers(ServletConfig servletConfig) throws RepositoryAdminException {
long start = System.currentTimeMillis();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
configuration = wac.getBean("archivaConfiguration#default", ArchivaConfiguration.class);
configuration.addListener(this);
managedRepositoryAdmin = wac.getBean(ManagedRepositoryAdmin.class);
repositoryMap = managedRepositoryAdmin.getManagedRepositoriesAsMap();
for (ManagedRepository repo : repositoryMap.values()) {
Path repoDir = Paths.get(repo.getLocation());
if (!Files.exists(repoDir)) {
try {
Files.createDirectories(repoDir);
} catch (IOException e) {
log.info("Unable to create missing directory for {}", repo.getLocation());
continue;
}
}
}
resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
locatorFactory = new ArchivaDavLocatorFactory();
ServletAuthenticator servletAuth = wac.getBean(ServletAuthenticator.class);
HttpAuthenticator httpAuth = wac.getBean("httpAuthenticator#basic", HttpAuthenticator.class);
sessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
long end = System.currentTimeMillis();
log.debug("initServers done in {} ms", (end - start));
}
use of org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin in project archiva by apache.
the class HttpProxyTransferTest method setUp.
@Before
public void setUp() throws Exception {
proxyHandler = applicationContext.getBean("repositoryProxyConnectors#test", RepositoryProxyConnectors.class);
config = applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.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);
MavenManagedRepository repo = new MavenManagedRepository(MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent());
repo.setLocation(new URI(repoPath));
repo.setLayout("default");
RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
managedDefaultRepository = repoContent;
((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(config);
RepositoryRegistry managedRepositoryAdmin = applicationContext.getBean(RepositoryRegistry.class);
if (managedRepositoryAdmin.getManagedRepository(repo.getId()) == null) {
managedRepositoryAdmin.putRepository(repo);
}
// config.getConfiguration().addManagedRepository( repo );
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);
// 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);
}
Aggregations