Search in sources :

Example 31 with HttpRequest

use of io.vertx.ext.web.client.HttpRequest in project raml-module-builder by folio-org.

the class DemoRamlRestTest method checkURLs.

public static Buffer checkURLs(TestContext context, String tenant, String url, int codeExpected, String accept) {
    Buffer res = Buffer.buffer();
    try {
        Async async = context.async();
        WebClient client = WebClient.create(vertx);
        final HttpRequest<Buffer> request = client.getAbs(url);
        if (tenant != null) {
            request.headers().add("x-okapi-tenant", tenant);
        }
        if (accept != null) {
            request.headers().add("Accept", accept);
        }
        request.send(x -> {
            x.map(httpClientResponse -> {
                res.appendBuffer(httpClientResponse.body());
                log.info(httpClientResponse.statusCode() + ", " + codeExpected + " status expected: " + url);
                log.info(res);
                context.assertEquals(codeExpected, httpClientResponse.statusCode(), url);
                async.complete();
                return null;
            }).otherwise(f -> {
                context.fail(url + " - " + f.getMessage());
                async.complete();
                return null;
            });
        });
        async.await();
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        context.fail(e);
    }
    return res;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TestContext(io.vertx.ext.unit.TestContext) CoreMatchers(org.hamcrest.CoreMatchers) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) HttpResponse(io.vertx.ext.web.client.HttpResponse) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) WebClient(io.vertx.ext.web.client.WebClient) Date(java.util.Date) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) RunWith(org.junit.runner.RunWith) Timeout(io.vertx.ext.unit.junit.Timeout) VertxUtils(org.folio.rest.tools.utils.VertxUtils) TenantClient(org.folio.rest.client.TenantClient) RequestSpecification(io.restassured.specification.RequestSpecification) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AsyncResult(io.vertx.core.AsyncResult) Datetime(org.folio.rest.jaxrs.model.Datetime) Metadata(org.folio.rest.jaxrs.model.Metadata) NetClient(io.vertx.core.net.NetClient) AfterClass(org.junit.AfterClass) AdminLoglevelPutLevel(org.folio.rest.jaxrs.model.AdminLoglevelPutLevel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) JsonPathParser(org.folio.rest.tools.parser.JsonPathParser) Data(org.folio.rest.jaxrs.model.Data) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) PostgresClient(org.folio.rest.persist.PostgresClient) HttpRequest(io.vertx.ext.web.client.HttpRequest) Book(org.folio.rest.jaxrs.model.Book) Logger(org.apache.logging.log4j.Logger) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) DeploymentOptions(io.vertx.core.DeploymentOptions) AdminClient(org.folio.rest.client.AdminClient) HttpMethod(io.vertx.core.http.HttpMethod) TenantAttributes(org.folio.rest.jaxrs.model.TenantAttributes) RestAssured.given(io.restassured.RestAssured.given) Books(org.folio.rest.jaxrs.model.Books) RestAssured(io.restassured.RestAssured) LogManager(org.apache.logging.log4j.LogManager) TenantInit(org.folio.rest.tools.utils.TenantInit) NetSocket(io.vertx.core.net.NetSocket) Async(io.vertx.ext.unit.Async) WebClient(io.vertx.ext.web.client.WebClient)

Example 32 with HttpRequest

use of io.vertx.ext.web.client.HttpRequest in project vertx-web by vert-x3.

the class ApiClient method querySpaceDelimitedNoexplodeArray.

/**
 * Call query_spaceDelimited_noexplode_array with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void querySpaceDelimitedNoexplodeArray(List<Object> color, Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null)
        throw new RuntimeException("Missing parameter color");
    // Generate the uri
    String uri = "/query/spaceDelimited/noexplode/array";
    HttpRequest request = client.get(uri);
    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null)
        this.addQueryArraySpaceDelimited("color", color, request);
    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
Also used : HttpRequest(io.vertx.ext.web.client.HttpRequest) MultiMap(io.vertx.core.MultiMap)

Example 33 with HttpRequest

use of io.vertx.ext.web.client.HttpRequest in project vertx-web by vert-x3.

the class ApiClient method queryDeepObjectExplodeObject.

/**
 * Call query_deepObject_explode_object with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void queryDeepObjectExplodeObject(Map<String, Object> color, Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null)
        throw new RuntimeException("Missing parameter color");
    // Generate the uri
    String uri = "/query/deepObject/explode/object";
    HttpRequest request = client.get(uri);
    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null)
        this.addQueryObjectDeepObjectExplode("color", color, request);
    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
Also used : HttpRequest(io.vertx.ext.web.client.HttpRequest) MultiMap(io.vertx.core.MultiMap)

Example 34 with HttpRequest

use of io.vertx.ext.web.client.HttpRequest in project vertx-web by vert-x3.

the class ApiClient method queryFormExplodeEmpty.

/**
 * Call query_form_explode_empty with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void queryFormExplodeEmpty(String color, Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null)
        throw new RuntimeException("Missing parameter color");
    // Generate the uri
    String uri = "/query/form/explode/empty";
    HttpRequest request = client.get(uri);
    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null)
        this.addQueryParam("color", color, request);
    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
Also used : HttpRequest(io.vertx.ext.web.client.HttpRequest) MultiMap(io.vertx.core.MultiMap)

Example 35 with HttpRequest

use of io.vertx.ext.web.client.HttpRequest in project vertx-web by vert-x3.

the class ApiClient method pathMatrixExplodeString.

/**
 * Call path_matrix_explode_string with empty body.
 * @param color Parameter color inside path
 * @param handler The handler for the asynchronous request
 */
public void pathMatrixExplodeString(String color, Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null)
        throw new RuntimeException("Missing parameter color in path");
    // Generate the uri
    String uri = "/path/matrix/explode/string/{;color*}";
    // Remove * . ; ? from url template
    uri = uri.replaceAll("\\{{1}([.;?*+]*([^\\{\\}.;?*+]+)[^\\}]*)\\}{1}", "{$2}");
    uri = uri.replace("{color}", this.renderPathMatrix("color", color));
    HttpRequest request = client.get(uri);
    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
Also used : HttpRequest(io.vertx.ext.web.client.HttpRequest) MultiMap(io.vertx.core.MultiMap)

Aggregations

HttpRequest (io.vertx.ext.web.client.HttpRequest)53 MultiMap (io.vertx.core.MultiMap)52 AsyncResult (io.vertx.core.AsyncResult)5 Buffer (io.vertx.core.buffer.Buffer)5 HttpResponse (io.vertx.ext.web.client.HttpResponse)5 WebClient (io.vertx.ext.web.client.WebClient)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)4 Span (io.opentracing.Span)4 Future (io.vertx.core.Future)4 Handler (io.vertx.core.Handler)4 HttpHeaders (io.vertx.core.http.HttpHeaders)4 VertxExtension (io.vertx.junit5.VertxExtension)4 VertxTestContext (io.vertx.junit5.VertxTestContext)4 MqttEndpoint (io.vertx.mqtt.MqttEndpoint)4 MqttPublishMessage (io.vertx.mqtt.messages.MqttPublishMessage)4 HttpURLConnection (java.net.HttpURLConnection)4 URLEncoder (java.net.URLEncoder)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Map (java.util.Map)4