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


Java HTTP类代码示例

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


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

示例1: delete

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Deletes a specified key.
 *
 * @param key    The key to delete.
 * @param params Map of parameters, e.g. recurse.
 */
private void delete(String key, Map<String, String> params) {


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


    final Set<Map.Entry<String, String>> entries = params.entrySet();
    for (Map.Entry<String, String> entry : entries) {
        httpRequestBuilder.addParam(entry.getKey(), entry.getValue());
    }

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

    if (httpResponse.code() != 200) {
        die("Unable to delete key", uri, key, httpResponse.code(), httpResponse.body());
    }
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:27,代码来源:KeyValueStoreEndpoint.java

示例2: destroy

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Destroy the session.
 * @param sessionId id of session
 * @param session session
 * @param datacenter datacenter
 * @return true if success
 */
public boolean destroy(final String sessionId, final Session session, final String datacenter) {

    final URI uri = createURI("/destroy/" + sessionId);
    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, null, null, "");


    HTTP.Response httpResponse = HTTP.jsonRestCallViaPUT(uri.toString() + "?" + httpRequestBuilder.paramString(),
            toJson(session));

    if (httpResponse == null || httpResponse.code() != 200) {
        die("Unable destroy the session", sessionId, uri, httpResponse);
    }

    return httpResponse.code() == 200;
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:24,代码来源:SessionEndpoint.java

示例3: renew

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * /v1/session/renew: Renews a TTL-based session
 *
 * @param sessionId  session id
 * @param datacenter datacenter
 * @return session
 */
public Session renew(final String sessionId, final String datacenter) {

    final URI uri = createURI("/renew/" + sessionId);
    final HttpRequestBuilder httpRequestBuilder = RequestUtils
            .getHttpRequestBuilder(datacenter, null, null, "");


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

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

    return fromJsonArray(httpResponse.body(), Session.class).get(0);
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:24,代码来源:SessionEndpoint.java

示例4: 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

示例5: 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

示例6: 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

示例7: main

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
public static void main(final String... args) throws Exception {

        for (int index = 0; index < 5; index++) {

            HTTP.postJSON("http://localhost:8888/v1/todo-service/todo",
                    JsonFactory.toJson(new Todo("name" + index,
                            "desc" + index, System.currentTimeMillis() )));
            System.out.print(".");
        }
    }
 
开发者ID:MammatusTech,项目名称:qbit-microservices-examples,代码行数:11,代码来源:HttpClient.java

示例8: main

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
public static void main(final String... args) throws Exception {

        Category parent = new Category("foo");

        for (int index = 0; index < 100; index++) {

            HTTP.postJSON("http://localhost:8888/v1/todo-service/todo",
                    JsonFactory.toJson(new Todo("name" + index,
                            "desc" + index, System.currentTimeMillis(), parent )));
            System.out.print(".");
        }
    }
 
开发者ID:MammatusTech,项目名称:qbit-microservices-examples,代码行数:13,代码来源:HttpClient.java

示例9: 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

示例10: register

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Register a service with Consul.
 *
 * @param registration The registration payload.
 */
public void register(final Registration registration) {

    final URI uri = createURI("/service/register");
    HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(registration));

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

示例11: registerCheck

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Registers a Health Check with the Agent.
 *
 * @param check The Check to register.
 */
public void registerCheck(Check check) {

    final URI uri = createURI("/check/register");

    HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(check));

    if (response.status() != 200) {
        die("Error removing registration of service with Consul",
                uri, check, response.status(), response.statusMessageAsString(),
                response.payloadAsString());
    }
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:18,代码来源:AgentEndpoint.java

示例12: 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

示例13: getMembers

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Retrieves all members that the Agent can see in the gossip pool.
 * <p>
 * GET /v1/agent/members
 *
 * @return List of Members.
 */
public List<Member> getMembers() {

    final URI uri = createURI("/members");
    final HTTP.Response response = HTTP.getResponse(uri.toString());
    if (response.code() == 200) {
        return fromJsonArray(response.body(), Member.class);
    }
    die("Unable to read members", uri, response.code(), response.body());
    return Collections.emptyList();

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

示例14: forceLeave

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * GET /v1/agent/force-leave/{node}
 * <p>
 * Instructs the agent to force a node into the "left" state.
 *
 * @param node node
 */
public void forceLeave(String node) {

    final URI uri = createURI("/force-leave/" + node);
    final HTTP.Response httpResponse = HTTP.getResponse(uri.toString());

    if (httpResponse.code() != 200) {
        die("Unable to force leave", uri, httpResponse.code(), httpResponse.body());
    }
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:17,代码来源:AgentEndpoint.java

示例15: check

import io.advantageous.qbit.http.HTTP; //导入依赖的package包/类
/**
 * Checks in with Consul.
 *
 * @param checkId The Check ID to check in.
 * @param status  The current state of the Check.
 * @param note    Any note to associate with the Check.
 */
public void check(String checkId, Status status, String note) {

    final URI uri = createURI("/check/" + status.getUri() + "/" + checkId);

    final HTTP.Response httpResponse = Str.isEmpty(note) ? HTTP.getResponse(uri.toString()) :
            HTTP.getResponse(uri.toString() + "?note=" + note);

    if (httpResponse.code() != 200) {
        notRegistered("Unable to perform check", uri, httpResponse.code(), httpResponse.statusMessageAsString(),
                httpResponse.body());
    }

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


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