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.methods.CloseableHttpResponse;
|
||||
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.DefaultHttpClient;
|
||||
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)
|
||||
*/
|
||||
@Test
|
||||
public final void givenTimeoutIsConfigured_whenTimingOut_thenCorrect() throws ClientProtocolException, IOException {
|
||||
@Test(expected = ConnectTimeoutException.class)
|
||||
public final void givenTimeoutIsConfigured_whenTimingOut_thenTimeoutException() throws ClientProtocolException, IOException {
|
||||
final int timeout = 3;
|
||||
|
||||
final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();
|
||||
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||
|
||||
final HttpGet request = new HttpGet("http://www.google.com:81");
|
||||
response = client.execute(request);
|
||||
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
client.execute(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,19 +81,11 @@ public class HttpsClientSslLiveTest {
|
|||
return true;
|
||||
}
|
||||
};
|
||||
final SSLContext sslContext = SSLContexts.custom()
|
||||
.loadTrustMaterial(null, acceptingTrustStrategy).build();
|
||||
final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
|
||||
|
||||
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
||||
sslContext,
|
||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
|
||||
final CloseableHttpClient httpClient = HttpClients
|
||||
.custom()
|
||||
.setHostnameVerifier(
|
||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
|
||||
.setSSLSocketFactory(sslsf).build();
|
||||
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
|
||||
final CloseableHttpClient httpClient = HttpClients.custom().setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER).setSSLSocketFactory(sslsf).build();
|
||||
|
||||
final HttpGet getMethod = new HttpGet(HOST_WITH_SSL);
|
||||
final HttpResponse response = httpClient.execute(getMethod);
|
||||
|
|
|
@ -70,8 +70,7 @@ public class HttpClientCookieLiveTest {
|
|||
cookie.setDomain(".github.com");
|
||||
cookie.setPath("/");
|
||||
cookieStore.addCookie(cookie);
|
||||
final HttpClient client = HttpClientBuilder.create()
|
||||
.setDefaultCookieStore(cookieStore).build();
|
||||
final HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
|
||||
|
||||
final HttpGet request = new HttpGet("http://www.github.com");
|
||||
|
||||
|
|
Loading…
Reference in New Issue