当前位置: 首页>>代码示例>>Java>>正文


Java HTTP.getResponse方法代码示例

本文整理汇总了Java中io.advantageous.qbit.http.HTTP.getResponse方法的典型用法代码示例。如果您正苦于以下问题:Java HTTP.getResponse方法的具体用法?Java HTTP.getResponse怎么用?Java HTTP.getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.advantageous.qbit.http.HTTP的用法示例。


在下文中一共展示了HTTP.getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNode

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a single node for a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/catalog/node/{node}?dc={datacenter}
 *
 * @param node           node
 * @param datacenter     dc
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A list of matching {@link io.advantageous.consul.domain.CatalogService} objects.
 */
public ConsulResponse<CatalogNode> getNode(final String node,
                                           final String datacenter,
                                           final String tag,
                                           final RequestOptions requestOptions) {

    final URI uri = createURI("/node/" + node);

    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, tag, requestOptions, "");

    final HTTP.Response httpResponse = HTTP.getResponse(uri + "?" + httpRequestBuilder.paramString());
    if (httpResponse.code() != 200) {
        die("Unable to retrieve the node", uri, httpResponse.code(), httpResponse.body());
    }
    return RequestUtils.consulResponse(CatalogNode.class, httpResponse);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:28,代码来源:CatalogEndpoint.java

示例2: getChecks

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves all checks registered with the Agent.
 * <p>
 * GET /v1/agent/checks
 *
 * @return Map of Check ID to Checks.
 */
public Map<String, HealthCheck> getChecks() {

    final URI uri = createURI("/checks");

    final HTTP.Response response = HTTP.getResponse(uri.toString());

    final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create();
    if (response.status() == 200) {
        final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString());
        final Map<String, HealthCheck> returnMap = new HashMap<>(map.size());
        map.entrySet().forEach(entry -> {
            @SuppressWarnings("unchecked") HealthCheck healthCheck = fromMap((Map<String, Object>) entry.getValue(), HealthCheck.class);
            returnMap.put(entry.getKey(), healthCheck);

        });
        return returnMap;
    }
    die("Unable to get health checks", uri, response.status(), response.statusMessageAsString(),
            response.payloadAsString());
    return null;
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:29,代码来源:AgentEndpoint.java

示例3: getServices

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves all services registered with the Agent.
 * <p>
 * GET /v1/agent/services
 *
 * @return Map of Service ID to Services.
 */
public Map<String, Service> getServices() {

    final URI uri = createURI("/services");

    final HTTP.Response response = HTTP.getResponse(uri.toString());

    final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create();
    if (response.status() == 200) {
        final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString());
        final Map<String, Service> returnMap = new HashMap<>(map.size());
        map.entrySet().forEach(entry -> {
            @SuppressWarnings("unchecked") Service service = fromMap((Map<String, Object>) entry.getValue(), Service.class);
            returnMap.put(entry.getKey(), service);

        });
        return returnMap;
    }

    die("Unable to get list of services", uri, response.status(), response.payloadAsString());
    return null;
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:29,代码来源:AgentEndpoint.java

示例4: getDatacenters

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves all datacenters.
 * <p>
 * GET /v1/catalog/datacenters
 *
 * @return A list of datacenter names.
 */
