use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class SampleApp method main.
public static void main(String[] args) throws Exception {
// 1
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
System.out.println(ConfigurationManager.getConfigInstance().getProperty("sample-client.ribbon.listOfServers"));
// 2
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
// 3
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
// 4
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " :" + response.getStatus());
}
ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client.getLoadBalancer();
System.out.println(lb.getLoadBalancerStats());
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.listOfServers", // 5
"www.linkedin.com:80,www.google.com:80");
System.out.println("changing servers ...");
// 6
Thread.sleep(3000);
for (int i = 0; i < 20; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " : " + response.getStatus());
}
// 7
System.out.println(lb.getLoadBalancerStats());
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class SampleApp method main.
public static void main(String[] args) throws Exception {
// 1
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
System.out.println(ConfigurationManager.getConfigInstance().getProperty("sample-client.ribbon.listOfServers"));
// 2
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
// 3
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
// 4
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " :" + response.getStatus());
}
@SuppressWarnings("rawtypes") ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client.getLoadBalancer();
System.out.println(lb.getLoadBalancerStats());
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.listOfServers", // 5
"www.linkedin.com:80,www.google.com:80");
System.out.println("changing servers ...");
// 6
Thread.sleep(3000);
for (int i = 0; i < 20; i++) {
HttpResponse response = null;
try {
response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " : " + response.getStatus());
} finally {
if (response != null) {
response.close();
}
}
}
// 7
System.out.println(lb.getLoadBalancerStats());
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class RetryTest method testRetriesOnPostWithConnectException.
@Test
public void testRetriesOnPostWithConnectException() throws Exception {
URI localUrl = new URI("/status?code=503");
lb.setServersList(Lists.newArrayList(localServer));
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
try {
HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
fail("Exception expected");
} catch (ClientException e) {
// NOPMD
}
ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer);
assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class RetryTest method testSuccessfulRetries.
@Test
public void testSuccessfulRetries() throws Exception {
lb.setServersList(Lists.newArrayList(new Server("localhost:12987"), new Server("localhost:12987"), localServer));
URI localUrl = new URI("/ok");
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).queryParams("name", "ribbon").build();
try {
HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
assertEquals(200, response.getStatus());
} catch (ClientException e) {
fail("Unexpected exception");
}
ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(new Server("localhost:12987"));
assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class SecureAcceptAllGetTest method testPositiveAcceptAllSSLSocketFactory.
@Test
public void testPositiveAcceptAllSSLSocketFactory() throws Exception {
// test connection succeeds connecting to a random SSL endpoint with allow all SSL factory
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testPositiveAcceptAllSSLSocketFactory";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory");
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
TEST_SERVER.accept();
URI getUri = new URI(TEST_SERVICE_URI + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
Aggregations