Search in sources :

Example 1 with URLConnector

use of aQute.bnd.service.url.URLConnector in project bnd by bndtools.

the class AbstractIndexedRepo method init.

protected final synchronized void init(boolean ignoreCachedFile) throws Exception {
    if (!initialised) {
        clear();
        // Load the available providers from the workspace plugins.
        loadAllContentProviders();
        // Load the request repository content providers, if specified
        if (requestedContentProviderList != null && requestedContentProviderList.length() > 0) {
            generatingProviders.clear();
            // Find the requested providers from the available ones.
            StringTokenizer tokenizer = new StringTokenizer(requestedContentProviderList, "|");
            while (tokenizer.hasMoreTokens()) {
                String token = tokenizer.nextToken().trim();
                IRepositoryContentProvider provider = allContentProviders.get(token);
                if (provider == null) {
                    warning("Unknown repository content provider \"%s\".", token);
                } else {
                    generatingProviders.add(provider);
                }
            }
            if (generatingProviders.isEmpty()) {
                warning("No valid repository index generators were found, requested list was: [%s]", requestedContentProviderList);
            }
        }
        // Initialise index locations
        indexLocations = loadIndexes();
        // Create the callback for new referral and resource objects
        final URLConnector connector = getConnector();
        IRepositoryIndexProcessor processor = new IRepositoryIndexProcessor() {

            public void processResource(Resource resource) {
                identityMap.put(resource);
                capabilityIndex.addResource(resource);
            }

            public void processReferral(URI parentUri, Referral referral, int maxDepth, int currentDepth) {
                try {
                    URI indexLocation = new URI(referral.getUrl());
                    try {
                        CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
                        indexHandle.setReporter(reporter);
                        InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexHandle.request()));
                        readIndex(indexLocation.getPath(), indexLocation, indexStream, allContentProviders.values(), this, logService);
                    } catch (Exception e) {
                        warning("Unable to read referral index at URL '%s' from parent index '%s': %s", indexLocation, parentUri, e);
                    }
                } catch (URISyntaxException e) {
                    warning("Invalid referral URL '%s' from parent index '%s': %s", referral.getUrl(), parentUri, e);
                }
            }
        };
        // Parse the indexes
        for (URI indexLocation : indexLocations) {
            try {
                CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
                // OR 2) online is false
                if (indexHandle.cachedFile != null && !ignoreCachedFile && ((System.currentTimeMillis() - indexHandle.cachedFile.lastModified() < this.cacheTimeoutSeconds * 1000) || !this.online)) {
                    indexHandle.sha = indexHandle.getCachedSHA();
                    if (indexHandle.sha != null && !this.online) {
                        System.out.println(String.format("Offline. Using cached %s.", indexLocation));
                    }
                }
                indexHandle.setReporter(reporter);
                File indexFile = indexHandle.request();
                InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexFile));
                readIndex(indexFile.getName(), indexLocation, indexStream, allContentProviders.values(), processor, logService);
            } catch (Exception e) {
                error("Unable to read index at URL '%s': %s", indexLocation, e);
            }
        }
        initialised = true;
    }
}
Also used : IRepositoryIndexProcessor(aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor) InputStream(java.io.InputStream) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector) URLConnector(aQute.bnd.service.url.URLConnector) Resource(org.osgi.resource.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) StringTokenizer(java.util.StringTokenizer) Referral(aQute.bnd.deployer.repository.api.Referral) IRepositoryContentProvider(aQute.bnd.deployer.repository.api.IRepositoryContentProvider) File(java.io.File)

Example 2 with URLConnector

use of aQute.bnd.service.url.URLConnector in project bnd by bndtools.

the class IndexedReposWithComms method testBasicWorkspace.

public void testBasicWorkspace() throws Exception {
    HttpTestServer ht = http();
    try {
        createSecureSocks5();
        Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/basic"));
        assertNotNull(ws);
        List<URLConnector> connectors = ws.getPlugins(URLConnector.class);
        assertNotNull(connectors);
        assertEquals(1, connectors.size());
        assertTrue(connectors.get(0) instanceof HttpClient);
        HttpClient hc = (HttpClient) connectors.get(0);
        InputStream connect = hc.connect(new URL(ht.getBaseURI() + "/basic-auth/user/good"));
        assertNotNull(connect);
        aQute.lib.io.IO.copy(connect, System.out);
        connect.close();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        ht.close();
    }
}
Also used : InputStream(java.io.InputStream) HttpClient(aQute.bnd.http.HttpClient) URLConnector(aQute.bnd.service.url.URLConnector) HttpTestServer(aQute.http.testservers.HttpTestServer) URL(java.net.URL) CloseSessionException(sockslib.server.listener.CloseSessionException) IOException(java.io.IOException) AuthenticationException(sockslib.common.AuthenticationException) Workspace(aQute.bnd.build.Workspace)

Example 3 with URLConnector

use of aQute.bnd.service.url.URLConnector in project bnd by bndtools.

the class AbstractIndexedRepo method getConnector.

/**
	 * @return the class to use for URL connections. It's retrieved from the
	 *         registry under the URLConnector class, or it will be the
	 *         DefaultURLConnector if the former was not found.
	 */
private URLConnector getConnector() {
    URLConnector connector;
    synchronized (this) {
        connector = registry != null ? registry.getPlugin(URLConnector.class) : null;
    }
    if (connector == null) {
        DefaultURLConnector defaultConnector = new DefaultURLConnector();
        defaultConnector.setRegistry(registry);
        connector = defaultConnector;
    }
    return connector;
}
Also used : DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector) URLConnector(aQute.bnd.service.url.URLConnector) DefaultURLConnector(aQute.bnd.deployer.http.DefaultURLConnector)

Aggregations

URLConnector (aQute.bnd.service.url.URLConnector)3 DefaultURLConnector (aQute.bnd.deployer.http.DefaultURLConnector)2 InputStream (java.io.InputStream)2 Workspace (aQute.bnd.build.Workspace)1 IRepositoryContentProvider (aQute.bnd.deployer.repository.api.IRepositoryContentProvider)1 IRepositoryIndexProcessor (aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor)1 Referral (aQute.bnd.deployer.repository.api.Referral)1 HttpClient (aQute.bnd.http.HttpClient)1 HttpTestServer (aQute.http.testservers.HttpTestServer)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 StringTokenizer (java.util.StringTokenizer)1 Resource (org.osgi.resource.Resource)1 AuthenticationException (sockslib.common.AuthenticationException)1 CloseSessionException (sockslib.server.listener.CloseSessionException)1