本文整理了Java中io.sphere.sdk.http.HttpClient
类的一些代码示例,展示了HttpClient
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient
类的具体详情如下:
包路径:io.sphere.sdk.http.HttpClient
类名称:HttpClient
暂无
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-java-client-core
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: com.commercetools.sunrise/common
@Override
public void close() {
underlying.close();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public final void testConnection() {
final HttpClient client = createClient();
final HttpResponse response = client.execute(HttpRequest.of(HttpMethod.GET, "http://dev.commercetools.com")).toCompletableFuture().join();
client.close();
final String body = new String(response.getResponseBody());
final Integer statusCode = response.getStatusCode();
assertThat(statusCode).isLessThan(400);
assertThat(body).containsIgnoringCase("commercetools");
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
when(sphereApiConfig.getProjectKey()).thenReturn(projectKey);
when(sphereApiConfig.getApiUrl()).thenReturn("http://api.commercetools.de");
when(httpClient.getUserAgent()).thenReturn("user-agent");
when(sphereAccessTokenSupplier.get()).thenReturn(CompletableFutureUtils.successful("token"));
when(httpClient.execute(httpRequestArgumentCaptor.capture()))
.thenReturn(CompletableFuture.completedFuture(HttpResponse.of(200, "ok")));
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Nullable
@Override
public String getUserAgent() {
return delegate.getUserAgent();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
final HttpClient client = createClient();
final HttpRequest httpRequest = HttpRequest.of(HttpMethod.POST, "http://localhost:" + port, HttpHeaders.of("foo", "bar"), requestBody);
final HttpResponse response = client.execute(httpRequest).toCompletableFuture().get(15, TimeUnit.SECONDS);
client.close();
final String receivedHttpHeadersAndBody = future.join();
LoggerFactory.getLogger(HttpClientAdapterTest.class).info(receivedHttpHeadersAndBody);
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Nullable
@Override
public String getUserAgent() {
return httpClient.getUserAgent();
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-java-client-core
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: com.commercetools.payment/common
@Override
@Nonnull
public CompletionStage<HttpRequestResult> sendHttpGetRequest(String url) {
HttpRequest request = HttpRequest.of(HttpMethod.GET, url);
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());
}
}
代码示例来源:origin: io.sphere.jvmsdk/java-client
@Override
public void close() {
requestExecutor.close();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private static String userAgent(final HttpClient httpClient) {
final String template = "${sdkLikeGitHubRepo}/${sdkVersion} (${underlyingHttpClient}) ${runtime}/${runtimeVersion} (${optionalOs}; ${optionalOsarch}) ${solutionInfos}";
final Map<String, String> values = new HashMap<>();
values.put("sdkLikeGitHubRepo", "commercetools-jvm-sdk");
values.put("sdkVersion", BuildInfo.version());
final String underlyingHttpClient = Optional.ofNullable(httpClient.getUserAgent()).orElse("unknown/" + BuildInfo.version());
values.put("underlyingHttpClient", underlyingHttpClient);
values.put("runtime", "Java");
values.put("runtimeVersion", SystemUtils.JAVA_RUNTIME_VERSION);
values.put("optionalOs", SystemUtils.OS_NAME);
values.put("optionalOsarch", SystemUtils.OS_ARCH);
values.put("solutionInfos", getSolutionInfoString());
return new StrSubstitutor(values).replace(template).trim();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void customClient() {
final HttpClient httpClient = createCustomHttpClient();
final CompletionStage<HttpResponse> completionStage =
httpClient.execute(HttpRequest.of(GET, "http://commercetools.com"));
final HttpResponse httpResponse = completionStage.toCompletableFuture().join();
assertThat(httpResponse.getStatusCode()).isLessThanOrEqualTo(302);
httpClient.close();
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public void close() {
client.close();
closed = true;
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-java-client-core
private static String userAgent(final HttpClient httpClient) {
final String template = "${sdkLikeGitHubRepo}/${sdkVersion} (${underlyingHttpClient}) ${runtime}/${runtimeVersion} (${optionalOs}; ${optionalOsarch}) ${solutionInfos}";
final Map<String, String> values = new HashMap<>();
values.put("sdkLikeGitHubRepo", "commercetools-jvm-sdk");
values.put("sdkVersion", BuildInfo.version());
final String underlyingHttpClient = Optional.ofNullable(httpClient.getUserAgent()).orElse("unknown/" + BuildInfo.version());
values.put("underlyingHttpClient", underlyingHttpClient);
values.put("runtime", "Java");
values.put("runtimeVersion", SystemUtils.JAVA_RUNTIME_VERSION);
values.put("optionalOs", SystemUtils.OS_NAME);
values.put("optionalOsarch", SystemUtils.OS_ARCH);
values.put("solutionInfos", getSolutionInfoString());
return new StrSubstitutor(values).replace(template).trim();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return client.execute(httpRequest);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public void close() {
httpClient.close();
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public final void userAgent() throws Exception {
try (final HttpClient client = createClient()) {
assertThat(client.getUserAgent()).matches("\\S+/\\S+");
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
this.request = httpRequest;
return httpClient.execute(httpRequest);
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public void close() {
delegate.close();
}
内容来源于网络,如有侵权,请联系作者删除!