本文整理了Java中io.sphere.sdk.http.HttpClient.execute()
方法的一些代码示例,展示了HttpClient.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.execute()
方法的具体详情如下:
包路径:io.sphere.sdk.http.HttpClient
类名称:HttpClient
方法名:execute
暂无
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-java-client-core
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-java-client-core
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return httpClient.execute(httpRequest);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
return client.execute(httpRequest);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
this.request = httpRequest;
return httpClient.execute(httpRequest);
}
}
代码示例来源:origin: com.commercetools.sunrise/common
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
final long startTimestamp = System.currentTimeMillis();
return underlying.execute(httpRequest).thenApply(res -> {//important to not use async here
final long stopTimestamp = System.currentTimeMillis();
if (metricsEnabled) {
report(context, httpRequest, res, startTimestamp, stopTimestamp);
}
return res;
});
}
代码示例来源:origin: io.sphere.sdk.jvm/java-client-core
/**
* Executes a http auth sphere request and fetches a new access token.
* @return future of a token
*/
@Override
public CompletableFuture<Tokens> get() {
AUTH_LOGGER.debug(() -> "Fetching new token.");
final CompletableFuture<Tokens> result = httpClient.execute(newRequest()).thenApply(this::parseResponse);
logTokenResult(result);
return result;
}
代码示例来源:origin: com.commercetools.sunrise.payment/common
@Override
public HttpRequestResult sendHttpGetRequest(String url) {
HttpRequest request = HttpRequest.of(HttpMethod.GET, url);
try(HttpClient client = SphereClientFactory.of().createHttpClient()) {
HttpResponse response = client.execute(request).toCompletableFuture().get(10000, TimeUnit.MILLISECONDS);
return HttpRequestResult.of(request, response, null);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
return HttpRequestResult.of(request, null, e);
}
}
}
代码示例来源: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: io.sphere.jvmsdk/java-client
@Override
public <T> CompletableFuture<T> execute(final ClientRequest<T> clientRequest) {
final SphereInternalLogger logger = getLogger(clientRequest);
logger.debug(() -> clientRequest);
logger.trace(() -> {
final Optional<String> requestBody = clientRequest.httpRequest().getBody();
return requestBody.map(body -> JsonUtils.prettyPrintJsonStringSecure(body)).orElse("no request body present");
});
return requestExecutor.
execute(clientRequest).
thenApply(preProcess(clientRequest, clientRequest.resultMapper()));
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) {
lastUserAgent = httpRequest.getHeaders().getHeader(HttpHeaders.USER_AGENT).stream().findFirst().orElse(null);
return delegate.execute(httpRequest);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private <T> CompletableFuture<T> executeWithRecover(final SphereRequest<T> sphereRequest, final HttpRequest httpRequest, final int ttl) {
final CompletionStage<T> intermediateResult = httpClient.execute(httpRequest).thenApplyAsync(httpResponse -> {
try {
return processHttpResponse(sphereRequest, objectMapper, config, httpResponse, httpRequest);
} catch (final SphereException e) {
fillExceptionWithData(sphereRequest, httpResponse, e, config, httpRequest);
throw e;
}
});
final CompletableFuture<T> result = new CompletableFuture<T>();
intermediateResult.whenCompleteAsync((value, throwable) -> {
if (throwable != null) {
if (throwable.getCause() instanceof InvalidTokenException && ttl > 0 && tokenSupplier instanceof RefreshableSphereAccessTokenSupplier) {
final RefreshableSphereAccessTokenSupplier supplier = (RefreshableSphereAccessTokenSupplier) tokenSupplier;
final CompletionStage<T> nextAttemptCompletionStage = supplier.getNewToken().thenComposeAsync(token -> execute(sphereRequest, token, ttl - 1));
CompletableFutureUtils.transferResult(nextAttemptCompletionStage, result);
} else {
result.completeExceptionally(throwable);
}
} else {
result.complete(value);
}
});
return result;
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-java-client-core
/**
* Executes a http auth sphere request and fetches a new access token.
* @return future of a token
*/
@Override
public CompletionStage<Tokens> get() {
AUTH_LOGGER.debug(() -> "Fetching new token.");
final HttpRequest httpRequest = newRequest();
final CompletionStage<HttpResponse> httpResponseStage = httpClient.execute(httpRequest);
final CompletionStage<Tokens> result = httpResponseStage.thenApply((response) -> parseResponse(response, httpRequest));
result.whenCompleteAsync(this::logTokenResult);
return result;
}
代码示例来源:origin: io.sphere.sdk.jvm/java-client-core
private <T> CompletableFuture<T> execute(final SphereRequest<T> sphereRequest, final String token) {
final HttpRequest httpRequest = createHttpRequest(sphereRequest, token);
final SphereInternalLogger logger = getLogger(httpRequest);
logger.debug(() -> sphereRequest);
logger.trace(() -> {
final String output;
if (httpRequest.getBody().isPresent() && httpRequest.getBody().get() instanceof StringHttpRequestBody) {
final StringHttpRequestBody body = (StringHttpRequestBody) httpRequest.getBody().get();
final String unformattedJson = body.getString();
output = "send: " + unformattedJson + "\nformatted: " + JsonUtils.prettyPrintJsonStringSecure(unformattedJson);
} else {
output = "no request body present";
}
return output;
});
return httpClient.
execute(httpRequest).
thenApply(preProcess(sphereRequest, objectMapper, config));
}
代码示例来源:origin: com.commercetools.sunrise.payment/payone-adapter
@Override
public CompletionStage<Payment> requestHandling(String paymentId) {
try (final HttpClient httpClient = SphereClientFactory.of().createHttpClient()) {
return httpClient.execute(HttpRequest.of(HttpMethod.GET, buildUrl(paymentId)))
.thenCompose(response -> {
if(response.getStatusCode().equals(HttpStatusCode.OK_200)) {
return sphereClient.execute(PaymentByIdGet.of(paymentId));
}
return null;
});
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Test
public void shouldSendCorrelationId() throws Exception {
final CompletableFuture<HttpResponse> successful = CompletableFutureUtils
.successful(HttpResponse.of(200, "{\"access_token\": \"access_token\"}"));
when(httpClient.execute(requestCaptor.capture())).thenReturn(successful);
tokensSupplier.get().toCompletableFuture().get();
final HttpRequest httpRequest = requestCaptor.getValue();
final Optional<String> correlationIdHeader = httpRequest.getHeaders().findFlatHeader(HttpHeaders.X_CORRELATION_ID);
assertThat(correlationIdHeader).isPresent();
final String correlationId = correlationIdHeader.get();
final String[] correlationIdParts = correlationId.split("/");
assertThat(correlationIdParts).hasSize(2);
assertThat(correlationIdParts[0]).isEqualTo(authConfig.getProjectKey());
}
}
代码示例来源: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: 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: com.commercetools.sdk.jvm.core/commercetools-java-client-core
/**
* Executes a http auth sphere request and fetches a new access token.
* @return future of a token
*/
@Override
public CompletionStage<Tokens> get() {
rejectExcutionIfClosed("Token supplier is already closed.");
AUTH_LOGGER.debug(() -> isPasswordFlow() ? "Fetching new password flow token." : "Fetching new client credentials flow token.");
final HttpRequest httpRequest = newRequest();
final CompletionStage<HttpResponse> httpResponseStage = httpClient.execute(httpRequest);
final CompletionStage<Tokens> result = httpResponseStage.thenApply((response) -> parseResponse(response, httpRequest));
result.whenCompleteAsync(this::logTokenResult);
return result;
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
/**
* Executes a http auth sphere request and fetches a new access token.
* @return future of a token
*/
@Override
public CompletionStage<Tokens> get() {
rejectExcutionIfClosed("Token supplier is already closed.");
AUTH_LOGGER.debug(() -> isPasswordFlow() ? "Fetching new password flow token." : "Fetching new client credentials flow token.");
final HttpRequest httpRequest = newRequest();
final CompletionStage<HttpResponse> httpResponseStage = httpClient.execute(httpRequest);
final CompletionStage<Tokens> result = httpResponseStage.thenApply((response) -> parseResponse(response, httpRequest));
result.whenCompleteAsync(this::logTokenResult);
return result;
}
内容来源于网络,如有侵权,请联系作者删除!