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


Java HTTP.Response方法代码示例

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


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

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

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

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

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

示例5: testBadJSONCustomHandler

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
@Test
public void testBadJSONCustomHandler() {

    serviceEndpointServer.stop();

    openPort = PortUtils.findOpenPort();
    serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder()
            .setPort(openPort)
            .setErrorHandler(new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) {
                    final Optional<HttpRequest> httpRequest = new HttpContext().getHttpRequest();
                    if (httpRequest.isPresent()) {
                        httpRequest.get().getReceiver().respondOK("\"Bad JSON" + throwable.getMessage() + "\"");
                        httpRequest.get().handled();
                    }
                }
            })
            .build();
    serviceEndpointServer.initServices(new TestService());
    serviceEndpointServer.startServerAndWait();


    HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"),
            "\"i\": 1, \"s\": \"string\"}, " +
                    "{\"i\": 2, \"s\": \"string2\"}]");

    assertEquals(200, response.status());


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

示例6: getPeers

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a list of host/ports for raft peers.
 * <p>
 * GET /v1/status/peers
 *
 * @return List of host/ports for raft peers.
 */
public List<String> getPeers() {


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

    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 get the peers", uri, httpResponse.code(), httpResponse.body());
    }

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

示例7: getValues

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves a list of {@link io.advantageous.consul.domain.KeyValue} objects for a specific key
 * from the key/value store.
 * <p>
 * GET /v1/keyValueStore/{key}?recurse
 *
 * @param key The key to retrieve.
 * @return A list of zero to many {@link io.advantageous.consul.domain.KeyValue} objects.
 */
public List<KeyValue> getValues(String key) {


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


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


    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 fromJsonArray(httpResponse.body(), KeyValue.class);

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

示例8: putValue

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
     * Puts a value into the key/value store.
     *
     * @param key        The key to use as index.
     * @param value      The value to index.
     * @param putOptions PUT options (e.g. wait, acquire).
     * @param flags      flags
     * @return <code>true</code> if the value was successfully indexed.
     */
    public boolean putValue(final String key, final String value, final long flags, final KeyValuePutOptions putOptions) {
        Integer cas = putOptions.getCas();
        String release = putOptions.getRelease();
        String acquire = putOptions.getAcquire();


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


//        httpRequestBuilder.addParam("recurse", "true");


        if (cas != null) {
            httpRequestBuilder.addParam("cas", cas.toString());
        }

        if (!Str.isEmpty(release)) {
            httpRequestBuilder.addParam("release", release);
        }

        if (!Str.isEmpty(acquire)) {
            httpRequestBuilder.addParam("acquire", acquire);
        }

        if (flags != 0) {
            httpRequestBuilder.addParam("flags", String.valueOf(flags));
        }


        httpRequestBuilder.setBody(value);
        httpRequestBuilder.setMethodPut();

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

        if (httpResponse.code() == 200) {
            return Boolean.parseBoolean(httpResponse.body());
        } else {
            die("Unable to put value", uri, putOptions, httpResponse.code(), httpResponse.body());
            return false;
        }

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

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

示例10: getNodeChecks

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * Retrieves the healthchecks for a node in a given datacenter with {@link io.advantageous.consul.domain.option.RequestOptions}.
 * <p>
 * GET /v1/health/node/{node}?dc={datacenter}
 *
 * @param node           node
 * @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>> getNodeChecks(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.toString() + "?" + httpRequestBuilder.paramString());

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

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

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

示例11: testPing3

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
@Test
public void testPing3() {
    HTTP.Response response = HTTP.jsonRestCallViaPUT(buildURL("ping3"), "\"foo\"");
    assertEquals(777, response.status());
    assertEquals("hello mom foo", response.body());
}
 
开发者ID:advantageous,项目名称:qbit,代码行数:7,代码来源:RestTests.java

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

示例13: test

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
@Test
public void test() {


    HTTP.Response response = HTTP.jsonRestCallViaPOST(buildURL("addall"),
            "[{\"i\": 1, \"s\": \"string\"}, " +
                    "{\"i\": 2, \"s\": \"string2\"}]");

    assertEquals(202, response.status());

    while (ref.get() == null) {
        Sys.sleep(10);
    }

    assertNotNull(ref.get());


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

示例14: getNodes

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
public ConsulResponse<List<Node>> getNodes(final String datacenter,
                                           final String tag,
                                           final RequestOptions requestOptions) {


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


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


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

    if (httpResponse.code() != 200) {
        die("Unable to retrieve the nodes", uri, httpResponse.code(), httpResponse.body());
    }
    return RequestUtils.consulResponseList(Node.class, httpResponse);

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

示例15: info

import io.advantageous.qbit.http.HTTP; //导入方法依赖的package包/类
/**
 * /v1/session/info/session:
 * Queries a given session
 *
 * @param sessionId      id of a session
 * @param requestOptions request options
 * @param datacenter     datacenter
 * @return Session for this session id.
 */
public Optional<Session> info(final String sessionId, final String datacenter, final RequestOptions requestOptions) {


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


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

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

    final List<Session> sessions = fromJsonArray(httpResponse.body(), Session.class);
    if (sessions == null || sessions.size() == 0) {
        return Optional.empty();
    }

    return Optional.of(sessions.get(0));

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


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