Search in sources :

Example 6 with HttpClient

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

the class CentralTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    tmpName = "generated/tmp/test/" + getName();
    local = IO.getFile(tmpName + "/local");
    reporter.setTrace(true);
    Config config = new Config();
    IO.delete(local);
    local.mkdirs();
    repo = MavenRemoteRepository.create(REPO_URL, reporter, local, new HttpClient());
    storage = new MavenRepository(local, "central", this.repo, null, null, null, null);
}
Also used : Config(aQute.http.testservers.HttpTestServer.Config) HttpClient(aQute.bnd.http.HttpClient)

Example 7 with HttpClient

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

the class MavenBndRepoTest method config.

void config(Map<String, String> override) throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put("local", tmpName + "/local");
    config.put("index", tmpName + "/index");
    config.put("releaseUrl", fnx.getBaseURI() + "/repo/");
    if (override != null)
        config.putAll(override);
    reporter = new Processor();
    reporter.addBasicPlugin(new ProgressPlugin() {

        @Override
        public Task startTask(final String name, int size) {
            System.out.println("Starting " + name);
            return new Task() {

                @Override
                public void worked(int units) {
                    System.out.println("Worked " + name + " " + units);
                }

                @Override
                public void done(String message, Throwable e) {
                    System.out.println("Done " + name + " " + message + " " + e);
                }

                @Override
                public boolean isCanceled() {
                    return false;
                }
            };
        }
    });
    HttpClient client = new HttpClient();
    client.setRegistry(reporter);
    Executor executor = Executors.newCachedThreadPool();
    reporter.addBasicPlugin(client);
    reporter.setTrace(true);
    repo = new MavenBndRepository();
    repo.setReporter(reporter);
    repo.setRegistry(reporter);
    repo.setProperties(config);
}
Also used : Processor(aQute.bnd.osgi.Processor) Executor(java.util.concurrent.Executor) HashMap(java.util.HashMap) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient)

Example 8 with HttpClient

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

the class HttpClientProxyTest method assertSocks5Proxy.

@SuppressWarnings("resource")
void assertSocks5Proxy(String password, boolean authenticationCalled) throws MalformedURLException, Exception {
    Processor p = new Processor();
    p.setProperty("-connectionsettings", "" + false);
    HttpClient hc = new HttpClient();
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    if (socks5Proxy != null) {
        ProxyDTO proxy = new ProxyDTO();
        proxy.active = true;
        proxy.host = "localhost";
        proxy.port = socksProxyPort;
        proxy.protocol = Type.SOCKS;
        if (password != null) {
            proxy.username = "proxyuser";
            proxy.password = password;
        }
        hc.addProxyHandler(ConnectionSettings.createProxyHandler(proxy));
    }
    ServerDTO server = new ServerDTO();
    server.id = httpTestServer.getBaseURI().toString();
    server.verify = false;
    server.trust = Strings.join(httpTestServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    URL url = new URL(httpTestServer.getBaseURI() + "/get-tag/ABCDEFGH");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    assertEquals("ABCDEFGH", tag.getTag());
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
// assertTrue(this.authenticationCalled.get() == authenticationCalled);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Example 9 with HttpClient

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

the class HttpClientTest method testCachingMultipleFetch.

public void testCachingMultipleFetch() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        hc.setCache(tmp);
        Promise<TaggedData> a = hc.build().useCache().age(1, TimeUnit.DAYS).asTag().async(httpServer.getBaseURI("mftch"));
        Thread.sleep(100);
        Promise<TaggedData> b = hc.build().useCache().age(1, TimeUnit.DAYS).asTag().async(httpServer.getBaseURI("mftch"));
        TaggedData ta = a.getValue();
        assertEquals("FOO", ta.getTag());
        assertEquals(200, ta.getResponseCode());
        assertEquals(true, ta.hasPayload());
        assertEquals(true, ta.isOk());
        assertEquals(State.UPDATED, ta.getState());
        TaggedData tb = b.getValue();
        assertEquals("FOO", tb.getTag());
        assertEquals(304, tb.getResponseCode());
        assertEquals(false, tb.hasPayload());
        assertEquals(State.UNMODIFIED, tb.getState());
        System.out.println(a.getValue());
        System.out.println(b.getValue());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Example 10 with HttpClient

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

the class HttpClientCacheTest method testGetNewThenUnmodifiedThenModified.

public void testGetNewThenUnmodifiedThenModified() throws URISyntaxException, Exception {
    try (HttpClient client = new HttpClient()) {
        client.setCache(cache);
        // Set a tag, but it must always fetch the file
        etag = "1234";
        File go1 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
        assertTrue(go1.isFile());
        assertEquals("1234", IO.collect(go1));
        // Set time very old so we can see if the file is updated
        go1.setLastModified(1000);
        File go2 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
        assertEquals(go1, go2);
        assertEquals("1234", IO.collect(go1));
        assertEquals(1000, go2.lastModified());
        // New tag (i.e. file is updated on server) but we use the stale
        // period to NOT fetch a new one
        etag = "5678";
        go1.setLastModified(System.currentTimeMillis());
        File go3 = client.build().useCache(10000).go(new URI(httpServer.getBaseURI() + "/testetag"));
        assertEquals(go1, go3);
        assertEquals("1234", IO.collect(go3));
        // We have a stale copy, see if we fetch a new copy
        File go4 = client.build().useCache().go(new URI(httpServer.getBaseURI() + "/testetag"));
        assertEquals(go1, go4);
        assertEquals("5678", IO.collect(go3));
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) File(java.io.File) URI(java.net.URI)

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