use of java.net.ProxySelector in project okhttp-digest by rburgst.
the class DigestAuthenticatorTest method beforeMethod.
@Before
public void beforeMethod() {
Connection mockConnection = mock(Connection.class);
Dns mockDns = mock(Dns.class);
SocketFactory socketFactory = mock(SocketFactory.class);
Authenticator proxyAuthenticator = mock(Authenticator.class);
ProxySelector proxySelector = mock(ProxySelector.class);
Proxy proxy = mock(Proxy.class);
// setup some dummy data so that we dont get NPEs
Address address = new Address("localhost", 8080, mockDns, socketFactory, null, null, null, proxyAuthenticator, null, Collections.singletonList(Protocol.HTTP_1_1), Collections.singletonList(ConnectionSpec.MODERN_TLS), proxySelector);
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 8080);
mockRoute = new Route(address, proxy, inetSocketAddress);
given(mockConnection.route()).willReturn(mockRoute);
authenticator = new DigestAuthenticator(new Credentials("user1", "user1"));
}
use of java.net.ProxySelector in project okhttp by square.
the class SocksProxyTest method proxySelector.
@Test
public void proxySelector() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));
ProxySelector proxySelector = new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return Collections.singletonList(socksProxy.proxy());
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
throw new AssertionError();
}
};
OkHttpClient client = clientTestRule.newClientBuilder().proxySelector(proxySelector).build();
Request request = new Request.Builder().url(server.url("/")).build();
Response response = client.newCall(request).execute();
assertThat(response.body().string()).isEqualTo("abc");
assertThat(socksProxy.connectionCount()).isEqualTo(1);
}
use of java.net.ProxySelector in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesACustomRoutePlanner.
@Test
void usesACustomRoutePlanner() throws Exception {
final HttpRoutePlanner routePlanner = new SystemDefaultRoutePlanner(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return Collections.singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.52.1", 8080)));
}
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
}
});
final CloseableHttpClient httpClient = builder.using(configuration).using(routePlanner).createClient(apacheBuilder, connectionManager, "test").getClient();
assertThat(httpClient).isNotNull();
assertThat(spyHttpClientBuilderField("routePlanner", apacheBuilder)).isSameAs(routePlanner);
assertThat(spyHttpClientField("routePlanner", httpClient)).isSameAs(routePlanner);
}
use of java.net.ProxySelector in project open-ecard by ecsec.
the class UpdatingProxySelector method loadSelector.
private synchronized void loadSelector() {
long now = System.currentTimeMillis();
long diff = now - lastUpdate;
if (diff > UPDATE_DELTA) {
lastUpdate = now;
ProxySelector selector = supplier.find();
if (selector == null) {
selector = new NoProxySelector();
}
this.lastSelector = selector;
}
}
use of java.net.ProxySelector in project scout.rt by eclipse.
the class ConfigurableProxySelector method select.
@Override
public List<Proxy> select(URI uri) {
LOG.trace("Selecting proxy for {}.", uri);
if (!m_proxyIgnoreList.isEmpty()) {
for (Pattern ignorePattern : m_proxyIgnoreList) {
if (ignorePattern.matcher(uri.toString()).matches()) {
LOG.trace("Using no proxy for {} specified by proxy ignore list.", uri);
return Collections.singletonList(Proxy.NO_PROXY);
}
}
}
if (!m_proxyMap.isEmpty()) {
List<Proxy> proxyList = new ArrayList<Proxy>();
for (Entry<Pattern, Proxy> entry : m_proxyMap.entrySet()) {
if (entry.getKey().matcher(uri.toString()).matches()) {
proxyList.add(entry.getValue());
}
}
if (!proxyList.isEmpty()) {
LOG.trace("Using {} for {} (configured by properties).", proxyList, uri);
return proxyList;
}
}
ProxySelector fallbackProxySelector = getFallbackProxySelector();
if (fallbackProxySelector != null) {
List<Proxy> proxyList = fallbackProxySelector.select(uri);
if (proxyList != null && !proxyList.isEmpty()) {
LOG.trace("Using {} for {} (configured by fallback proxy selector).", proxyList, uri);
return proxyList;
}
}
if (isUseSystemDefaultProxySelectorAsFallback()) {
fallbackProxySelector = ProxySelector.getDefault();
if (fallbackProxySelector != null && fallbackProxySelector != this) {
List<Proxy> proxyList = fallbackProxySelector.select(uri);
if (proxyList != null && !proxyList.isEmpty()) {
LOG.trace("Using {} for {} (configured by system default proxy selector).", proxyList, uri);
return proxyList;
}
}
}
// no proxy found (not in configuration and also not in fallback lists)
LOG.trace("No proxy found for {} using a direct connection.", uri);
return Collections.singletonList(Proxy.NO_PROXY);
}
Aggregations