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


Java HttpClient类代码示例

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


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

示例1: createClient

import io.sphere.sdk.http.HttpClient; //导入依赖的package包/类
/**
 * Creates a {@link BlockingSphereClient} with a custom {@code timeout} with a custom {@link TimeUnit}.
 *
 * @param clientConfig the client configuration for the client.
 * @param timeout the timeout value for the client requests.
 * @param timeUnit the timeout time unit.
 * @return the instantiated {@link BlockingSphereClient}.
 */
public static synchronized SphereClient createClient(@Nonnull final SphereClientConfig clientConfig,
                                                     final long timeout,
                                                     @Nonnull final TimeUnit timeUnit) {
    if (!delegatesCache.containsKey(clientConfig)) {
        final HttpClient httpClient = getHttpClient();
        final SphereAccessTokenSupplier tokenSupplier =
            SphereAccessTokenSupplier.ofAutoRefresh(clientConfig, httpClient, false);
        final SphereClient underlying = SphereClient.of(clientConfig, httpClient, tokenSupplier);
        final SphereClient retryClient = withRetry(underlying);
        final SphereClient limitedParallelRequestsClient = withLimitedParallelRequests(retryClient);
        delegatesCache.put(clientConfig, limitedParallelRequestsClient);
    }
    return BlockingSphereClient.of(delegatesCache.get(clientConfig), timeout, timeUnit);
}
 
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:23,代码来源:ClientConfigurationUtils.java

示例2: getHttpClient

import io.sphere.sdk.http.HttpClient; //导入依赖的package包/类
/**
 * Gets an asynchronous {@link HttpClient} to be used by the {@link BlockingSphereClient}.
 * Client is created during first invocation and then cached.
 *
 * @return {@link HttpClient}
 */
private static synchronized HttpClient getHttpClient() {
    if (httpClient == null) {
        final AsyncHttpClient asyncHttpClient =
            new DefaultAsyncHttpClient(
                new DefaultAsyncHttpClientConfig.Builder().setAcceptAnyCertificate(true)
                                                          .setHandshakeTimeout((int) DEFAULT_TIMEOUT)
                                                          .build());
        httpClient = AsyncHttpClientAdapter.of(asyncHttpClient);
    }
    return httpClient;
}
 
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:18,代码来源:ClientConfigurationUtils.java

示例3: sendHttpGetRequest

import io.sphere.sdk.http.HttpClient; //导入依赖的package包/类
@Override
@Nonnull
public CompletionStage<HttpRequestResult> sendHttpGetRequest(String url) {
    HttpRequest request = HttpRequest.of(HttpMethod.GET, url);

    // TODO: must be injected, instead of initialization!!!
    HttpClient client = SphereClientFactory.of().createHttpClient();

    return client.execute(request)
                 .thenApplyAsync(response -> HttpRequestResult.of(request, response, null))
                 .exceptionally(throwable -> HttpRequestResult.of(request, null, throwable))
                 .whenCompleteAsync((response, throwable) -> client.close());
}
 
开发者ID:commercetools,项目名称:commercetools-payment-integration-java,代码行数:14,代码来源:PaymentConnectorHelperImpl.java

示例4: provideSphereClient

import io.sphere.sdk.http.HttpClient; //导入依赖的package包/类
public static BlockingSphereClient provideSphereClient(final HttpClient httpClient) {
    return provideSphereClient(httpClient, provideSphereClientConfig());
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:4,代码来源:SphereClientFixtures.java

示例5: provideHttpClient

import io.sphere.sdk.http.HttpClient; //导入依赖的package包/类
public static HttpClient provideHttpClient() {
    final AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(new DefaultAsyncHttpClientConfig.Builder().setAcceptAnyCertificate(true).build());
    return AsyncHttpClientAdapter.of(asyncHttpClient);
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:5,代码来源:SphereClientFixtures.java


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