Search in sources :

Example 21 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class HttpClientTest method testRedirect.

public void testRedirect() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData tag = hc.build().get(TaggedData.class).go(httpServer.getBaseURI("redirect/3/200"));
        assertNotNull(tag);
        assertEquals(200, tag.getResponseCode());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Example 22 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class HttpClientTest method testMultipleProgressPlugins.

public void testMultipleProgressPlugins() throws Exception {
    final long deadline = System.currentTimeMillis() + 1000L;
    try (HttpClient hc = new HttpClient()) {
        Processor p = new Processor();
        final int[] counts = new int[2];
        counts[0] = counts[1] = 0;
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(String name, int size) {
                return new Task() {

                    @Override
                    public void worked(int units) {
                        counts[0]++;
                    }

                    @Override
                    public void done(String message, Throwable e) {
                        counts[0]++;
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(String name, int size) {
                return new Task() {

                    @Override
                    public void worked(int units) {
                        counts[1]++;
                    }

                    @Override
                    public void done(String message, Throwable e) {
                        counts[1]++;
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        hc.setRegistry(p);
        String text = hc.build().get(String.class).go(httpServer.getBaseURI("get"));
        assertNotNull(text);
        assertTrue(counts[0] > 0);
        assertEquals(counts[0], counts[1]);
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient)

Example 23 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class HttpClientTest method testETag.

public void testETag() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).go(httpServer.getBaseURI("etag/1234/0"));
        assertNotNull(data);
        assertEquals("1234", data.getTag());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Example 24 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class P2Repository method getP2Index0.

P2Indexer getP2Index0() {
    this.workspace = registry.getPlugin(Workspace.class);
    HttpClient client = registry.getPlugin(HttpClient.class);
    URI url = config.url();
    if (url == null)
        throw new IllegalArgumentException("For a p2 repository you must set the url parameter to the repository");
    try {
        name = config.name(client.toName(url));
        File location = workspace.getFile(config.location("cnf/cache/p2-" + name));
        IO.mkdirs(location);
        File indexFile = new File(location, "index.xml.gz");
        return new P2Indexer(reporter, location, client, url, name);
    } catch (Exception e) {
        throw Exceptions.duck(e);
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) URI(java.net.URI) File(java.io.File) IOException(java.io.IOException) Workspace(aQute.bnd.build.Workspace)

Example 25 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class BndPomRepository method init.

public synchronized void init() {
    try {
        if (inited)
            return;
        inited = true;
        Workspace workspace = registry.getPlugin(Workspace.class);
        HttpClient client = registry.getPlugin(HttpClient.class);
        File localRepo = IO.getFile(configuration.local(MAVEN_REPO_LOCAL));
        File location = workspace.getFile(getLocation());
        List<MavenBackingRepository> release = MavenBackingRepository.create(configuration.releaseUrls(), reporter, localRepo, client);
        List<MavenBackingRepository> snapshot = MavenBackingRepository.create(configuration.snapshotUrls(), reporter, localRepo, client);
        MavenRepository repository = new MavenRepository(localRepo, name, release, snapshot, Processor.getExecutor(), reporter, null);
        boolean transitive = configuration.transitive(true);
        if (pomFiles != null) {
            repoImpl = new PomRepository(repository, client, location, transitive).uris(pomFiles);
        } else if (revisions != null) {
            repoImpl = new PomRepository(repository, client, location, transitive).revisions(revisions);
        } else if (query != null) {
            repoImpl = new SearchRepository(repository, location, query, queryUrl, workspace, client, transitive);
        } else {
            repository.close();
            throw new IllegalStateException("We have neither a pom, revision, or query set!");
        }
        bridge = new BridgeRepository(repoImpl);
    } catch (Exception e) {
        throw Exceptions.duck(e);
    }
}
Also used : BridgeRepository(aQute.bnd.osgi.repository.BridgeRepository) MavenBackingRepository(aQute.maven.provider.MavenBackingRepository) MavenRepository(aQute.maven.provider.MavenRepository) HttpClient(aQute.bnd.http.HttpClient) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Aggregations

HttpClient (aQute.bnd.http.HttpClient)46 TaggedData (aQute.bnd.service.url.TaggedData)18 File (java.io.File)14 Processor (aQute.bnd.osgi.Processor)13 URI (java.net.URI)9 ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)6 Version (aQute.bnd.version.Version)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HashMap (java.util.HashMap)6 ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)5 Workspace (aQute.bnd.build.Workspace)4 ServerDTO (aQute.bnd.connection.settings.ServerDTO)4 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)4 Config (aQute.http.testservers.HttpTestServer.Config)4 Resource (org.osgi.resource.Resource)4 Jar (aQute.bnd.osgi.Jar)3 Slf4jReporter (aQute.libg.reporter.slf4j.Slf4jReporter)3 MavenRepository (aQute.maven.provider.MavenRepository)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3