io.vertx.ext.web.client.HttpResponse Java Examples

The following examples show how to use io.vertx.ext.web.client.HttpResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_noexplode_object with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormNoexplodeObject(
    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 = "/cookie/form/noexplode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieObjectForm("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #2
Source File: Application.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
private void handleDefault(RoutingContext routingContext) {
  webClient
      .get(METADATA_PORT, METADATA_HOST, "/computeMetadata/v1/project/project-id")
      .putHeader("Metadata-Flavor", "Google")
      .expect(ResponsePredicate.SC_OK)
      .send(
          res -> {
            if (res.succeeded()) {
              HttpResponse<Buffer> response = res.result();
              routingContext
                  .response()
                  .putHeader("content-type", "text/html")
                  .end("Hello World! from " + response.body());
            } else {
              routingContext.fail(res.cause());
            }
          });
}
 
Example #3
Source File: ConsumerTest.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Test
void createConsumerWithGeneratedName(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    JsonObject json = new JsonObject();
    AtomicReference<String> name = new AtomicReference<>();

    CompletableFuture<Boolean> create = new CompletableFuture<>();
    consumerService()
        .createConsumerRequest(groupId, json)
            .as(BodyCodec.jsonObject())
            .sendJsonObject(json, ar -> {
                context.verify(() -> {
                    assertThat(ar.succeeded(), is(true));
                    HttpResponse<JsonObject> response = ar.result();
                    assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
                    JsonObject bridgeResponse = response.body();
                    String consumerInstanceId = bridgeResponse.getString("instance_id");
                    name.set(consumerInstanceId);
                    assertThat(consumerInstanceId.startsWith(config.get(BridgeConfig.BRIDGE_ID).toString()), is(true));
                    create.complete(true);
                });
            });
    create.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    consumerService()
        .deleteConsumer(context, groupId, name.get());
    context.completeNow();
}
 
Example #4
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call path_multi_label_matrix with empty body.
 * @param colorLabel Parameter color_label inside path
 * @param colorMatrix Parameter color_matrix inside path
 * @param handler The handler for the asynchronous request
 */
public void pathMultiLabelMatrix(
    List<Object> colorLabel,
    Map<String, Object> colorMatrix,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (colorLabel == null) throw new RuntimeException("Missing parameter colorLabel in path");
    if (colorMatrix == null) throw new RuntimeException("Missing parameter colorMatrix in path");


    // Generate the uri
    String uri = "/path/multi/{.color_label}{;color_matrix*}/test";
    uri = uri.replaceAll("\\{{1}([.;?*+]*([^\\{\\}.;?*+]+)[^\\}]*)\\}{1}", "{$2}"); //Remove * . ; ? from url template
    uri = uri.replace("{color_label}", this.renderPathArrayLabel("color_label", colorLabel));
    uri = uri.replace("{color_matrix}", this.renderPathObjectMatrixExplode("color_matrix", colorMatrix));


    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #5
Source File: WebClientExamples.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public void predicateCustomErrorWithBody() {
  ErrorConverter converter = ErrorConverter.createFullBody(result -> {

    // Invoked after the response body is fully received
    HttpResponse<Buffer> response = result.response();

    if (response
      .getHeader("content-type")
      .equals("application/json")) {

      // Error body is JSON data
      JsonObject body = response.bodyAsJsonObject();

      return new MyCustomException(
        body.getString("code"),
        body.getString("message"));
    }

    // Fallback to defaut message
    return new MyCustomException(result.message());
  });

  ResponsePredicate predicate = ResponsePredicate
    .create(ResponsePredicate.SC_SUCCESS, converter);
}
 
Example #6
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_explode_empty with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormExplodeEmpty(
    String color,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null) throw new RuntimeException("Missing parameter color");


    // Generate the uri
    String uri = "/cookie/form/explode/empty";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieParam("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #7
Source File: HttpKafkaConsumer.java    From client-examples with Apache License 2.0 6 votes vote down vote up
private Future<Void> deleteConsumer() {
    Future<Void> fut = Future.future();

    this.client.delete(this.consumer.getBaseUri())
        .putHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "application/vnd.kafka.v2+json")
        .as(BodyCodec.jsonObject())
        .send(ar -> {
            if (ar.succeeded()) {
                HttpResponse<JsonObject> response = ar.result();
                if (response.statusCode() == HttpResponseStatus.NO_CONTENT.code()) {
                    log.info("Consumer {} deleted", this.consumer.getInstanceId());
                    fut.complete();
                } else {
                    fut.fail(new RuntimeException("Got HTTP status code " + response.statusCode()));
                } 
            } else {
                fut.fail(ar.cause());
            }
        });
    return fut;
}
 
Example #8
Source File: HttpKafkaConsumer.java    From client-examples with Apache License 2.0 6 votes vote down vote up
private Future<Void> subscribe(CreatedConsumer consumer, String topic) {
    Future<Void> fut = Future.future();

    JsonObject topics = new JsonObject()
        .put("topics", new JsonArray().add(topic));
    
    this.client.post(consumer.getBaseUri() + "/subscription")
        .putHeader(HttpHeaderNames.CONTENT_LENGTH.toString(), String.valueOf(topics.toBuffer().length()))
        .putHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "application/vnd.kafka.v2+json")
        .as(BodyCodec.jsonObject())
        .sendJsonObject(topics, ar -> {
            if (ar.succeeded()) {
                HttpResponse<JsonObject> response = ar.result();
                if (response.statusCode() == HttpResponseStatus.NO_CONTENT.code()) {
                    log.info("Subscribed to {}", topic);
                    fut.complete();
                } else {
                    fut.fail(new RuntimeException("Got HTTP status code " + response.statusCode()));
                }
            } else {
                fut.fail(ar.cause());
            }
        });
    return fut;
}
 
Example #9
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call query_pipeDelimited_noexplode_object with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void queryPipeDelimitedNoexplodeObject(
    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/pipeDelimited/noexplode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addQueryObjectPipeDelimited("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #10
Source File: VertxJobsServiceTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
void testGetScheduleTimeJobNotFound(@Mock HttpRequest<Buffer> request, @Mock HttpResponse<Buffer> response) {
    when(webClient.get(anyString())).thenReturn(request);
    AsyncResult<HttpResponse<Buffer>> asyncResult = mock(AsyncResult.class);
    when(asyncResult.succeeded()).thenReturn(true);
    when(asyncResult.result()).thenReturn(response);
    when(response.statusCode()).thenReturn(404);
    
    doAnswer(invocationOnMock -> {
        Handler<AsyncResult<HttpResponse<Buffer>>> handler = invocationOnMock.getArgument(0);
        executor.submit(() -> handler.handle(asyncResult));
        return null;
    }).when(request).send(any());
    
    assertThatThrownBy(() -> tested.getScheduledTime("123"))
        .hasCauseExactlyInstanceOf(JobNotFoundException.class);
    
    verify(webClient).get("/jobs/123");
}
 
Example #11
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call path_multi_simple_matrix with empty body.
 * @param colorSimple Parameter color_simple inside path
 * @param colorMatrix Parameter color_matrix inside path
 * @param handler The handler for the asynchronous request
 */
public void pathMultiSimpleMatrix(
    String colorSimple,
    List<Object> colorMatrix,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (colorSimple == null) throw new RuntimeException("Missing parameter colorSimple in path");
    if (colorMatrix == null) throw new RuntimeException("Missing parameter colorMatrix in path");


    // Generate the uri
    String uri = "/path/multi/{color_simple}{;color_matrix}/test";
    uri = uri.replaceAll("\\{{1}([.;?*+]*([^\\{\\}.;?*+]+)[^\\}]*)\\}{1}", "{$2}"); //Remove * . ; ? from url template
    uri = uri.replace("{color_simple}", this.renderPathParam("color_simple", colorSimple));
    uri = uri.replace("{color_matrix}", this.renderPathArrayMatrix("color_matrix", colorMatrix));


    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #12
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call query_spaceDelimited_noexplode_object with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void querySpaceDelimitedNoexplodeObject(
    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/spaceDelimited/noexplode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addQueryObjectSpaceDelimited("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #13
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_noexplode_object with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormNoexplodeObject(
    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 = "/cookie/form/noexplode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieObjectForm("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #14
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call query_form_explode_object with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void queryFormExplodeObject(
    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/form/explode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addQueryObjectFormExplode("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #15
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call path_multi_label_matrix with empty body.
 * @param colorLabel Parameter color_label inside path
 * @param colorMatrix Parameter color_matrix inside path
 * @param handler The handler for the asynchronous request
 */
public void pathMultiLabelMatrix(
    List<Object> colorLabel,
    Map<String, Object> colorMatrix,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (colorLabel == null) throw new RuntimeException("Missing parameter colorLabel in path");
    if (colorMatrix == null) throw new RuntimeException("Missing parameter colorMatrix in path");


    // Generate the uri
    String uri = "/path/multi/{.color_label}{;color_matrix*}/test";
    uri = uri.replaceAll("\\{{1}([.;?*+]*([^\\{\\}.;?*+]+)[^\\}]*)\\}{1}", "{$2}"); //Remove * . ; ? from url template
    uri = uri.replace("{color_label}", this.renderPathArrayLabel("color_label", colorLabel));
    uri = uri.replace("{color_matrix}", this.renderPathObjectMatrixExplode("color_matrix", colorMatrix));


    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #16
Source File: ValidationHandlerTest.java    From vertx-starter with Apache License 2.0 6 votes vote down vote up
private void doTest(Vertx vertx, VertxTestContext testContext, ValidationHandler validator, MultiMap params, String extension, Handler<HttpResponse<Buffer>> handler) {
  Router router = Router.router(vertx);
  router.route().handler(validator).handler(rc -> {
    VertxProject vertProject = rc.get(WebVerticle.VERTX_PROJECT_KEY);
    rc.response().end(Json.encodePrettily(vertProject));
  });

  vertx.createHttpServer(new HttpServerOptions().setPort(0))
    .requestHandler(router)
    .listen(testContext.succeeding(server -> {

      WebClientOptions options = new WebClientOptions().setDefaultPort(server.actualPort());
      WebClient webClient = WebClient.create(vertx, options);

      HttpRequest<Buffer> request = webClient.get("/starter" + extension);
      request.queryParams().addAll(params);

      request.send(testContext.succeeding(handler));
    }));
}
 
Example #17
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_explode_array with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormExplodeArray(
    List<Object> color,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null) throw new RuntimeException("Missing parameter color");


    // Generate the uri
    String uri = "/cookie/form/explode/array";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieArrayFormExplode("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #18
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call query_spaceDelimited_noexplode_object with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void querySpaceDelimitedNoexplodeObject(
    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/spaceDelimited/noexplode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addQueryObjectSpaceDelimited("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #19
Source File: SlimVaultClient.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
/**
 * Looks up for the current token metadata.
 *
 * @param resultHandler the callback invoked with the result
 */
public void lookupSelf(Handler<AsyncResult<Lookup>> resultHandler) {
  client.get("/v1/auth/token/lookup-self")
    .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must not be null"))
    .send(ar -> {
      if (ar.failed()) {
        resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
        return;
      }
      HttpResponse<Buffer> response = ar.result();
      if (response.statusCode() != 200) {
        resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
          response.bodyAsString()));
      } else {
        JsonObject object = response.bodyAsJsonObject();
        Lookup lookup = object.getJsonObject("data").mapTo(Lookup.class);
        resultHandler.handle(Future.succeededFuture(lookup));
      }
    });
}
 
Example #20
Source File: KubernetesServiceImporter.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
private Future<JsonArray> retrieveServices(String token) {
  Promise<JsonArray> promise = Promise.promise();
  String path = "/api/v1/namespaces/" + namespace + "/services";
  client.get(path)
    .putHeader("Authorization", "Bearer " + token)
    .send(resp -> {
      if (resp.failed()) {
        promise.fail(resp.cause());
      } else if (resp.result().statusCode() != 200) {
        promise.fail("Unable to retrieve services from namespace " + namespace + ", status code: "
          + resp.result().statusCode() + ", content: " + resp.result().bodyAsString());
      } else {
        HttpResponse<Buffer> response = resp.result();
        JsonArray items = response.bodyAsJsonObject().getJsonArray("items");
        if (items == null) {
          promise.fail("Unable to retrieve services from namespace " + namespace + " - no items");
        } else {
          promise.complete(items);
          watch(client, token, response.bodyAsJsonObject().getJsonObject("metadata").getString("resourceVersion"));
        }
      }
    });
  return promise.future();
}
 
Example #21
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call header_simple_explode_object with empty body.
 * @param color Parameter color inside header
 * @param handler The handler for the asynchronous request
 */
public void headerSimpleExplodeObject(
    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 = "/header/simple/explode/object";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addHeaderObjectSimpleExplode("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #22
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call query_form_noexplode_array with empty body.
 * @param color Parameter color inside query
 * @param handler The handler for the asynchronous request
 */
public void queryFormNoexplodeArray(
    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/form/noexplode/array";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.addQueryArrayForm("color", color, request);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #23
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_explode_string with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormExplodeString(
    String color,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null) throw new RuntimeException("Missing parameter color");


    // Generate the uri
    String uri = "/cookie/form/explode/string";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieParam("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #24
Source File: ConsumerTest.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Test
void createConsumerWrongFormat(VertxTestContext context) throws InterruptedException, TimeoutException, ExecutionException {
    JsonObject consumerJson = new JsonObject()
        .put("name", name)
        .put("format", "foo");

    // create consumer
    CompletableFuture<Boolean> create = new CompletableFuture<>();
    consumerService().createConsumerRequest(groupId, consumerJson)
            .sendJsonObject(consumerJson, ar -> {
                context.verify(() -> {
                    assertThat(ar.succeeded(), is(true));
                    HttpResponse<JsonObject> response = ar.result();
                    assertThat(response.statusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
                    HttpBridgeError error = HttpBridgeError.fromJson(response.body());
                    assertThat(error.getCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
                    assertThat(error.getMessage(), is("Invalid format type."));
                });
                create.complete(true);
            });

    create.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    context.completeNow();
    assertThat(context.awaitCompletion(TEST_TIMEOUT, TimeUnit.SECONDS), is(true));
}
 
Example #25
Source File: AdminClientTest.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Test
void getTopicNotFoundTest(VertxTestContext context) throws Exception {
    String topic = "testGetTopicNotFound";

    baseService()
            .getRequest("/topics/" + topic)
            .as(BodyCodec.jsonObject())
            .send(ar -> {
                context.verify(() -> {
                    assertThat(ar.succeeded(), is(true));
                    HttpResponse<JsonObject> response = ar.result();
                    assertThat(response.statusCode(), is(HttpResponseStatus.NOT_FOUND.code()));
                });
                context.completeNow();
            });
}
 
Example #26
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_noexplode_string with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormNoexplodeString(
    String color,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null) throw new RuntimeException("Missing parameter color");


    // Generate the uri
    String uri = "/cookie/form/noexplode/string";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieParam("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #27
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call path_multi_simple_label with empty body.
 * @param colorSimple Parameter color_simple inside path
 * @param colorLabel Parameter color_label inside path
 * @param handler The handler for the asynchronous request
 */
public void pathMultiSimpleLabel(
    String colorSimple,
    List<Object> colorLabel,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (colorSimple == null) throw new RuntimeException("Missing parameter colorSimple in path");
    if (colorLabel == null) throw new RuntimeException("Missing parameter colorLabel in path");


    // Generate the uri
    String uri = "/path/multi/{color_simple}{.color_label}/test";
    uri = uri.replaceAll("\\{{1}([.;?*+]*([^\\{\\}.;?*+]+)[^\\}]*)\\}{1}", "{$2}"); //Remove * . ; ? from url template
    uri = uri.replace("{color_simple}", this.renderPathParam("color_simple", colorSimple));
    uri = uri.replace("{color_label}", this.renderPathArrayLabel("color_label", colorLabel));


    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #28
Source File: OtherServicesTest.java    From strimzi-kafka-bridge with Apache License 2.0 6 votes vote down vote up
@Test
void postToNonexistentEndpoint(VertxTestContext context) {
    baseService()
        .postRequest("/not-existing-endpoint")
        .as(BodyCodec.jsonObject())
        .sendJsonObject(null, ar -> {
            context.verify(() -> {
                assertThat(ar.succeeded(), is(true));
                HttpResponse<JsonObject> response = ar.result();
                HttpBridgeError error = HttpBridgeError.fromJson(response.body());
                assertThat(response.statusCode(), is(HttpResponseStatus.NOT_FOUND.code()));
                assertThat(error.getCode(), is(HttpResponseStatus.NOT_FOUND.code()));
            });
            context.completeNow();
        });
}
 
Example #29
Source File: ApiClient.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
/**
 * Call cookie_form_noexplode_string with empty body.
 * @param color Parameter color inside cookie
 * @param handler The handler for the asynchronous request
 */
public void cookieFormNoexplodeString(
    String color,
    Handler<AsyncResult<HttpResponse>> handler) {
    // Check required params
    if (color == null) throw new RuntimeException("Missing parameter color");


    // Generate the uri
    String uri = "/cookie/form/noexplode/string";

    HttpRequest request = client.get(uri);

    MultiMap requestCookies = MultiMap.caseInsensitiveMultiMap();
    if (color != null) this.renderCookieParam("color", color, requestCookies);


    this.renderAndAttachCookieHeader(request, requestCookies);
    request.send(handler);
}
 
Example #30
Source File: ConsumerTest.java    From strimzi-kafka-bridge with Apache License 2.0 5 votes vote down vote up
@Test
void consumerDeletedAfterInactivity(VertxTestContext context) {
    CompletableFuture<Boolean> create = new CompletableFuture<>();

    consumerService()
        .createConsumerRequest(groupId, consumerJson)
            .as(BodyCodec.jsonObject())
            .sendJsonObject(consumerJson, ar -> {
                context.verify(() -> {
                    assertThat(ar.succeeded(), is(true));
                    HttpResponse<JsonObject> response = ar.result();
                    assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
                    JsonObject bridgeResponse = response.body();
                    String consumerInstanceId = bridgeResponse.getString("instance_id");
                    String consumerBaseUri = bridgeResponse.getString("base_uri");
                    assertThat(consumerInstanceId, is(name));
                    assertThat(consumerBaseUri, is(Urls.consumerInstance(groupId, name)));

                    vertx.setTimer(timeout * 2 * 1000L, timeouted -> {
                        CompletableFuture<Boolean> delete = new CompletableFuture<>();
                        // consumer deletion
                        consumerService()
                            .deleteConsumerRequest(groupId, name)
                                .send(consumerDeletedResponse -> {
                                    context.verify(() -> assertThat(ar.succeeded(), is(true)));

                                    HttpResponse<JsonObject> deletionResponse = consumerDeletedResponse.result();
                                    assertThat(deletionResponse.statusCode(), is(HttpResponseStatus.NOT_FOUND.code()));
                                    assertThat(deletionResponse.body().getString("message"), is("The specified consumer instance was not found."));

                                    delete.complete(true);
                                    context.completeNow();
                                });
                    });
                });
                create.complete(true);
            });
}