Search in sources :

Example 46 with HttpClient

use of io.vertx.core.http.HttpClient in project java-chassis by ServiceComb.

the class HttpClientVerticle method createClientPool.

@Override
public HttpClientWithContext createClientPool() {
    HttpClientOptions httpClientOptions = (HttpClientOptions) config().getValue(CLIENT_OPTIONS);
    HttpClient httpClient = vertx.createHttpClient(httpClientOptions);
    return new HttpClientWithContext(httpClient, context);
}
Also used : HttpClient(io.vertx.core.http.HttpClient) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 47 with HttpClient

use of io.vertx.core.http.HttpClient in project java-chassis by ServiceComb.

the class TestVertxGetMethod method testVertxGetMethod.

@Test
public void testVertxGetMethod() {
    HttpClient client = Mockito.mock(HttpClient.class);
    Invocation invocation = Mockito.mock(Invocation.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(ipPort.getPort()).thenReturn(10);
    assertEquals(10, ipPort.getPort());
    Mockito.when(ipPort.getHostOrIp()).thenReturn("ever");
    assertEquals("ever", ipPort.getHostOrIp());
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    HttpClientRequest obj = VertxGetMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 48 with HttpClient

use of io.vertx.core.http.HttpClient in project java-chassis by ServiceComb.

the class TestVertxPostMethod method testVertxPostMethod.

@Test
public void testVertxPostMethod() {
    Invocation invocation = Mockito.mock(Invocation.class);
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    assertEquals(23, ipPort.getPort());
    Mockito.when(ipPort.getHostOrIp()).thenReturn("testCall");
    assertNotNull("testCall", ipPort.getHostOrIp());
    HttpClientRequest obj = VertxPostMethod.INSTANCE.createRequest(client, invocation, ipPort, "test", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 49 with HttpClient

use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.

the class VertxHttpClientVerticle method start.

@Override
public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();
    client.getNow("perdu.com", "/", response -> {
        response.bodyHandler(buffer -> LOGGER.info(buffer.toString("UTF-8")));
    });
}
Also used : HttpClient(io.vertx.core.http.HttpClient)

Example 50 with HttpClient

use of io.vertx.core.http.HttpClient in project vertx-examples by vert-x3.

the class JUnitVerticleTest method canGetHello.

@Test
public void canGetHello(TestContext context) {
    Async async = context.async();
    HttpClient client = vertx.createHttpClient();
    client.getNow(port, "localhost", "/", response -> {
        response.bodyHandler(body -> {
            context.assertEquals("Hello!", body.toString());
            client.close();
            async.complete();
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.core.http.HttpClient) Test(org.junit.Test)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)77 Test (org.junit.Test)47 HttpClientRequest (io.vertx.core.http.HttpClientRequest)36 HttpClientOptions (io.vertx.core.http.HttpClientOptions)25 Vertx (io.vertx.core.Vertx)22 HttpMethod (io.vertx.core.http.HttpMethod)22 JsonObject (io.vertx.core.json.JsonObject)22 Handler (io.vertx.core.Handler)18 Buffer (io.vertx.core.buffer.Buffer)18 HttpClientResponse (io.vertx.core.http.HttpClientResponse)16 TimeUnit (java.util.concurrent.TimeUnit)16 HttpServer (io.vertx.core.http.HttpServer)15 Async (io.vertx.ext.unit.Async)15 Before (org.junit.Before)15 File (java.io.File)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 URL (java.net.URL)12 HttpServerOptions (io.vertx.core.http.HttpServerOptions)11 IOException (java.io.IOException)10 List (java.util.List)10