Search in sources :

Example 71 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project georocket by georocket.

the class S3Store method getOne.

@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
    String key = PathUtils.removeLeadingSlash(PathUtils.normalize(path));
    vertx.<URL>executeBlocking(f -> {
        f.complete(generatePresignedUrl(key, HttpMethod.GET));
    }, ar -> {
        if (ar.failed()) {
            handler.handle(Future.failedFuture(ar.cause()));
            return;
        }
        URL u = ar.result();
        log.debug("GET " + u);
        HttpClientRequest request = client.get(ar.result().getFile());
        request.putHeader("Host", u.getHost());
        request.exceptionHandler(t -> {
            handler.handle(Future.failedFuture(t));
        });
        request.handler(response -> {
            if (response.statusCode() == 200) {
                String contentLength = response.getHeader("Content-Length");
                long chunkSize = Long.parseLong(contentLength);
                handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunkSize, response)));
            } else {
                Buffer errorBody = Buffer.buffer();
                response.handler(buf -> {
                    errorBody.appendBuffer(buf);
                });
                response.endHandler(v -> {
                    log.error(errorBody);
                    handler.handle(Future.failedFuture(response.statusMessage()));
                });
            }
        });
        request.end();
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) HttpClientRequest(io.vertx.core.http.HttpClientRequest) URL(java.net.URL)

Example 72 with HttpClientRequest

use of io.vertx.core.http.HttpClientRequest in project georocket by georocket.

the class StoreEndpointTest method doScrolledStorepointRequest.

/**
 * Performs request against the server and checks for the scroll headers.
 * Fails when the headers are not present or an error occured during the request.
 *
 * @param context Test context
 * @param url url
 * @param checkHeaders should the test check the headers
 * @param checkScrollIdHeaderPresent should the test check the scroll id
 * @param handler response handler
 */
private void doScrolledStorepointRequest(TestContext context, String url, Boolean checkHeaders, Boolean checkScrollIdHeaderPresent, Handler<HttpClientResponse> handler) {
    HttpClient client = createHttpClient();
    HttpClientRequest request = client.get(url, response -> {
        if (checkHeaders) {
            checkScrollingResponsePresent(response, context, checkScrollIdHeaderPresent);
        }
        handler.handle(response);
    });
    request.exceptionHandler(x -> {
        context.fail("Exception during query.");
    });
    request.end();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Example 73 with HttpClientRequest

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

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

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

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