use of org.apache.http.impl.conn.SystemDefaultRoutePlanner in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomHttpRoutePlanner.
@Test
public void usesACustomHttpRoutePlanner() {
final HttpRoutePlanner customHttpRoutePlanner = new SystemDefaultRoutePlanner(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return ImmutableList.of(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.12", 8080)));
}
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
}
});
builder.using(customHttpRoutePlanner);
verify(apacheHttpClientBuilder).using(customHttpRoutePlanner);
}
use of org.apache.http.impl.conn.SystemDefaultRoutePlanner in project opennms by OpenNMS.
the class HttpClientWrapper method getClient.
public CloseableHttpClient getClient() {
if (m_httpClient == null) {
final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (!m_reuseConnections) {
httpClientBuilder.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
}
if (m_usePreemptiveAuth) {
enablePreemptiveAuth(httpClientBuilder);
}
if (m_useSystemProxySettings) {
httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
if (!isEmpty(m_cookieSpec)) {
requestConfigBuilder.setCookieSpec(m_cookieSpec);
}
if (m_cookieStore != null) {
httpClientBuilder.setDefaultCookieStore(m_cookieStore);
}
if (m_username != null) {
setCredentials(httpClientBuilder, m_username, m_password);
}
if (m_socketTimeout != null) {
requestConfigBuilder.setSocketTimeout(m_socketTimeout);
}
if (m_connectionTimeout != null) {
requestConfigBuilder.setConnectTimeout(m_connectionTimeout);
}
if (m_retries != null) {
httpClientBuilder.setRetryHandler(new HttpRequestRetryOnExceptionHandler(m_retries, false));
}
if (m_sslContext.size() != 0) {
configureSSLContext(httpClientBuilder);
}
for (final HttpRequestInterceptor interceptor : m_requestInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
for (final HttpResponseInterceptor interceptor : m_responseInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
if (m_useLaxRedirect) {
httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
}
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
m_httpClient = httpClientBuilder.build();
}
return m_httpClient;
}
use of org.apache.http.impl.conn.SystemDefaultRoutePlanner in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesACustomRoutePlanner.
@Test
public void usesACustomRoutePlanner() throws Exception {
final HttpRoutePlanner routePlanner = new SystemDefaultRoutePlanner(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return ImmutableList.of(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 org.apache.http.impl.conn.SystemDefaultRoutePlanner in project gradle by gradle.
the class HttpClientConfigurer method configureProxy.
private void configureProxy(HttpClientBuilder builder, CredentialsProvider credentialsProvider, HttpSettings httpSettings) {
HttpProxySettings.HttpProxy httpProxy = httpSettings.getProxySettings().getProxy();
HttpProxySettings.HttpProxy httpsProxy = httpSettings.getSecureProxySettings().getProxy();
for (HttpProxySettings.HttpProxy proxy : Lists.newArrayList(httpProxy, httpsProxy)) {
if (proxy != null) {
if (proxy.credentials != null) {
useCredentials(credentialsProvider, proxy.host, proxy.port, Collections.singleton(new AllSchemesAuthentication(proxy.credentials)));
}
}
}
builder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
Aggregations