本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
}
示例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());
}
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}