@Override public final String getMessage() { StringBuilder builder = new StringBuilder("\n===== BEGIN EXCEPTION OUTPUT =====").append("\n"); final String httpRequest = getSphereRequest().map(x -> x.httpRequestIntent()).map(Object::toString).orElse("<unknown>"); return builder .append("SDK: ").append(BuildInfo.version()).append("\n") .append("project: ").append(getProjectKey().orElse("<unknown>")).append("\n") .append(getSphereRequest().map(x -> x.httpRequestIntent()).map(x -> "" + x.getHttpMethod() + " " + x.getPath()).map(x -> "endpoint: " + x + "\n").orElse("")) .append("Java: ").append(System.getProperty("java.version")).append("\n") .append("cwd: ").append(System.getProperty("user.dir")).append("\n") .append("date: ").append(new Date()).append("\n") .append("sphere request: ").append(getSphereRequest().map(Object::toString).orElse("<unknown>")).append("\n") //duplicated in case SphereRequest does not implement a proper to String .append("http request: ").append(httpRequest).append("\n") .append("http response: ").append(getHttpResponse().map(Object::toString).orElse("<unknown>")).append("\n") .append(Optional.ofNullable(super.getMessage()).map(s -> "detailMessage: " + s + "\n").orElse("")) .append("additional notes: ").append(additionalNotes).append("\n") .append("Javadoc: ").append("http://sphereio.github.io/sphere-jvm-sdk/javadoc/").append(BuildInfo.version()).append("/").append(this.getClass().getCanonicalName().replace('.', '/')).append(".html").append("\n") .append("===== END EXCEPTION OUTPUT =====").toString(); }
@Override public final String getMessage() { StringBuilder builder = new StringBuilder(); return builder .append(Optional.ofNullable(super.getMessage()).map(s -> "detailMessage: " + s + "\n").orElse("")) .append(httpSummary()) .append(responseBodyFormatted()) .append("http response: ").append(Optional.ofNullable(getHttpResponse()).map(Object::toString).orElse("<unknown>")).append("\n") .append("SDK: ").append(BuildInfo.version()).append("\n") .append("project: ").append(Optional.ofNullable(getProjectKey()).orElse("<unknown>")).append("\n") .append(Optional.ofNullable(getSphereRequest()).map(x -> x.httpRequestIntent()).map(x -> "" + x.getHttpMethod() + " " + x.getPath()).map(x -> "endpoint: " + x + "\n").orElse("")) .append("Java: ").append(System.getProperty("java.version")).append("\n") .append("cwd: ").append(System.getProperty("user.dir")).append("\n") .append("sphere request: ").append(Optional.ofNullable(getSphereRequest()).map(Object::toString).orElse("<unknown>")).append("\n") //duplicated in case SphereRequest does not implement a proper to String .append(httpRequestLine()) .append(requestBodyFormatted()) .append("additional notes: ").append(additionalNotes).append("\n") .append("Javadoc: ").append("http://commercetools.github.io/commercetools-jvm-sdk/apidocs/").append(this.getClass().getCanonicalName().replace('.', '/')).append(".html").append("\n") .toString(); }
public HttpRequestIntent withHeaders(final HttpHeaders headers) { return HttpRequestIntent.of(getHttpMethod(), path, headers, getBody()); }
public static void logProductRequest(final Logger logger, final ProductProjectionSearch request, final PagedSearchResult<ProductProjection> result) { final HttpRequestIntent httpRequest = request.httpRequestIntent(); final String requestBody = printableRequestBody(httpRequest) .map(body -> " with body {" + body + "}") .orElse(""); logger.debug("Fetched {} out of {} products with request {} {}", result.getCount(), result.getTotal(), httpRequest.getHttpMethod(), httpRequest.getPath() + requestBody); }
final String httpMethod = Optional.ofNullable(this.httpRequest) .map(r -> r.getHttpMethod().toString()) .orElseGet(() -> this.httpRequestIntent.getHttpMethod().toString());
public HttpRequestIntent withPath(final String path) { return HttpRequestIntent.of(getHttpMethod(), path, getHeaders(), getBody()); }
public HttpRequestIntent prefixPath(final String prefix) { return HttpRequestIntent.of(getHttpMethod(), prefix + getPath(), getHeaders(), getBody()); }
public HttpRequestIntent prefixPath(final String prefix) { return HttpRequestIntent.of(getHttpMethod(), prefix + getPath(), getHeaders(), getBody()); }
public HttpRequest toHttpRequest(final String baseUrl) { return HttpRequest.of(getHttpMethod(), baseUrl + getPath(), getHeaders(), getBody()); }
public HttpRequest toHttpRequest(final String baseUrl) { return HttpRequest.of(getHttpMethod(), baseUrl + getPath(), getHeaders(), getBody()); }
public HttpRequestIntent plusHeader(final String name, final String value) { return HttpRequestIntent.of(getHttpMethod(), getPath(), getHeaders().plus(name, value), getBody()); }
public HttpRequestIntent plusHeader(final String name, final String value) { return HttpRequestIntent.of(getHttpMethod(), getPath(), getHeaders().plus(name, value), getBody()); }
private static Predicate<RetryContext> isDeleteAndNewVersionIsKnown() { return retryContext -> retryContext.getLatestError() instanceof ConcurrentModificationException && ((ConcurrentModificationException) retryContext.getLatestError()).getCurrentVersion() != null && retryContext.getLatestParameter() instanceof SphereRequest && ((SphereRequest) retryContext.getLatestParameter()).httpRequestIntent().getHttpMethod() == HttpMethod.DELETE; }