Search in sources :

Example 1 with ConnectionSettings

use of aQute.bnd.connection.settings.ConnectionSettings 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 2 with ConnectionSettings

use of aQute.bnd.connection.settings.ConnectionSettings in project bnd by bndtools.

the class HttpClientProxyTest method assertHttpProxy.

@SuppressWarnings("resource")
void assertHttpProxy(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 (httpProxy != null) {
        ProxyDTO proxy = new ProxyDTO();
        proxy.active = true;
        proxy.host = "localhost";
        proxy.port = httpProxyPort;
        proxy.protocol = Type.HTTP;
        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);
    if (tag.getState() != State.OTHER)
        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 3 with ConnectionSettings

use of aQute.bnd.connection.settings.ConnectionSettings 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 4 with ConnectionSettings

use of aQute.bnd.connection.settings.ConnectionSettings in project bnd by bndtools.

the class HttpClientServerTest method assertOk.

@SuppressWarnings("resource")
private void assertOk(String password, boolean verify) throws Exception {
    File log = new File(tmp, "log");
    Processor p = new Processor();
    p.setProperty("-connection-log", log.toURI().getPath());
    HttpClient hc = new HttpClient();
    hc.setLog(log);
    ConnectionSettings cs = new ConnectionSettings(p, hc);
    ServerDTO server = new ServerDTO();
    server.id = httpServer.getBaseURI().toString();
    server.verify = verify;
    if (password != null) {
        server.username = "user";
        server.password = password;
    }
    server.trust = Strings.join(httpServer.getTrustedCertificateFiles(IO.getFile("generated")));
    cs.add(server);
    System.out.println(httpServer.getBaseURI());
    URL url = password == null ? new URL(httpServer.getBaseURI() + "/get") : new URL(httpServer.getBaseURI() + "/basic-auth/user/good");
    TaggedData tag = hc.connectTagged(url);
    assertNotNull(tag);
    String s = IO.collect(tag.getInputStream());
    assertNotNull(s);
    assertTrue(s.trim().startsWith("{"));
    IO.copy(log, System.out);
}
Also used : ServerDTO(aQute.bnd.connection.settings.ServerDTO) Processor(aQute.bnd.osgi.Processor) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData) File(java.io.File) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) URL(java.net.URL)

Example 5 with ConnectionSettings

use of aQute.bnd.connection.settings.ConnectionSettings in project bnd by bndtools.

the class Workspace method setTypeSpecificPlugins.

@Override
protected void setTypeSpecificPlugins(Set<Object> list) {
    try {
        super.setTypeSpecificPlugins(list);
        list.add(this);
        list.add(maven);
        list.add(settings);
        if (!isTrue(getProperty(NOBUILDINCACHE))) {
            list.add(new CachedFileRepo());
        }
        resourceRepositoryImpl = new ResourceRepositoryImpl();
        resourceRepositoryImpl.setCache(IO.getFile(getProperty(CACHEDIR, "~/.bnd/caches/shas")));
        resourceRepositoryImpl.setExecutor(getExecutor());
        resourceRepositoryImpl.setIndexFile(getFile(getBuildDir(), "repo.json"));
        resourceRepositoryImpl.setURLConnector(new MultiURLConnectionHandler(this));
        customize(resourceRepositoryImpl, null);
        list.add(resourceRepositoryImpl);
        //
        // Exporters
        //
        list.add(new SubsystemExporter());
        try {
            HttpClient client = new HttpClient();
            client.setOffline(getOffline());
            client.setRegistry(this);
            try (ConnectionSettings cs = new ConnectionSettings(this, client)) {
                cs.readSettings();
            }
            list.add(client);
        } catch (Exception e) {
            exception(e, "Failed to load the communication settings");
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ResourceRepositoryImpl(aQute.bnd.resource.repository.ResourceRepositoryImpl) SubsystemExporter(aQute.bnd.exporter.subsystem.SubsystemExporter) HttpClient(aQute.bnd.http.HttpClient) MultiURLConnectionHandler(aQute.bnd.url.MultiURLConnectionHandler) ConnectionSettings(aQute.bnd.connection.settings.ConnectionSettings) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Aggregations

ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)5 HttpClient (aQute.bnd.http.HttpClient)5 ServerDTO (aQute.bnd.connection.settings.ServerDTO)4 Processor (aQute.bnd.osgi.Processor)4 TaggedData (aQute.bnd.service.url.TaggedData)3 URL (java.net.URL)3 ProxyDTO (aQute.bnd.connection.settings.ProxyDTO)2 SubsystemExporter (aQute.bnd.exporter.subsystem.SubsystemExporter)1 ResourceRepositoryImpl (aQute.bnd.resource.repository.ResourceRepositoryImpl)1 MultiURLConnectionHandler (aQute.bnd.url.MultiURLConnectionHandler)1 File (java.io.File)1 IOException (java.io.IOException)1 TimeLimitExceededException (javax.naming.TimeLimitExceededException)1