/** * @return the response body decoded as , or <code>null</code> if a codec other than was used */ public JsonObject bodyAsJsonObject() { if (cached_9 != null) { return cached_9; } JsonObject ret = delegate.bodyAsJsonObject(); cached_9 = ret; return ret; }
/** * @return the response body decoded as , or <code>null</code> if a codec other than was used */ public JsonObject bodyAsJsonObject() { if (cached_9 != null) { return cached_9; } JsonObject ret = delegate.bodyAsJsonObject(); cached_9 = ret; return ret; }
public static java.util.Map<String, Object> bodyAsJsonObject(io.vertx.ext.web.client.HttpResponse<Object> j_receiver) { return io.vertx.core.impl.ConversionHelper.fromJsonObject(j_receiver.bodyAsJsonObject()); } public static java.util.List<Object> bodyAsJsonArray(io.vertx.ext.web.client.HttpResponse<Object> j_receiver) {
private <T> void requestObject(HttpMethod method, String path, Query query, String body, Handler<AsyncResult<T>> resultHandler, BiFunction<JsonObject, MultiMap, T> mapper) { request(DEFAULT_VALID_CODES, method, path, query, body, resultHandler, resp -> mapper.apply(resp.bodyAsJsonObject(), resp.headers())); }
private Future<JsonArray> retrieveServices(String token) { Future<JsonArray> future = Future.future(); String path = "/api/v1/namespaces/" + namespace + "/services"; client.get(path) .putHeader("Authorization", "Bearer " + token) .send(resp -> { if (resp.failed()) { future.fail(resp.cause()); } else if (resp.result().statusCode() != 200) { future.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) { future.fail("Unable to retrieve services from namespace " + namespace + " - no items"); } else { future.complete(items); watch(client, token, response.bodyAsJsonObject().getJsonObject("metadata").getString("resourceVersion")); } } }); return future; }
private void manageAuthResult(Handler<AsyncResult<Auth>> resultHandler, HttpResponse<Buffer> response) { if (response.statusCode() != 200) { resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(), response.bodyAsString())); } else { JsonObject object = response.bodyAsJsonObject(); Auth auth = object.getJsonObject("auth").mapTo(Auth.class); resultHandler.handle(Future.succeededFuture(auth)); } }
/** * 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)); } }); }
@Override public ConsulClient transaction(TxnRequest request, Handler<AsyncResult<TxnResponse>> resultHandler) { String boby = request.toJson().getJsonArray("operations").encode(); request(TXN_VALID_CODES, HttpMethod.PUT, "/v1/txn", null, boby, resultHandler, resp -> TxnResponseParser.parse(resp.bodyAsJsonObject())); return this; }
JsonObject data = response.bodyAsJsonObject().getJsonObject("data"); if (data == null) { future.fail("Invalid secret of configmap in namespace " + namespace + " " + name + ", the data " +
@Test public void testExpectCustomExceptionWithResponseBody() throws Exception { UUID uuid = UUID.randomUUID(); ResponsePredicate predicate = ResponsePredicate.create(ResponsePredicate.SC_SUCCESS, ErrorConverter.createFullBody(result -> { JsonObject body = result.response().bodyAsJsonObject(); return new CustomException(UUID.fromString(body.getString("tag")), body.getString("message")); })); testExpectation(true, req -> req.expect(predicate), httpServerResponse -> { httpServerResponse .setStatusCode(400) .end(new JsonObject().put("tag", uuid.toString()).put("message", "tilt").toBuffer()); }, ar -> { Throwable cause = ar.cause(); assertThat(cause, instanceOf(CustomException.class)); CustomException customException = (CustomException) cause; assertEquals("tilt", customException.getMessage()); assertEquals(uuid, customException.tag); }); }
@Test public void testResponseUnknownContentTypeBodyAsJsonObject() throws Exception { JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu"); server.requestHandler(req -> req.response().end(expected.encode())); startServer(); HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath"); get.send(onSuccess(resp -> { assertEquals(200, resp.statusCode()); assertEquals(expected, resp.bodyAsJsonObject()); testComplete(); })); await(); }
context.fail(async.cause()); assertStatus(async.result().bodyAsJsonObject(), "UP"); assertData(async.result().bodyAsJsonObject(), null); nothing.complete(); }); context.fail(async.cause()); assertStatus(async.result().bodyAsJsonObject(), "UP"); assertData(async.result().bodyAsJsonObject(), null); ok.complete(); }); context.fail(async.cause()); assertStatus(async.result().bodyAsJsonObject(), "DOWN"); assertData(async.result().bodyAsJsonObject(), null); ko.complete(); }); context.fail(async.cause()); assertStatus(async.result().bodyAsJsonObject(), "UP"); assertData(async.result().bodyAsJsonObject(), new JsonObject().put("foo", "bar")); extra.complete(); });