use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class FollowRedirectTest method testRedirectFollowed.
@Test
public void testRedirectFollowed() throws Exception {
IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues("myclient2").set(IClientConfigKey.Keys.FollowRedirects, Boolean.TRUE);
ClientFactory.registerClientFromProperties("myclient2", config);
com.netflix.niws.client.http.RestClient client = (com.netflix.niws.client.http.RestClient) ClientFactory.getNamedClient("myclient2");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("http://localhost:" + redirectingServer.getPort())).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class GetPostTest method testGet.
@Test
public void testGet() throws Exception {
URI getUri = new URI(SERVICE_URI + "test/getObject");
MultivaluedMapImpl params = new MultivaluedMapImpl();
params.add("name", "test");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(TestObject.class).name.equals("test"));
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class GetPostTest method testPost.
@Test
public void testPost() throws Exception {
URI getUri = new URI(SERVICE_URI + "test/setObject");
TestObject obj = new TestObject();
obj.name = "fromClient";
HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(getUri).entity(obj).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(TestObject.class).name.equals("fromClient"));
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class GetPostTest method testChunkedEncoding.
@Test
public void testChunkedEncoding() throws Exception {
String obj = "chunked encoded content";
URI postUri = new URI(SERVICE_URI + "test/postStream");
InputStream input = new ByteArrayInputStream(obj.getBytes("UTF-8"));
HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(postUri).entity(input).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(String.class).equals(obj));
}
use of com.netflix.client.http.HttpResponse in project ribbon by Netflix.
the class RestClientTest method testSecureClient2.
@Test
public void testSecureClient2() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true");
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath());
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);
RestClient client = (RestClient) ClientFactory.getNamedClient("test3");
BaseLoadBalancer lb = new BaseLoadBalancer();
Server[] servers = new Server[] { new Server("localhost", secureServer.getServerPort()) };
lb.addServers(Arrays.asList(servers));
client.setLoadBalancer(lb);
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString());
}
Aggregations