Search in sources :

Example 1 with ProxyConfiguration

use of io.dropwizard.client.proxy.ProxyConfiguration in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesProxyWithAuth.

@Test
public void usesProxyWithAuth() throws Exception {
    HttpClientConfiguration config = new HttpClientConfiguration();
    AuthConfiguration auth = new AuthConfiguration("secret", "stuff");
    ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080, "http", auth);
    config.setProxyConfiguration(proxy);
    CloseableHttpClient httpClient = checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080, "http"));
    CredentialsProvider credentialsProvider = (CredentialsProvider) FieldUtils.getField(httpClient.getClass(), "credentialsProvider", true).get(httpClient);
    assertThat(credentialsProvider.getCredentials(new AuthScope("192.168.52.11", 8080))).isEqualTo(new UsernamePasswordCredentials("secret", "stuff"));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ProxyConfiguration(io.dropwizard.client.proxy.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) AuthConfiguration(io.dropwizard.client.proxy.AuthConfiguration) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 2 with ProxyConfiguration

use of io.dropwizard.client.proxy.ProxyConfiguration in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesProxy.

@Test
void usesProxy() throws Exception {
    HttpClientConfiguration config = new HttpClientConfiguration();
    ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080);
    config.setProxyConfiguration(proxy);
    checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080));
}
Also used : ProxyConfiguration(io.dropwizard.client.proxy.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) Test(org.junit.jupiter.api.Test)

Example 3 with ProxyConfiguration

use of io.dropwizard.client.proxy.ProxyConfiguration in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesProxyWithoutPort.

@Test
void usesProxyWithoutPort() throws Exception {
    HttpClientConfiguration config = new HttpClientConfiguration();
    ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11");
    config.setProxyConfiguration(proxy);
    checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11"));
}
Also used : ProxyConfiguration(io.dropwizard.client.proxy.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) Test(org.junit.jupiter.api.Test)

Example 4 with ProxyConfiguration

use of io.dropwizard.client.proxy.ProxyConfiguration in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesProxyWithNtlmAuth.

@Test
void usesProxyWithNtlmAuth() throws Exception {
    HttpClientConfiguration config = new HttpClientConfiguration();
    AuthConfiguration auth = new AuthConfiguration("secret", "stuff", "NTLM", "realm", "host", "domain", "NT");
    ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080, "http", auth);
    config.setProxyConfiguration(proxy);
    CloseableHttpClient httpClient = checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080, "http"));
    CredentialsProvider credentialsProvider = (CredentialsProvider) getInaccessibleField(httpClient.getClass(), "credentialsProvider").get(httpClient);
    AuthScope authScope = new AuthScope("192.168.52.11", 8080, "realm", "NTLM");
    Credentials credentials = new NTCredentials("secret", "stuff", "host", "domain");
    assertThat(credentialsProvider.getCredentials(authScope)).isEqualTo(credentials);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ProxyConfiguration(io.dropwizard.client.proxy.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) AuthConfiguration(io.dropwizard.client.proxy.AuthConfiguration) CredentialsProvider(org.apache.http.client.CredentialsProvider) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) Test(org.junit.jupiter.api.Test)

Example 5 with ProxyConfiguration

use of io.dropwizard.client.proxy.ProxyConfiguration in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesProxyWithNonProxyHostsAndTargetDoesNotMatch.

@Test
void usesProxyWithNonProxyHostsAndTargetDoesNotMatch() throws Exception {
    HttpClientConfiguration config = new HttpClientConfiguration();
    ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11");
    proxy.setNonProxyHosts(Collections.singletonList("*.example.com"));
    config.setProxyConfiguration(proxy);
    checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11"));
}
Also used : ProxyConfiguration(io.dropwizard.client.proxy.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyConfiguration (io.dropwizard.client.proxy.ProxyConfiguration)8 HttpHost (org.apache.http.HttpHost)8 Test (org.junit.jupiter.api.Test)6 AuthConfiguration (io.dropwizard.client.proxy.AuthConfiguration)4 AuthScope (org.apache.http.auth.AuthScope)4 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)4 CredentialsProvider (org.apache.http.client.CredentialsProvider)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Credentials (org.apache.http.auth.Credentials)2 NTCredentials (org.apache.http.auth.NTCredentials)2 NonProxyListProxyRoutePlanner (io.dropwizard.client.proxy.NonProxyListProxyRoutePlanner)1 ConnectionReuseStrategy (org.apache.http.ConnectionReuseStrategy)1 HttpResponse (org.apache.http.HttpResponse)1 HttpRequestRetryHandler (org.apache.http.client.HttpRequestRetryHandler)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 SocketConfig (org.apache.http.config.SocketConfig)1 DefaultConnectionReuseStrategy (org.apache.http.impl.DefaultConnectionReuseStrategy)1 NoConnectionReuseStrategy (org.apache.http.impl.NoConnectionReuseStrategy)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 DefaultConnectionKeepAliveStrategy (org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy)1