use of com.netflix.niws.client.http.RestClient in project spring-cloud-netflix by spring-cloud.
the class SpringClientFactoryTests method testCookiePolicy.
@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
SpringClientFactory factory = new SpringClientFactory();
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
addEnvironment(parent, "ribbon.restclient.enabled=true");
parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
parent.refresh();
factory.setApplicationContext(parent);
RestClient client = factory.getClient("foo", RestClient.class);
ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler().getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
parent.close();
factory.destroy();
}
use of com.netflix.niws.client.http.RestClient 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.niws.client.http.RestClient 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.niws.client.http.RestClient in project ribbon by Netflix.
the class ManyShortLivedRequestsSurvivorTest method survive.
@Test
public void survive() throws IOException, ClientException, URISyntaxException, InterruptedException {
String clientName = "RibbonClientTest-loadBalancingDefaultPolicyRoundRobin";
String serverListKey = clientName + ".ribbon.listOfServers";
int nbHitsPerServer = 60;
MockWebServer server1 = new MockWebServer();
MockWebServer server2 = new MockWebServer();
for (int i = 0; i < nbHitsPerServer; i++) {
server1.enqueue(new MockResponse().setResponseCode(200).setBody("server1 success <" + i + ">!"));
server2.enqueue(new MockResponse().setResponseCode(200).setBody("server2 success <" + i + ">!"));
}
server1.play();
server2.play();
getConfigInstance().setProperty(serverListKey, hostAndPort(server1.getUrl("")) + "," + hostAndPort(server2.getUrl("")));
RestClient client = (RestClient) ClientFactory.getNamedClient(clientName);
HttpRequest request;
for (int i = 0; i < nbHitsPerServer * 2; i++) {
request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
response.close();
}
}
use of com.netflix.niws.client.http.RestClient in project ribbon by Netflix.
the class NamedConnectionPoolTest method testConnectionPoolCleaner.
@Test
public void testConnectionPoolCleaner() throws Exception {
// LogManager.getRootLogger().setLevel((Level)Level.DEBUG);
ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnIdleEvictTimeMilliSeconds, "100");
ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnectionCleanerRepeatInterval, "500");
RestClient client = (RestClient) ClientFactory.getNamedClient("ConnectionPoolCleanerTest");
NFHttpClient httpclient = NFHttpClientFactory.getNamedNFHttpClient("ConnectionPoolCleanerTest");
assertNotNull(httpclient);
com.netflix.client.http.HttpResponse response = null;
try {
response = client.execute(HttpRequest.newBuilder().uri(server.getServerPath("/")).build());
} finally {
if (response != null) {
response.close();
}
}
MonitoredConnectionManager connectionPoolManager = (MonitoredConnectionManager) httpclient.getConnectionManager();
Thread.sleep(2000);
assertEquals(0, connectionPoolManager.getConnectionsInPool());
client.shutdown();
}
Aggregations