Search in sources :

Example 31 with HttpClient

use of io.vertx.core.http.HttpClient in project mod-inventory-storage by folio-org.

the class LoanTypeTest method send.

private void send(URL url, HttpMethod method, String content, Handler<HttpClientResponse> handler) {
    HttpClient client = StorageTestSuite.getVertx().createHttpClient();
    HttpClientRequest request;
    if (content == null) {
        content = "";
    }
    Buffer buffer = Buffer.buffer(content);
    switch(method) {
        case POST:
            request = client.postAbs(url.toString());
            break;
        case DELETE:
            request = client.deleteAbs(url.toString());
            break;
        case GET:
            request = client.getAbs(url.toString());
            break;
        default:
            request = client.putAbs(url.toString());
    }
    request.exceptionHandler(error -> {
        Assert.fail(error.getLocalizedMessage());
    }).handler(handler);
    request.putHeader("Authorization", "test_tenant");
    request.putHeader("x-okapi-tenant", "test_tenant");
    request.putHeader("Accept", "application/json,text/plain");
    request.putHeader("Content-type", SUPPORTED_CONTENT_TYPE_JSON_DEF);
    request.end(buffer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ResponseHandler(org.folio.rest.support.ResponseHandler) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Response(org.folio.rest.support.Response) DecodeException(io.vertx.core.json.DecodeException) URL(java.net.URL) MaterialTypesClient(org.folio.rest.support.client.MaterialTypesClient) AdditionalHttpStatusCodes(org.folio.rest.support.AdditionalHttpStatusCodes) TimeoutException(java.util.concurrent.TimeoutException) InterfaceUrls.itemsStorageUrl(org.folio.rest.support.http.InterfaceUrls.itemsStorageUrl) CompletableFuture(java.util.concurrent.CompletableFuture) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) JsonObject(io.vertx.core.json.JsonObject) InterfaceUrls.materialTypesStorageUrl(org.folio.rest.support.http.InterfaceUrls.materialTypesStorageUrl) Before(org.junit.Before) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) UUID(java.util.UUID) InterfaceUrls.loanTypesStorageUrl(org.folio.rest.support.http.InterfaceUrls.loanTypesStorageUrl) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 32 with HttpClient

use of io.vertx.core.http.HttpClient in project mod-inventory-storage by folio-org.

the class LocationsTest method send.