public List<String> getDatacenters() {

    URI uri = createURI("/datacenters");

    HTTP.Response httpResponse = HTTP.getResponse(uri.toString());

    if (httpResponse.code() == 200) {
        return fromJsonArray(httpResponse.body(), String.class);
    }
    die("Unable to retrieve the datacenters", uri, httpResponse.code(), httpResponse.body());
    return Collections.emptyList();
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:20,代码来源:CatalogEndpoint.java

示例5: pingAgent

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Pings the Consul Agent.
 */
public void pingAgent() {

    HTTP.Response response = HTTP.getResponse(createURI("/self").toString());

    if (response.status() != 200) {
        die("Error pinging Consul", response.payloadAsString());
    }
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:12,代码来源:AgentEndpoint.java

示例6: deregisterCheck

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * De-registers a Health Check with the Agent
 *
 * @param checkId the id of the Check to deregister
 */
public void deregisterCheck(String checkId) {

    final URI uri = createURI("/check/deregister/" + checkId);

    HTTP.Response response = HTTP.getResponse(uri.toString());

    if (response.status() != 200) {
        die("Error removing registration of service with Consul",
                uri, checkId, response.status(), response.statusMessageAsString(),
                response.payloadAsString());
    }

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:19,代码来源:AgentEndpoint.java

示例7: getLeader

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves the host/port of the Consul leader.
 * <p>
 * GET /v1/status/leader
 *
 * @return The host/port of the leader.
 */
public String getLeader() {


    final URI uri = createURI("/leader");

    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(null, null, RequestOptions.BLANK, "");

    final HTTP.Response httpResponse = HTTP.getResponse(uri + "?" + httpRequestBuilder.paramString());

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the leader", uri, httpResponse.code(), httpResponse.body());
    }

    return fromJson(httpResponse.body(), String.class).replace("\"", "").trim();
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:24,代码来源:StatusEndpoint.java

示例8: getValue

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a {@link io.advantageous.consul.domain.KeyValue} for a specific key
 * from the key/value store.
 * <p>
 * GET /v1/keyValueStore/{key}
 *
 * @param key            The key to retrieve.
 * @param requestOptions The query options.
 * @return An {@link Optional} containing the value or {@link java.util.Optional#empty()}
 */
public Optional<KeyValue> getValue(final String key, RequestOptions requestOptions) {


    final URI uri = createURI("/" + key);


    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(null, null, requestOptions, "");


    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());

    if (httpResponse.code() == 404) {
        return Optional.empty();
    }

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the key", key, uri, httpResponse.code(), httpResponse.body());
    }

    return getKeyValueOptional(httpResponse);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:33,代码来源:KeyValueStoreEndpoint.java

示例9: getService

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a single service for a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/catalog/service/{service}?dc={datacenter}
 *
 * @param serviceName    service name
 * @param datacenter     datacenter
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A {@link io.advantageous.consul.domain.ConsulResponse} containing
 * {@link io.advantageous.consul.domain.CatalogService} objects.
 */
public ConsulResponse<List<CatalogService>> getService(final String serviceName, final String datacenter, final String tag,
                                                       RequestOptions requestOptions) {


    final URI uri = createURI("/service/" + serviceName);


    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, tag, requestOptions, "/");


    HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the service", uri, httpResponse.code(), httpResponse.body());
    }

    return RequestUtils.consulResponseList(CatalogService.class, httpResponse);

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:33,代码来源:CatalogEndpoint.java

示例10: getKeys

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a list of matching keys for the given key.
 * <p>
 * GET /v1/keyValueStore/{key}?keys
 *
 * @param key The key to retrieve.
 * @return A list of zero to many keys.
 */
public List<String> getKeys(String key) {


    final URI uri = createURI("/" + key);
    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(null, null, RequestOptions.BLANK, "");


    httpRequestBuilder.addParam("keys", "true");


    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());


    if (httpResponse.code() == 200) {
        return fromJsonArray(httpResponse.body(), String.class);
    } else {
        die("Unable to get nested keys", uri, key, httpResponse.code(), httpResponse.body());
        return Collections.emptyList();
    }
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:30,代码来源:KeyValueStoreEndpoint.java

示例11: getServices

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves all services for a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/catalog/services?dc={datacenter}
 *
 * @param datacenter     datacenter
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A {@link io.advantageous.consul.domain.ConsulResponse} containing a map of service name to list of tags.
 */
public ConsulResponse<Map<String, List<String>>> getServices(
        @SuppressWarnings("SameParameterValue") final String datacenter, @SuppressWarnings("SameParameterValue") final String tag,
        final RequestOptions requestOptions) {


    final URI uri = createURI("/services");


    final HttpRequestBuilder httpRequestBuilder = RequestUtils.getHttpRequestBuilder(datacenter, tag, requestOptions, "/");


    HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the datacenters", uri, httpResponse.code(), httpResponse.body());
    }

    //noinspection unchecked
    return (ConsulResponse<Map<String, List<String>>>) (Object) RequestUtils.consulResponse(Map.class, httpResponse);

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:32,代码来源:CatalogEndpoint.java

示例12: getServiceChecks

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves the healthchecks for a service in a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/health/service/{service}?dc={datacenter}
 *
 * @param service        service
 * @param datacenter     datacenter
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A {@link io.advantageous.consul.domain.ConsulResponse} containing a list of
 * {@link io.advantageous.consul.domain.HealthCheck} objects.
 */
public ConsulResponse<List<HealthCheck>> getServiceChecks(String service, final String datacenter,
                                                          final String tag,
                                                          RequestOptions requestOptions) {

    final URI uri = createURI("/checks/" + service);


    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, tag, requestOptions, "");


    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());


    if (httpResponse.code() != 200) {
        die("Unable to retrieve the service", uri, httpResponse.code(), httpResponse.body());
    }

    return RequestUtils.consulResponseList(HealthCheck.class, httpResponse);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:33,代码来源:HealthEndpoint.java

示例13: getChecksByState

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves the healthchecks for a state in a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/health/state/{state}?dc={datacenter}
 *
 * @param status         The state to query.
 * @param datacenter     datacenter
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A {@link io.advantageous.consul.domain.ConsulResponse} containing a list of
 * {@link io.advantageous.consul.domain.HealthCheck} objects.
 */
public ConsulResponse<List<HealthCheck>> getChecksByState(final Status status,
                                                          final String datacenter,
                                                          final String tag,
                                                          final RequestOptions requestOptions) {


    final URI uri = createURI("/state/" + status.getName());


    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, tag, requestOptions, "");


    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());


    if (httpResponse.code() != 200) {
        die("Unable to retrieve the service", uri, httpResponse.code(), httpResponse.body());
    }

    return RequestUtils.consulResponseList(HealthCheck.class, httpResponse);

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:36,代码来源:HealthEndpoint.java

