Search in sources :

Example 6 with HttpClientConfig

use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.

the class TestTestingHttpServer method testRequest.

@Test
public void testRequest() throws Exception {
    DummyServlet servlet = new DummyServlet();
    TestingHttpServer server = createTestingHttpServer(servlet, ImmutableMap.of());
    try {
        server.start();
        try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) {
            StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler());
            assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(servlet.getCallCount(), 1);
        }
    } finally {
        server.stop();
    }
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) HttpClient(io.airlift.http.client.HttpClient) Duration(io.airlift.units.Duration) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Test(org.testng.annotations.Test)

Example 7 with HttpClientConfig

use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.

the class TestHttpEventClient method setup.

@BeforeMethod
public void setup() throws Exception {
    httpClient = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(10, SECONDS)));
    servlet = new DummyServlet();
    server = createServer(servlet);
    server.start();
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Duration(io.airlift.units.Duration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with HttpClientConfig

use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.

the class TestHttpServerProvider method testHttps.

@Test
public void testHttps() throws Exception {
    config.setHttpEnabled(false).setHttpsEnabled(true);
    httpsConfig.setKeystorePath(getResource("test.keystore.with.two.passwords").getPath()).setKeystorePassword("airlift").setKeyManagerPassword("airliftkey").setAutomaticHttpsSharedSecret("shared-secret");
    createAndStartServer();
    HttpClientConfig http1ClientConfig = new HttpClientConfig().setHttp2Enabled(false).setTrustStorePath(getResource("test.truststore").getPath()).setTrustStorePassword("airlift").setAutomaticHttpsSharedSecret("shared-secret");
    try (JettyHttpClient httpClient = createJettyClient(http1ClientConfig)) {
        verifyHttps(httpClient, "localhost");
        verifyHttps(httpClient, "127-0-0-1.ip");
        verifyHttps(httpClient, "x--1.ip");
    }
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Test(org.testng.annotations.Test)

Example 9 with HttpClientConfig

use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.

the class TestHttpServerProvider method testHttp.

@Test
public void testHttp() throws Exception {
    createServer();
    server.start();
    try (JettyHttpClient httpClient = new JettyHttpClient(new HttpClientConfig().setHttp2Enabled(false))) {
        StatusResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).build(), createStatusResponseHandler());
        assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
        assertEquals(response.getHeader("X-Protocol"), "HTTP/1.1");
    }
    try (JettyHttpClient httpClient = new JettyHttpClient(new HttpClientConfig().setHttp2Enabled(true))) {
        StatusResponse response = httpClient.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).build(), createStatusResponseHandler());
        assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
        assertEquals(response.getHeader("X-Protocol"), "HTTP/2.0");
    }
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Test(org.testng.annotations.Test)

Example 10 with HttpClientConfig

use of io.airlift.http.client.HttpClientConfig in project airlift by airlift.

the class TestHttpServerProvider method testClientCertificateJava.

@Test
public void testClientCertificateJava() throws Exception {
    config.setHttpEnabled(false).setHttpsEnabled(true);
    httpsConfig.setKeystorePath(getResource("clientcert-java/server.keystore").getPath()).setKeystorePassword("airlift").setAutomaticHttpsSharedSecret("shared-secret");
    clientCertificate = ClientCertificate.REQUIRED;
    createAndStartServer(createCertTestServlet());
    HttpClientConfig clientConfig = new HttpClientConfig().setKeyStorePath(getResource("clientcert-java/client.keystore").getPath()).setKeyStorePassword("airlift").setTrustStorePath(getResource("clientcert-java/client.truststore").getPath()).setTrustStorePassword("airlift").setAutomaticHttpsSharedSecret("shared-secret");
    assertClientCertificateRequest(clientConfig, "localhost");
    assertClientCertificateRequest(clientConfig, "127-0-0-1.ip");
    assertClientCertificateRequest(clientConfig, "x--1.ip");
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) Test(org.testng.annotations.Test)

Aggregations

HttpClientConfig (io.airlift.http.client.HttpClientConfig)16 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)13 Test (org.testng.annotations.Test)11 Duration (io.airlift.units.Duration)8 HttpClient (io.airlift.http.client.HttpClient)5 StatusResponse (io.airlift.http.client.StatusResponseHandler.StatusResponse)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 Injector (com.google.inject.Injector)3 Bootstrap (io.airlift.bootstrap.Bootstrap)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 TheServlet (io.airlift.http.server.TheServlet)3 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)3 Map (java.util.Map)3 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Closer (com.google.common.io.Closer)1 PrivateModule (com.google.inject.PrivateModule)1