Client.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:gatekeeper 作者:
public List<String> list(String key) throws Exception {
    HttpRequest request = new HttpRequestWithBody(
        HttpMethod.GET,
        makeConsulUrl(key) + "?keys&separator=/"
    ).getHttpRequest();

    authorizeHttpRequest(request);

    HttpResponse<JsonNode> response;

    try {
        response = HttpClientHelper.request(request, JsonNode.class);
    } catch (Exception exception) {
        throw new ConsulException("Consul request failed", exception);
    }

    if (response.getStatus() == 404) {
        return null;
    }

    JsonNode data = response.getBody();

    if (!data.isArray()) {
        throw new ConsulException("Malformed response - expected an array");
    }

    List<String> keys = new ArrayList<>(data.getArray().length());

    data.getArray().forEach((object) -> {
        String iter = object.toString();

        if (prefix != null) {
            iter = iter.substring(prefix.length());
        }

        keys.add(iter);
    });

    return keys;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号