Search in sources :

Example 11 with HttpRequest

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

the class SecureAcceptAllGetTest method testNegativeAcceptAllSSLSocketFactory.

@Test
public void testNegativeAcceptAllSSLSocketFactory() throws Exception {
    // test exception is thrown connecting to a random SSL endpoint without explicitly setting factory to allow all
    String name = "GetPostSecureTest" + ".testNegativeAcceptAllSSLSocketFactory";
    // don't set any interesting properties -- really we're just setting the defaults
    RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
    TEST_SERVER.accept();
    URI getUri = new URI(TEST_SERVICE_URI + "test/");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    boolean foundCause = false;
    try {
        rc.execute(request);
    } catch (Throwable t) {
        while (t != null && !foundCause) {
            if (t instanceof SSLPeerUnverifiedException && t.getMessage().startsWith("peer not authenticated")) {
                foundCause = true;
                break;
            }
            t = t.getCause();
        }
    }
    assertTrue(foundCause);
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) URI(java.net.URI)

Example 12 with HttpRequest

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

the class SecureGetTest method testClientRejectsWrongServer.

@Test
public void testClientRejectsWrongServer() throws Exception {
    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
    String name = "GetPostSecureTest" + ".testClientRejectsWrongServer";
    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_TS1.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();
    try {
        rc.execute(request);
        fail("expecting ssl hostname validation error");
    } catch (ClientHandlerException che) {
        assertTrue(che.getMessage().indexOf("peer not authenticated") > -1);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) URI(java.net.URI) Test(org.junit.Test)

Example 13 with HttpRequest

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

the class SecureGetTest method testFailsWithHostNameValidationOn.

@Test
public void testFailsWithHostNameValidationOn() throws Exception {
    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
    String name = "GetPostSecureTest" + ".testFailsWithHostNameValidationOn";
    String configPrefix = name + "." + "ribbon";
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1));
    // <--
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "true");
    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/");
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add("name", "test");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    try {
        rc.execute(request);
        fail("expecting ssl hostname validation error");
    } catch (ClientHandlerException che) {
        assertTrue(che.getMessage().indexOf("hostname in certificate didn't match") > -1);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) URI(java.net.URI) Test(org.junit.Test)

Example 14 with HttpRequest

use of com.netflix.client.http.HttpRequest 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 15 with HttpRequest

use of com.netflix.client.http.HttpRequest 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)

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