use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class FollowRedirectTest method testRedirectNotFollowed.
@Test
public void testRedirectNotFollowed() throws Exception {
IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues("myclient");
config.setProperty(CommonClientConfigKey.FollowRedirects, Boolean.FALSE);
ClientFactory.registerClientFromProperties("myclient", config);
RestClient client = (RestClient) ClientFactory.getNamedClient("myclient");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("http://localhost:" + redirectingServer.getPort())).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertEquals(302, response.getStatus());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testExecuteWithLB.
@Test
public void testExecuteWithLB() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("allservices.ribbon." + CommonClientConfigKey.ReadTimeout, "10000");
ConfigurationManager.getConfigInstance().setProperty("allservices.ribbon." + CommonClientConfigKey.FollowRedirects, "true");
RestClient client = (RestClient) ClientFactory.getNamedClient("allservices");
BaseLoadBalancer lb = new BaseLoadBalancer();
Server[] servers = new Server[] { new Server("localhost", server.getServerPort()) };
lb.addServers(Arrays.asList(servers));
client.setLoadBalancer(lb);
Set<URI> expected = new HashSet<URI>();
expected.add(new URI(server.getServerPath("/")));
Set<URI> result = new HashSet<URI>();
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 5; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertTrue(response.isSuccess());
String content = response.getEntity(String.class);
response.close();
assertFalse(content.isEmpty());
result.add(response.getRequestedURI());
}
assertEquals(expected, result);
request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertEquals(200, response.getStatus());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testDelete.
@Test
public void testDelete() throws Exception {
RestClient client = (RestClient) ClientFactory.getNamedClient("google");
HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).verb(HttpRequest.Verb.DELETE).build();
HttpResponse response = client.execute(request);
assertStatusIsOk(response.getStatus());
request = HttpRequest.newBuilder().uri(server.getServerURI()).verb(HttpRequest.Verb.DELETE).entity("").build();
response = client.execute(request);
assertStatusIsOk(response.getStatus());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testSecureClient.
@Test
public void testSecureClient() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test2.ribbon.IsSecure", "true");
RestClient client = (RestClient) ClientFactory.getNamedClient("test2");
HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testVipAsURI.
@Test
public void testVipAsURI() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test1.ribbon.DeploymentContextBasedVipAddresses", server.getServerPath("/"));
ConfigurationManager.getConfigInstance().setProperty("test1.ribbon.InitializeNFLoadBalancer", "false");
RestClient client = (RestClient) ClientFactory.getNamedClient("test1");
assertNull(client.getLoadBalancer());
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertEquals(server.getServerPath("/"), response.getRequestedURI().toString());
}
Aggregations