Search in sources :

Example 41 with HttpClient

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

the class HttpClientTest method testPut.

public void testPut() throws URISyntaxException, Exception {
    try (Processor p = new Processor()) {
        final AtomicBoolean done = new AtomicBoolean();
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(final String name, int size) {
                System.out.println("start " + 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);
                        done.set(true);
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        try (HttpClient c = new HttpClient()) {
            c.setRegistry(p);
            TaggedData go = c.build().verb("PUT").upload("hello").asTag().go(httpServer.getBaseURI("put"));
            go.getInputStream().close();
            assertEquals(200, go.getResponseCode());
            assertTrue(done.get());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Processor(aQute.bnd.osgi.Processor) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Example 42 with HttpClient

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

the class HttpClientTest method testModifiedWithEtag.

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

Example 43 with HttpClient

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

the class HttpClientTest method testFetch.

public void testFetch() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        String text = hc.build().get(String.class).go(httpServer.getBaseURI("get"));
        assertNotNull(text);
        assertTrue(text.startsWith("{"));
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient)

Example 44 with HttpClient

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

the class HttpClientTest method testNotModifiedSince.

public void testNotModifiedSince() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("*").ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/10000"));
        assertNotNull(data);
        assertEquals("1234", data.getTag());
        assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, data.getResponseCode());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Example 45 with HttpClient

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

the class HttpClientTest method testNotModifiedSinceAtSameTime.

public void testNotModifiedSinceAtSameTime() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("*").ifModifiedSince(20000).go(httpServer.getBaseURI("etag/1234/20000"));
        assertNotNull(data);
        assertEquals("1234", data.getTag());
        assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, data.getResponseCode());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

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