Search in sources :

Example 6 with HttpResponse

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) IClientConfig(com.netflix.client.config.IClientConfig) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 7 with HttpResponse

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"));
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) URI(java.net.URI) Test(org.junit.Test)

Example 8 with HttpResponse

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"));
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 9 with HttpResponse

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));
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 10 with HttpResponse

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) Server(com.netflix.loadbalancer.Server) MockHttpServer(com.netflix.client.testutil.MockHttpServer) HttpResponse(com.netflix.client.http.HttpResponse) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) URI(java.net.URI) Test(org.junit.Test)

Aggregations

HttpRequest (com.netflix.client.http.HttpRequest)20 HttpResponse (com.netflix.client.http.HttpResponse)20 URI (java.net.URI)16 Test (org.junit.Test)16 MockHttpServer (com.netflix.client.testutil.MockHttpServer)3 Server (com.netflix.loadbalancer.Server)3 RestClient (com.netflix.niws.client.http.RestClient)3 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)3 ClientException (com.netflix.client.ClientException)2 IClientConfig (com.netflix.client.config.IClientConfig)2 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)2 ServerStats (com.netflix.loadbalancer.ServerStats)2 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)2 MockResponse (com.google.mockwebserver.MockResponse)1 MockWebServer (com.google.mockwebserver.MockWebServer)1 NFRequestContext (com.netflix.zuul.context.NFRequestContext)1 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1