io.sphere.sdk.http.HttpRequest.getPath()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中io.sphere.sdk.http.HttpRequest.getPath()方法的一些代码示例,展示了HttpRequest.getPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getPath()方法的具体详情如下:
包路径:io.sphere.sdk.http.HttpRequest
类名称:HttpRequest
方法名:getPath

HttpRequest.getPath介绍

暂无

代码示例

代码示例来源:origin: io.sphere.jvmsdk/common

private static String getFirstPathElement(final HttpRequest httpRequest) {
  final String path = httpRequest.getPath();
  final String leadingSlashRemoved = path.substring(1);
  return substringBefore(substringBefore(leadingSlashRemoved, "/"), "?");
}

代码示例来源:origin: io.sphere.jvmsdk/common

public void setUnderlyingHttpRequest(final HttpRequest httpRequest) {
  final String body = httpRequest.getBody().map(s -> JsonUtils.prettyPrintJsonStringSecureWithFallback(s)).orElse("<no body>");
  final String requestAsString = new StringBuilder(httpRequest.getHttpMethod().toString()).append(" ").append(httpRequest.getPath()).append("\n").append(body).toString();
  setUnderlyingHttpRequest(requestAsString);
}

代码示例来源:origin: io.sphere.jvmsdk/java-client

<T> Request asNingRequest(final Requestable requestable) {
  final HttpRequest request = requestable.httpRequest();
  final RequestBuilder builder = new RequestBuilder().
      setUrl(CharMatcher.is('/').trimTrailingFrom(coreUrl) + "/" + projectKey + request.getPath()).
      setMethod(request.getHttpMethod().toString()).
      setHeader("User-Agent", "SPHERE.IO JVM SDK version " + BuildInfo.version()).
      setHeader("Authorization", "Bearer " + clientCredentials.getAccessToken());
  return request.getBody().map(builder::setBody).orElse(builder).build();
}

代码示例来源:origin: io.sphere.jvmsdk/java-client

@Override
  public T apply(final HttpResponse httpResponse) {
    final SphereInternalLogger logger = getLogger(httpResponse);
    logger.debug(() -> httpResponse.withoutRequest());
    logger.trace(() -> httpResponse.getStatusCode() + "\n" + JsonUtils.prettyPrintJsonStringSecure(httpResponse.getResponseBody()) + "\n");
    final int status = httpResponse.getStatusCode();
    final String body = httpResponse.getResponseBody();
    final boolean hasError = status / 100 != 2;
    if (hasError) {
      SphereErrorResponse errorResponse;
      try {
        if (Strings.isNullOrEmpty(body)) {//the /model/id endpoint does not return JSON on 404
          errorResponse = new SphereErrorResponse(status, "<no body>", Collections.<SphereError>emptyList());
        } else {
          errorResponse = objectMapper.readValue(body, errorResponseJsonTypeRef);
        }
      } catch (final Exception e) {
        // This can only happen when the backend and SDK don't match.
        final SphereException exception = new SphereException("Can't parse backend response", e);
        fillExceptionWithData(httpResponse, exception, clientRequest);
        throw exception;
      }
      final SphereBackendException exception = new SphereBackendException(clientRequest.httpRequest().getPath(), errorResponse);
      fillExceptionWithData(httpResponse, exception, clientRequest);
      throw exception;
    } else {
      return underlying.apply(httpResponse);
    }
  }
};

相关文章