Search in sources :

Example 16 with HttpClient

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

the class SettingsParserTest method testMavenEncryptedPassword.

public void testMavenEncryptedPassword() throws Exception {
    System.setProperty(ConnectionSettings.M2_SETTINGS_SECURITY_PROPERTY, "testresources/settings-security.xml");
    Processor proc = new Processor();
    proc.setProperty("-connection-settings", "testresources/server-maven-encrypted-selection.xml");
    try (ConnectionSettings cs = new ConnectionSettings(proc, new HttpClient())) {
        cs.readSettings();
        List<ServerDTO> serverDTOs = cs.getServerDTOs();
        assertEquals(1, serverDTOs.size());
        ServerDTO s = serverDTOs.get(0);
        assertEquals("encrypted-password", s.id);
        assertEquals("FOOBAR", s.password);
    }
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings)

Example 17 with HttpClient

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

the class HttpClientTest method testRedirectURL.

public void testRedirectURL() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        HttpsVerification httpsVerification = new HttpsVerification(httpsServer.getCertificateChain(), false, hc.getReporter());
        hc.addURLConnectionHandler(httpsVerification);
        URI uri = httpsServer.getBaseURI("get");
        URL go = httpServer.getBaseURI("xlocation").toURL();
        TaggedData tag = hc.build().maxRedirects(3).get(TaggedData.class).headers("XLocation", uri.toString()).go(go);
        assertNotNull(tag);
        assertEquals(200, tag.getResponseCode());
    }
}
Also used : HttpsVerification(aQute.bnd.url.HttpsVerification) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) URI(java.net.URI) URL(java.net.URL)

Example 18 with HttpClient

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

the class HttpClientTest method testNotModifiedEtag.

public void testNotModifiedEtag() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        TaggedData data = hc.build().get(TaggedData.class).ifNoneMatch("1234").go(httpServer.getBaseURI("etag/1234/0"));
        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 19 with HttpClient

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

the class HttpClientTest method testCancel.

public void testCancel() throws Exception {
    final long deadline = System.currentTimeMillis() + 1000L;
    try (HttpClient hc = new HttpClient()) {
        Processor p = new Processor();
        p.addBasicPlugin(new ProgressPlugin() {

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

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

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

                    @Override
                    public boolean isCanceled() {
                        System.out.println("Cancel check ");
                        return System.currentTimeMillis() > deadline;
                    }
                };
            }
        });
        hc.setRegistry(p);
        TaggedData tag = hc.build().asTag().go(httpServer.getBaseURI("timeout/50"));
        assertNotNull(tag);
        assertEquals(200, tag.getResponseCode());
        try {
            String s = IO.collect(tag.getInputStream());
            fail();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) URISyntaxException(java.net.URISyntaxException)

Example 20 with HttpClient

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

the class HttpClientTest method testTimeout.

public void testTimeout() throws Exception {
    try (HttpClient hc = new HttpClient()) {
        try {
            TaggedData tag = hc.build().asTag().timeout(1000).go(httpServer.getBaseURI("timeout/10"));
            assertNotNull(tag);
            assertEquals(200, tag.getResponseCode());
            IO.collect(tag.getInputStream());
            fail();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) URISyntaxException(java.net.URISyntaxException)

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