本文整理了Java中io.sphere.sdk.http.HttpResponse.getStatusCode()
方法的一些代码示例,展示了HttpResponse.getStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getStatusCode()
方法的具体详情如下:
包路径:io.sphere.sdk.http.HttpResponse
类名称:HttpResponse
方法名:getStatusCode
暂无
代码示例来源:origin: io.sphere.sdk.jvm/sdk-http
public static boolean responseCodeStartsWith(final HttpResponse httpResponse, final int firstNumberOfStatusCode) {
final List<Integer> possibleValues = Arrays.asList(1, 2, 3, 4, 5);
if (!possibleValues.contains(firstNumberOfStatusCode)) {
final String message = format("Response code can only start with %s but it was %d.", possibleValues, firstNumberOfStatusCode);
throw new IllegalArgumentException(message);
}
final String actualResponseCodeAsString = Objects.toString(httpResponse.getStatusCode());
final String firstNumberAsString = Objects.toString(firstNumberOfStatusCode);
return actualResponseCodeAsString.startsWith(firstNumberAsString);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
public static boolean responseCodeStartsWith(final HttpResponse httpResponse, final int firstNumberOfStatusCode) {
final List<Integer> possibleValues = Arrays.asList(1, 2, 3, 4, 5);
if (!possibleValues.contains(firstNumberOfStatusCode)) {
final String message = format("Response code can only start with %s but it was %d.", possibleValues, firstNumberOfStatusCode);
throw new IllegalArgumentException(message);
}
final String actualResponseCodeAsString = Objects.toString(httpResponse.getStatusCode());
final String firstNumberAsString = Objects.toString(firstNumberOfStatusCode);
return actualResponseCodeAsString.startsWith(firstNumberAsString);
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
@Nullable
@Override
public final CustomObject<T> deserialize(final HttpResponse httpResponse) {
return (httpResponse.getStatusCode() == NOT_FOUND_404) ? null : deserializeCustomObject(httpResponse);
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
@Nullable
@Override
public final CustomObject<T> deserialize(final HttpResponse httpResponse) {
return (httpResponse.getStatusCode() == NOT_FOUND_404) ? null : deserializeCustomObject(httpResponse);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
@Override
public boolean canHandleResponse(final HttpResponse response) {
return response.hasSuccessResponseCode() || response.getStatusCode() == NOT_FOUND_404;
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Nullable
@Override
public final CustomObject<T> deserialize(final HttpResponse httpResponse) {
return (httpResponse.getStatusCode() == NOT_FOUND_404) ? null : deserializeCustomObject(httpResponse);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Nullable
@Override
public R deserialize(final HttpResponse httpResponse) {
return Optional.of(httpResponse)
.filter(r -> r.getStatusCode() != NOT_FOUND_404)
.map(r -> SphereRequestUtils.<R>deserialize(r, jacksonJavaType()))
.orElse(null);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
@Override
public Function<HttpResponse, Optional<T>> resultMapper() {
return httpResponse -> {
final Optional<T> result;
if (httpResponse.getStatusCode() == NOT_FOUND_404) {
result = Optional.empty();
} else {
result = Optional.of(resultMapperOf(typeReference()).apply(httpResponse));
}
return result;
};
}
代码示例来源: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/common
public void setUnderlyingHttpResponse(final HttpResponse httpResponse) {
final String s = "status=" + httpResponse.getStatusCode() + " " + JsonUtils.prettyPrintJsonStringSecureWithFallback(httpResponse.getResponseBody());
setUnderlyingHttpResponse(s);
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-java-client-core
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse) {
final SphereInternalLogger logger = getLogger(httpResponse);
logger.debug(() -> httpResponse);
logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present.") + "\n");
final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE);
if (notices != null) {
notices.stream().forEach(message -> logger.warn(() -> "Deprecation notice : " + message));
}
return parse(sphereRequest, objectMapper, config, httpResponse);
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-java-client-core
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) {
final SphereInternalLogger logger = getLogger(httpResponse);
logger.debug(() -> httpResponse);
logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present."));
final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE);
if (notices != null) {
notices.forEach(message -> logger.warn(() -> "Deprecation notice : " + message));
}
return parse(sphereRequest, objectMapper, config, httpResponse, httpRequest);
}
代码示例来源:origin: io.sphere.sdk.jvm/java-client-core
static <T> Function<HttpResponse, T> preProcess(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config) {
return httpResponse -> {
final SphereInternalLogger logger = getLogger(httpResponse);
logger.debug(() -> httpResponse);
logger.trace(() -> httpResponse.getStatusCode() + "\n" + httpResponse.getResponseBody().map(body -> JsonUtils.prettyPrintJsonStringSecure(bytesToString(body))).orElse("No body present.") + "\n");
final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE);
if (notices != null) {
notices.stream().forEach(message -> logger.warn(() -> "Deprecation notice : " + message));
}
return parse(httpResponse, sphereRequest, objectMapper, config);
};
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private static <T> T processHttpResponse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) {
final SphereInternalLogger logger = getLogger(httpResponse);
logger.debug(() -> httpResponse);
logger.trace(() -> httpResponse.getStatusCode() + "\n" + Optional.ofNullable(httpResponse.getResponseBody()).map(body -> SphereJsonUtils.prettyPrint(bytesToString(body))).orElse("No body present."));
final List<String> notices = httpResponse.getHeaders().getHeadersAsMap().get(SphereHttpHeaders.X_DEPRECATION_NOTICE);
if (notices != null) {
notices.forEach(message -> logger.warn(() -> "Deprecation notice : " + message));
}
return parse(sphereRequest, objectMapper, config, httpResponse, httpRequest);
}
代码示例来源: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 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();
}
}
内容来源于网络,如有侵权,请联系作者删除!