public static <R>java.lang.Object bodyAsJson(io.vertx.ext.web.client.HttpResponse<Object> j_receiver, java.lang.Class<java.lang.Object> type) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.bodyAsJson(type)); } }
/** * @param type * @return the response body decoded as the specified <code>type</code> with the Jackson mapper, or <code>null</code> if a codec other than was used */ public <R> R bodyAsJson(Class<R> type) { R ret = (R)io.vertx.lang.rx.TypeArg.of(type).wrap(delegate.bodyAsJson(io.vertx.lang.rxjava.Helper.unwrap(type))); return ret; }
/** * @param type * @return the response body decoded as the specified <code>type</code> with the Jackson mapper, or <code>null</code> if a codec other than was used */ public <R> R bodyAsJson(Class<R> type) { R ret = (R)io.vertx.lang.rx.TypeArg.of(type).wrap(delegate.bodyAsJson(io.vertx.lang.rxjava.Helper.unwrap(type))); return ret; }
/** * Reads a secret from `path`. * * @param path the path * @param responseHandler the callback invoked with the result */ public void read(String path, Handler<AsyncResult<Secret>> responseHandler) { Objects.requireNonNull(responseHandler); client.get("/v1/" + Objects.requireNonNull(path)) .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "No token to access the vault")) .send(response -> { if (response.failed()) { responseHandler.handle(VaultException.toFailure("Unable to access the Vault", response.cause())); return; } HttpResponse<Buffer> result = response.result(); if (result.statusCode() != 200) { responseHandler.handle(VaultException.toFailure(result.statusMessage(), result.statusCode(), result.bodyAsString())); } else { Secret secret = result.bodyAsJson(Secret.class); responseHandler.handle(Future.succeededFuture(secret)); } }); }
/** * Write a secret to `path`. * * @param path the path * @param resultHandler the callback invoked with the result */ public void write(String path, JsonObject secrets, Handler<AsyncResult<Secret>> resultHandler) { Objects.requireNonNull(resultHandler); client.post("/v1/" + Objects.requireNonNull(path)) .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set")) .sendJsonObject(Objects.requireNonNull(secrets, "The secret must be set"), 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 || response.statusCode() == 204) { resultHandler.handle(Future.succeededFuture(response.bodyAsJson(Secret.class))); } else { resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(), response.bodyAsString())); } }); }
@Test public void testResponseUnknownContentTypeBodyAsJsonMapped() 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(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class)); testComplete(); })); await(); }