Search in sources :

Example 1 with ProxyDTO

use of aQute.bnd.connection.settings.ProxyDTO 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 ProxyDTO

use of aQute.bnd.connection.settings.ProxyDTO 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 ProxyDTO

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

the class SettingsParserTest method testSocksAuth.

public void testSocksAuth() throws Exception {
    SettingsDTO settings = getSettings("socks-auth.xml");
    assertEquals(1, settings.proxies.size());
    ProxyDTO p = settings.proxies.get(0);
    assertEquals("myproxy", p.id);
    assertEquals(true, p.active);
    assertEquals(Type.SOCKS, p.protocol);
    assertEquals(1080, p.port);
    assertEquals(null, p.nonProxyHosts);
    assertEquals("proxyuser", p.username);
    assertEquals("somepassword", p.password);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) SettingsDTO(aQute.bnd.connection.settings.SettingsDTO)

Example 4 with ProxyDTO

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

the class SettingsParserTest method testSocksNoAuth.

public void testSocksNoAuth() throws Exception {
    SettingsDTO settings = getSettings("socks-noauth.xml");
    assertEquals(1, settings.proxies.size());
    ProxyDTO p = settings.proxies.get(0);
    assertEquals("myproxy", p.id);
    assertEquals(true, p.active);
    assertEquals(Type.SOCKS, p.protocol);
    assertEquals(1080, p.port);
    assertEquals(null, p.nonProxyHosts);
    assertEquals(null, p.username);
    assertEquals(null, p.password);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) SettingsDTO(aQute.bnd.connection.settings.SettingsDTO)

Example 5 with ProxyDTO

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

the class SettingsParserTest method testNonProxyHost.

public void testNonProxyHost() throws Exception {
    SettingsDTO settings = getSettings("socks-auth-nonproxyhosts.xml");
    assertEquals(1, settings.proxies.size());
    ProxyDTO p = settings.proxies.get(0);
    assertEquals("myproxy", p.id);
    assertEquals(true, p.active);
    assertEquals(Type.SOCKS, p.protocol);
    assertEquals(1080, p.port);
    assertEquals("*.google.com|ibiblio.org", p.nonProxyHosts);
    assertEquals(null, p.username);
    assertEquals(null, p.password);
}
Also used : ProxyDTO(aQute.bnd.connection.settings.ProxyDTO) SettingsDTO(aQute.bnd.connection.settings.SettingsDTO)

Aggregations

ProxyDTO (aQute.bnd.connection.settings.ProxyDTO)5 SettingsDTO (aQute.bnd.connection.settings.SettingsDTO)3 ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)2 ServerDTO (aQute.bnd.connection.settings.ServerDTO)2 HttpClient (aQute.bnd.http.HttpClient)2 Processor (aQute.bnd.osgi.Processor)2 TaggedData (aQute.bnd.service.url.TaggedData)2 URL (java.net.URL)2