本文整理了Java中io.sphere.sdk.http.HttpResponse
类的一些代码示例,展示了HttpResponse
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse
类的具体详情如下:
包路径:io.sphere.sdk.http.HttpResponse
类名称:HttpResponse
暂无
代码示例来源:origin: io.sphere.sdk.jvm/sdk-http
default HttpResponse withoutRequest() {
return HttpResponse.of(getStatusCode(), getResponseBody(), null, getHeaders());
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-models
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
}
代码示例来源:origin: io.sphere.jvmsdk/common
public HttpResponse withoutRequest() {
return of(getStatusCode(), getResponseBody());
}
}
代码示例来源:origin: io.sphere.sdk.jvm/common
public static HttpResponse of(final int status, final Optional<byte[]> body, final Optional<HttpRequest> associatedRequest, final HttpHeaders headers) {
return of(status, body, associatedRequest, Optional.of(headers));
}
代码示例来源: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: com.commercetools.sdk.jvm.core/commercetools-models
@Override
protected CustomObject<T> deserializeCustomObject(final HttpResponse httpResponse) {
return Optional.ofNullable(httpResponse)
.filter(response -> response.getResponseBody() != null && response.getResponseBody().length > 0)
.map(response -> response.getResponseBody())
.map(responseBody -> SphereJsonUtils.<CustomObject<T>>readObject(httpResponse.getResponseBody(), javaType))
.orElse(null);
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-java-client-core
private static boolean isServiceNotAvailable(final HttpResponse httpResponse) {
return httpResponse.getStatusCode() == 503 || Optional.ofNullable(httpResponse.getResponseBody()).map(b -> bytesToString(b)).map(s -> s.contains("<h2>Service Unavailable</h2>")).orElse(false);
}
代码示例来源: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
/**
Checks if the response can be handled by {@link #deserialize(HttpResponse)}.
Use case 1: A http response returns 404 and the this {@link SphereRequest}
can handle this error by returning an empty optional, an empty list or throwing a domain specific exception.
@param httpResponse the http response which shall be transformed
@return true if the http response can be consumed, false otherwise
*/
default boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() && httpResponse.getResponseBody() != null;
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
.map(r -> r.getStatusCode())
.map(r -> r.toString())
.map(r -> "response code " + r)
.map(r -> r.getHeaders())
.flatMap(headers -> headers.findFlatHeader(correlationIdHeaderName))
.map(id -> " with " + correlationIdHeaderName + " `" + id + "`")
代码示例来源:origin: io.sphere.sdk.jvm/java-client-core
private List<String> getDeprecationNoticeHeaderValues(final HttpResponse response) {
return response.getHeaders().getHeader(SphereHttpHeaders.X_DEPRECATION_NOTICE);
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
public static SphereInternalLogger getLogger(final HttpResponse response) {
final String firstPathElement = Optional.ofNullable(response.getAssociatedRequest())
.map(r -> getPathElement(r)).orElse("endpoint-unknown");
final String lastPathElement = Optional.ofNullable(response.getAssociatedRequest())
.map(r -> requestOrCommandScopeSegment(r)).orElse("execution-type-unknown");
return getLogger(firstPathElement + ".responses." + lastPathElement);
}
代码示例来源:origin: io.sphere.sdk.jvm/sdk-http
static HttpResponse of(@Nullable final Integer status, final String responseBody, final HttpHeaders headers) {
return of(status, responseBody, null, headers);
}
代码示例来源: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: com.commercetools.sdk.jvm.core/commercetools-models
@Override
protected CustomObject<T> deserializeCustomObject(final HttpResponse httpResponse) {
return Optional.ofNullable(httpResponse)
.filter(response -> response.getResponseBody() != null && response.getResponseBody().length > 0)
.map(response -> response.getResponseBody())
.map(responseBody -> SphereJsonUtils.<CustomObject<T>>readObject(httpResponse.getResponseBody(), javaType))
.orElse(null);
}
}
代码示例来源:origin: io.sphere.sdk.jvm/java-client-core
private static boolean isServiceNotAvailable(final HttpResponse httpResponse) {
return httpResponse.getStatusCode() == 503 || httpResponse.getResponseBody().map(b -> bytesToString(b)).map(s -> s.contains("<h2>Service Unavailable</h2>")).orElse(false);
}
代码示例来源: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: io.sphere.sdk.jvm/common
/**
Checks if the response can be handled by {@link #resultMapper()}.
Use case 1: A http response returns 404 and the this {@link SphereRequest}
can handle this error by returning an empty optional, an empty list or throwing a domain specific exception.
@param response the http response which shall be transformed
@return true if the http response can be consumed, false otherwise
*/
default boolean canHandleResponse(final HttpResponse response) {
return response.hasSuccessResponseCode() && response.getResponseBody().isPresent();
}
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-java-client-core
private List<String> getDeprecationNoticeHeaderValues(final HttpResponse response) {
return response.getHeaders().getHeader(SphereHttpHeaders.X_DEPRECATION_NOTICE);
}
代码示例来源:origin: io.sphere.jvmsdk/common
public static SphereInternalLogger getLogger(final HttpResponse response) {
final String firstPathElement = response.getAssociatedRequest()
.map(r -> getFirstPathElement(r)).orElse("endpoint-unknown");
final String lastPathElement = response.getAssociatedRequest()
.map(r -> requestOrCommandScopeSegment(r.getHttpMethod())).orElse("execution-type-unknown");
return getLogger(firstPathElement + ".responses." + lastPathElement);
}
内容来源于网络,如有侵权,请联系作者删除!