small fixes and formatting work
This commit is contained in:
parent
1c79503594
commit
84d3367a37
|
@ -11,6 +11,7 @@ import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.conn.ConnectTimeoutException;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
@ -93,17 +94,15 @@ public class HttpClientTimeoutLiveTest {
|
||||||
/**
|
/**
|
||||||
* This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP)
|
* This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test(expected = ConnectTimeoutException.class)
|
||||||
public final void givenTimeoutIsConfigured_whenTimingOut_thenCorrect() throws ClientProtocolException, IOException {
|
public final void givenTimeoutIsConfigured_whenTimingOut_thenTimeoutException() throws ClientProtocolException, IOException {
|
||||||
final int timeout = 3;
|
final int timeout = 3;
|
||||||
|
|
||||||
final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();
|
final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();
|
||||||
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
|
|
||||||
final HttpGet request = new HttpGet("http://www.google.com:81");
|
final HttpGet request = new HttpGet("http://www.google.com:81");
|
||||||
response = client.execute(request);
|
client.execute(request);
|
||||||
|
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,19 +81,11 @@ public class HttpsClientSslLiveTest {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final SSLContext sslContext = SSLContexts.custom()
|
final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
|
||||||
.loadTrustMaterial(null, acceptingTrustStrategy).build();
|
|
||||||
|
|
||||||
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
sslContext,
|
|
||||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
|
||||||
|
|
||||||
final CloseableHttpClient httpClient = HttpClients
|
|
||||||
.custom()
|
|
||||||
.setHostnameVerifier(
|
|
||||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
|
|
||||||
.setSSLSocketFactory(sslsf).build();
|
|
||||||
|
|
||||||
|
final CloseableHttpClient httpClient = HttpClients.custom().setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER).setSSLSocketFactory(sslsf).build();
|
||||||
|
|
||||||
final HttpGet getMethod = new HttpGet(HOST_WITH_SSL);
|
final HttpGet getMethod = new HttpGet(HOST_WITH_SSL);
|
||||||
final HttpResponse response = httpClient.execute(getMethod);
|
final HttpResponse response = httpClient.execute(getMethod);
|
||||||
|
|
|
@ -70,8 +70,7 @@ public class HttpClientCookieLiveTest {
|
||||||
cookie.setDomain(".github.com");
|
cookie.setDomain(".github.com");
|
||||||
cookie.setPath("/");
|
cookie.setPath("/");
|
||||||
cookieStore.addCookie(cookie);
|
cookieStore.addCookie(cookie);
|
||||||
final HttpClient client = HttpClientBuilder.create()
|
final HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
|
||||||
.setDefaultCookieStore(cookieStore).build();
|
|
||||||
|
|
||||||
final HttpGet request = new HttpGet("http://www.github.com");
|
final HttpGet request = new HttpGet("http://www.github.com");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue