本文整理了Java中io.vertx.ext.web.client.HttpResponse.bodyAsJsonObject()
方法的一些代码示例,展示了HttpResponse.bodyAsJsonObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.bodyAsJsonObject()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:bodyAsJsonObject
暂无
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* @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;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @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;
}
代码示例来源:origin: io.vertx/vertx-lang-groovy
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) {
代码示例来源:origin: io.vertx/vertx-consul-client
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()));
}
代码示例来源:origin: vert-x3/vertx-service-discovery
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;
}
代码示例来源:origin: vert-x3/vertx-config
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));
}
}
代码示例来源:origin: vert-x3/vertx-config
/**
* 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));
}
});
}
代码示例来源:origin: io.vertx/vertx-consul-client
@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;
}
代码示例来源:origin: vert-x3/vertx-config
JsonObject data = response.bodyAsJsonObject().getJsonObject("data");
if (data == null) {
future.fail("Invalid secret of configmap in namespace " + namespace + " " + name + ", the data " +
代码示例来源:origin: io.vertx/vertx-web-client
@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);
});
}
代码示例来源:origin: io.vertx/vertx-web-client
@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();
}
代码示例来源:origin: io.vertx/vertx-lang-js
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();
});
内容来源于网络,如有侵权,请联系作者删除!