// /////////////////////////// helpers
private static void send(URL url, HttpMethod method, String content, String contentType, Handler<HttpClientResponse> handler) {
    HttpClient client = StorageTestSuite.getVertx().createHttpClient();
    HttpClientRequest request;
    if (content == null) {
        content = "";
    }
    Buffer buffer = Buffer.buffer(content);
    if (method == HttpMethod.POST) {
        request = client.postAbs(url.toString());
    } else if (method == HttpMethod.DELETE) {
        request = client.deleteAbs(url.toString());
    } else if (method == HttpMethod.GET) {
        request = client.getAbs(url.toString());
    } else {
        request = client.putAbs(url.toString());
    }
    request.exceptionHandler(error -> {
        Assert.fail(error.getLocalizedMessage());
    }).handler(handler);
    request.putHeader("Authorization", "test_tenant");
    request.putHeader("x-okapi-tenant", "test_tenant");
    request.putHeader("Accept", "application/json,text/plain");
    request.putHeader("Content-type", contentType);
    request.end(buffer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ResponseHandler(org.folio.rest.support.ResponseHandler) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Json(io.vertx.core.json.Json) Response(org.folio.rest.support.Response) URL(java.net.URL) MaterialTypesClient(org.folio.rest.support.client.MaterialTypesClient) TimeoutException(java.util.concurrent.TimeoutException) AdditionalHttpStatusCodes(org.folio.rest.support.AdditionalHttpStatusCodes) CompletableFuture(java.util.concurrent.CompletableFuture) HttpResponseMatchers.statusCodeIs(org.folio.rest.support.HttpResponseMatchers.statusCodeIs) LoggerFactory(io.vertx.core.logging.LoggerFactory) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) JsonObject(io.vertx.core.json.JsonObject) Logger(io.vertx.core.logging.Logger) Before(org.junit.Before) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) LoanTypesClient(org.folio.rest.support.client.LoanTypesClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 33 with HttpClient

use of io.vertx.core.http.HttpClient in project mod-inventory-storage by folio-org.

the class LocationUnitTest method send.

// //////////////// General helpers
/*
  private JsonObject createItemRequest(String temporaryLocationId) {

    JsonObject item = new JsonObject();

    item.put("holdingsRecordId", UUID.randomUUID().toString());
    item.put("barcode", "12345");
    item.put("permanentLoanTypeId", canCirculateLoanTypeID);
    item.put("materialTypeId", journalMaterialTypeID);
    item.put("temporaryLocationId", temporaryLocationId);

    return item;
  }
   */
private static void send(URL url, HttpMethod method, String content, String contentType, Handler<HttpClientResponse> handler) {
    HttpClient client = StorageTestSuite.getVertx().createHttpClient();
    HttpClientRequest request;
    if (content == null) {
        content = "";
    }
    Buffer buffer = Buffer.buffer(content);
    if (method == HttpMethod.POST) {
        request = client.postAbs(url.toString());
    } else if (method == HttpMethod.DELETE) {
        request = client.deleteAbs(url.toString());
    } else if (method == HttpMethod.GET) {
        request = client.getAbs(url.toString());
    } else {
        request = client.putAbs(url.toString());
    }
    request.exceptionHandler(error -> {
        Assert.fail(error.getLocalizedMessage());
    }).handler(handler);
    request.putHeader("Authorization", "test_tenant");
    request.putHeader("x-okapi-tenant", "test_tenant");
    request.putHeader("Accept", "application/json,text/plain");
    request.putHeader("Content-type", contentType);
    request.end(buffer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ResponseHandler(org.folio.rest.support.ResponseHandler) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Response(org.folio.rest.support.Response) URL(java.net.URL) AdditionalHttpStatusCodes(org.folio.rest.support.AdditionalHttpStatusCodes) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) HttpResponseMatchers.statusCodeIs(org.folio.rest.support.HttpResponseMatchers.statusCodeIs) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 34 with HttpClient

use of io.vertx.core.http.HttpClient in project mod-inventory-storage by folio-org.

the class MaterialTypeTest method send.

private void send(String url, HttpMethod method, String content, String contentType, Handler<HttpClientResponse> handler) {
    HttpClient client = StorageTestSuite.getVertx().createHttpClient();
    HttpClientRequest request;
    if (content == null) {
        content = "";
    }
    Buffer buffer = Buffer.buffer(content);
    if (method == HttpMethod.POST) {
        request = client.postAbs(url);
    } else if (method == HttpMethod.DELETE) {
        request = client.deleteAbs(url);
    } else if (method == HttpMethod.GET) {
        request = client.getAbs(url);
    } else {
        request = client.putAbs(url);
    }
    request.exceptionHandler(error -> {
        Assert.fail(error.getLocalizedMessage());
    }).handler(handler);
    request.putHeader("Authorization", "test_tenant");
    request.putHeader("x-okapi-tenant", "test_tenant");
    request.putHeader("Accept", "application/json,text/plain");
    request.putHeader("Content-type", contentType);
    request.end(buffer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) HttpResponseMatchers.statusCodeIs(org.folio.rest.support.HttpResponseMatchers.statusCodeIs) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) InterfaceUrls.instancesStorageUrl(org.folio.rest.support.http.InterfaceUrls.instancesStorageUrl) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) JsonObjectMatchers.hasSoleMessgeContaining(org.folio.rest.support.JsonObjectMatchers.hasSoleMessgeContaining) Handler(io.vertx.core.Handler) org.folio.rest.support(org.folio.rest.support) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) LoanTypesClient(org.folio.rest.support.client.LoanTypesClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 35 with HttpClient

use of io.vertx.core.http.HttpClient in project pinpoint by naver.

the class VertxPluginTestStarter method request.

public void request(int port, String host, String uri) {
    final HttpClient client = vertx.createHttpClient();
    client.request(HttpMethod.GET, port, host, uri, new Handler<HttpClientResponse>() {

        @Override
        public void handle(HttpClientResponse httpClientResponse) {
            httpClientResponse.exceptionHandler(new Handler<Throwable>() {

                @Override
                public void handle(Throwable throwable) {
                }
            });
            httpClientResponse.endHandler(new Handler<Void>() {

                @Override
                public void handle(Void aVoid) {
                }
            });
        }
    }).end();
}
Also used : HttpClient(io.vertx.core.http.HttpClient) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Handler(io.vertx.core.Handler)

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