/** * @return the response body decoded as a , or <code>null</code> if a codec other than was used */ public JsonArray bodyAsJsonArray() { if (cached_10 != null) { return cached_10; } JsonArray ret = delegate.bodyAsJsonArray(); cached_10 = ret; return ret; }
/** * @return the response body decoded as a , or <code>null</code> if a codec other than was used */ public JsonArray bodyAsJsonArray() { if (cached_10 != null) { return cached_10; } JsonArray ret = delegate.bodyAsJsonArray(); cached_10 = ret; return ret; }
public static java.util.List<Object> bodyAsJsonArray(io.vertx.ext.web.client.HttpResponse<Object> j_receiver) { return io.vertx.core.impl.ConversionHelper.fromJsonArray(j_receiver.bodyAsJsonArray()); } public static <R>java.lang.Object bodyAsJson(io.vertx.ext.web.client.HttpResponse<Object> j_receiver, java.lang.Class<java.lang.Object> type) {
private <T> void requestArray(HttpMethod method, String path, Query query, String body, Handler<AsyncResult<T>> resultHandler, BiFunction<JsonArray, MultiMap, T> mapper) { request(DEFAULT_VALID_CODES, method, path, query, body, resultHandler, resp -> mapper.apply(resp.bodyAsJsonArray(), resp.headers())); }
@Override public ConsulClient getKeysWithOptions(String keyPrefix, BlockingQueryOptions options, Handler<AsyncResult<List<String>>> resultHandler) { Query query = Query.of("recurse", true).put("keys", true).put(options); request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(keyPrefix), query, null, resultHandler, resp -> { if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) { return new ArrayList<>(); } else { return resp.bodyAsJsonArray().stream().map(Object::toString).collect(Collectors.toList()); } }); return this; }
@Override public ConsulClient getValuesWithOptions(String keyPrefix, BlockingQueryOptions options, Handler<AsyncResult<KeyValueList>> resultHandler) { Query query = Query.of("recurse", true).put(options); request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(keyPrefix), query, null, resultHandler, resp -> { if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) { return new KeyValueList(); } else { List<KeyValue> list = resp.bodyAsJsonArray().stream().map(obj -> KVParser.parse((JsonObject) obj)).collect(Collectors.toList()); return new KeyValueList().setList(list).setIndex(Long.parseLong(resp.headers().get(INDEX_HEADER))); } }); return this; }
@Override public ConsulClient getValueWithOptions(String key, BlockingQueryOptions options, Handler<AsyncResult<KeyValue>> resultHandler) { request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(key), new Query().put(options), null, resultHandler, resp -> { if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) { return new KeyValue(); } else { return KVParser.parse(resp.bodyAsJsonArray().getJsonObject(0)); } }); return this; }
@Test public void testResponseUnknownContentTypeBodyAsJsonArray() throws Exception { JsonArray expected = new JsonArray().add("cheese").add("wine"); 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.bodyAsJsonArray()); testComplete(); })); await(); }