示例14: getAllNodes

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves the healthchecks for all nodes in a given datacenter with
 * {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/health/service/{service}?dc={datacenter}
 *
 * @param service        The service to query.
 * @param datacenter     datacenter
 * @param tag            tag
 * @param requestOptions The Query Options to use.
 * @return A {@link io.advantageous.consul.domain.ConsulResponse} containing a list of
 * {@link io.advantageous.consul.domain.HealthCheck} objects.
 */
public ConsulResponse<List<ServiceHealth>> getAllNodes(final String service,
                                                       final String datacenter,
                                                       final String tag,
                                                       final RequestOptions requestOptions) {


    final URI uri = createURI("/service/" + service);


    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, tag, requestOptions, "");


    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());

    if (httpResponse == null) {
        die("No response from server for get all nodes request");
    }

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the service", uri, httpResponse.code(), httpResponse.body());
    }

    return RequestUtils.consulResponseList(ServiceHealth.class, httpResponse);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:39,代码来源:HealthEndpoint.java

示例15: getSessions

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * @param datacenter     datacenter
 * @param requestOptions request options for long poll and consistency.
 * @return list of sessions
 */
public List<Session> getSessions(final String datacenter, final RequestOptions requestOptions) {

    final URI uri = createURI("/list");
    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, null, requestOptions, "");

    HTTP.Response httpResponse = HTTP.getResponse(uri.toString() + "?" + httpRequestBuilder.paramString());

    if (httpResponse == null || httpResponse.code() != 200) {
        die("Unable to get the sessions", uri, httpResponse);
    }

    return fromJsonArray(httpResponse.body(), Session.class);

}
 
开发者ID:advantageous,项目名称:qbit,代码行数:21,代码来源:SessionEndpoint.java


注:本文中的io.advantageous.qbit.http.HTTP.getResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。