本文整理了Java中io.sphere.sdk.http.HttpResponse.getResponseBody()
方法的一些代码示例,展示了HttpResponse.getResponseBody()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getResponseBody()
方法的具体详情如下:
包路径:io.sphere.sdk.http.HttpResponse
类名称:HttpResponse
方法名:getResponseBody
暂无
代码示例来源: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: 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-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-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: commercetools/commercetools-jvm-sdk
protected CustomObject<T> deserializeCustomObject(final HttpResponse httpResponse) {
if(!httpResponse.hasSuccessResponseCode()){
return null;
}
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(), customObjectJavaType))
.orElse(null);
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
protected CustomObject<T> deserializeCustomObject(final HttpResponse httpResponse) {
if(!httpResponse.hasSuccessResponseCode()){
return null;
}
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(), customObjectJavaType))
.orElse(null);
}
代码示例来源: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: io.sphere.sdk.jvm/common
@Override
public Function<HttpResponse, Optional<JsonNode>> resultMapper() {
return httpResponse -> httpResponse.getResponseBody().map(body -> JsonUtils.readObject(new TypeReference<JsonNode>() {
}, body));
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-test-lib
@Nullable
@Override
public JsonNode deserialize(final HttpResponse httpResponse) {
return SphereJsonUtils.parse(httpResponse.getResponseBody());
}
代码示例来源: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: commercetools/commercetools-jvm-sdk
private String responseBodyFormatted() {
try {
return Optional.ofNullable(getHttpResponse())
.map(r -> r.getResponseBody())
.map(b -> SphereJsonUtils.prettyPrint(new String(b, StandardCharsets.UTF_8)))
.map(s -> "http response formatted body: " + s + "\n")
.orElse("");
} catch (final Exception e) {
return "";
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
@Nullable
@Override
public JsonNode deserialize(final HttpResponse httpResponse) {
return Optional.ofNullable(httpResponse.getResponseBody())
.map(body -> SphereJsonUtils.readObject(body, TypeReferences.jsonNodeTypeReference()))
.orElse(null);
}
代码示例来源:origin: io.sphere.sdk.jvm/common
public final Optional<JsonNode> getJsonBody() {
final Function<byte[], JsonNode> f = body -> JsonUtils.readTree(body);
try {
return httpResponse.flatMap(r -> r.getResponseBody().map(f));
} catch (final Exception e) {
SphereInternalLogger.getLogger(SphereServiceException.class).error(() -> "Cannot provide JSON body.", e);
return Optional.empty();
}
}
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
@Override
public ProductDiscount deserialize(final HttpResponse httpResponse) {
return SphereJsonUtils.readObject(httpResponse.getResponseBody(), ProductDiscount.typeReference());
}
代码示例来源:origin: com.commercetools.sdk.jvm.core/commercetools-models
@Override
public Project deserialize(final HttpResponse httpResponse) {
return SphereJsonUtils.readObject(httpResponse.getResponseBody(), Project.typeReference());
}
代码示例来源: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: 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.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);
};
}
内容来源于网络,如有侵权,请联系作者删除!