Search in sources :

Example 76 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest 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 77 with HttpClientRequest

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

the class HttpClient method post.

public void post(URL url, Object body, String tenantId, Handler<HttpClientResponse> responseHandler) {
    HttpClientRequest request = client.postAbs(url.toString(), responseHandler);
    request.headers().add("Accept", "application/json, text/plain");
    request.headers().add("Content-type", "application/json");
    if (tenantId != null) {
        request.headers().add(TENANT_HEADER, tenantId);
    }
    if (body == null) {
        request.end();
        return;
    }
    String encodedBody = Json.encodePrettily(body);
    log.debug("POST {0}, Request: {1}", url.toString(), encodedBody);
    request.end(encodedBody);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 78 with HttpClientRequest

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

the class HttpClient method delete.

public void delete(String url, String tenantId, Handler<HttpClientResponse> responseHandler) {
    HttpClientRequest request = client.deleteAbs(url, responseHandler);
    request.headers().add("Accept", "application/json, text/plain");
    if (tenantId != null) {
        request.headers().add(TENANT_HEADER, tenantId);
    }
    request.end();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 79 with HttpClientRequest

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

the class HttpClient method put.

public void put(URL url, Object body, String tenantId, Handler<HttpClientResponse> responseHandler) {
    HttpClientRequest request = client.putAbs(url.toString(), responseHandler);
    request.headers().add("Accept", "application/json, text/plain");
    request.headers().add("Content-type", "application/json");
    if (tenantId != null) {
        request.headers().add(TENANT_HEADER, tenantId);
    }
    request.end(Json.encodePrettily(body));
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Example 80 with HttpClientRequest

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

the class HttpClient method get.

public void get(String url, String tenantId, Handler<HttpClientResponse> responseHandler) {
    HttpClientRequest request = client.getAbs(url, responseHandler);
    request.headers().add("Accept", "application/json");
    if (tenantId != null) {
        request.headers().add(TENANT_HEADER, tenantId);
    }
    request.end();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest)

Aggregations

HttpClientRequest (io.vertx.core.http.HttpClientRequest)159 Test (org.junit.Test)82 Buffer (io.vertx.core.buffer.Buffer)73 HttpClient (io.vertx.core.http.HttpClient)56 HttpMethod (io.vertx.core.http.HttpMethod)51 HttpClientOptions (io.vertx.core.http.HttpClientOptions)50 HttpClientResponse (io.vertx.core.http.HttpClientResponse)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 Handler (io.vertx.core.Handler)40 HttpServerResponse (io.vertx.core.http.HttpServerResponse)40 CompletableFuture (java.util.concurrent.CompletableFuture)38 CountDownLatch (java.util.concurrent.CountDownLatch)36 TimeUnit (java.util.concurrent.TimeUnit)36 Vertx (io.vertx.core.Vertx)35 HttpServerOptions (io.vertx.core.http.HttpServerOptions)35 ArrayList (java.util.ArrayList)35 List (java.util.List)35 AtomicReference (java.util.concurrent.atomic.AtomicReference)34 MultiMap (io.vertx.core.MultiMap)33 HttpVersion (io.vertx.core.http.HttpVersion)31