Search in sources :

Example 31 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method postReadTimeout.

@Test
public void postReadTimeout() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer);
    assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ServerStats(com.netflix.loadbalancer.ServerStats) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 32 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method testReadTimeoutWithRetriesNextServe.

@Test
public void testReadTimeoutWithRetriesNextServe() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 33 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class SecureGetTest method testSunnyDayNoClientAuth.

@Test
public void testSunnyDayNoClientAuth() throws Exception {
    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
    String name = "GetPostSecureTest" + ".testSunnyDayNoClientAuth";
    String configPrefix = name + "." + "ribbon";
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2));
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS2.getAbsolutePath());
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
    RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
    testServer2.accept();
    URI getUri = new URI(SERVICE_URI2 + "test/");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    HttpResponse response = rc.execute(request);
    assertEquals(200, response.getStatus());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 34 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class SecureGetTest method testSunnyDay.

@Test
public void testSunnyDay() throws Exception {
    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
    String name = "GetPostSecureTest" + ".testSunnyDay";
    String configPrefix = name + "." + "ribbon";
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1));
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath());
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD);
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath());
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
    RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
    testServer1.accept();
    URI getUri = new URI(SERVICE_URI1 + "test/");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    HttpResponse response = rc.execute(request);
    assertEquals(200, response.getStatus());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 35 with HttpRequest

use of com.netflix.client.http.HttpRequest in project spring-cloud-netflix by spring-cloud.

the class RestClientRibbonCommandTests method testNullEntity.

@Test
public void testNullEntity() throws Exception {
    String uri = "http://example.com";
    LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("my-header", "my-value");
    LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("myparam", "myparamval");
    RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()), zuulProperties);
    HttpRequest request = command.createRequest();
    assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
    assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
    assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

HttpRequest (com.netflix.client.http.HttpRequest)36 URI (java.net.URI)28 Test (org.junit.Test)28 HttpResponse (com.netflix.client.http.HttpResponse)21 ClientException (com.netflix.client.ClientException)9 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)5 ServerStats (com.netflix.loadbalancer.ServerStats)4 MockHttpServer (com.netflix.client.testutil.MockHttpServer)3 Server (com.netflix.loadbalancer.Server)3 RestClient (com.netflix.niws.client.http.RestClient)3 InputStream (java.io.InputStream)3 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 IClientConfig (com.netflix.client.config.IClientConfig)2 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)2 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)2 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MockResponse (com.google.mockwebserver.MockResponse)1