当前位置: 首页>>代码示例>>Java>>正文


Java HttpEntity.isRepeatable方法代码示例

本文整理汇总了Java中org.apache.http.HttpEntity.isRepeatable方法的典型用法代码示例。如果您正苦于以下问题:Java HttpEntity.isRepeatable方法的具体用法?Java HttpEntity.isRepeatable怎么用?Java HttpEntity.isRepeatable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpEntity的用法示例。


在下文中一共展示了HttpEntity.isRepeatable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BufferedHttpEntity

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
 * Creates a new buffered entity wrapper.
 *
 * @param entity   the entity to wrap, not null
 * @throws IllegalArgumentException if wrapped is null
 */
public BufferedHttpEntity(final HttpEntity entity) throws IOException {
    super(entity);
    if (!entity.isRepeatable() || entity.getContentLength() < 0) {
        this.buffer = EntityUtils.toByteArray(entity);
    } else {
        this.buffer = null;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:BufferedHttpEntity.java

示例2: toFeignBody

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
Response.Body toFeignBody(HttpResponse httpResponse) throws IOException {
  final HttpEntity entity = httpResponse.getEntity();
  if (entity == null) {
    return null;
  }
  return new Response.Body() {

    @Override
    public Integer length() {
      return entity.getContentLength() >= 0 && entity.getContentLength() <= Integer.MAX_VALUE ?
              (int) entity.getContentLength() : null;
    }

    @Override
    public boolean isRepeatable() {
      return entity.isRepeatable();
    }

    @Override
    public InputStream asInputStream() throws IOException {
      return entity.getContent();
    }

    @Override
    public Reader asReader() throws IOException {
      return new InputStreamReader(asInputStream(), UTF_8);
    }

    @Override
    public void close() throws IOException {
      EntityUtils.consume(entity);
    }
  };
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:35,代码来源:ApacheHttpClient.java

示例3: toCurl

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
 * Generates a cURL command equivalent to the given request.
 */
private static String toCurl(HttpUriRequest request, boolean logAuthToken) throws IOException {
    StringBuilder builder = new StringBuilder();

    builder.append("curl ");

    for (Header header: request.getAllHeaders()) {
        if (!logAuthToken
                && (header.getName().equals("Authorization") ||
                    header.getName().equals("Cookie"))) {
            continue;
        }
        builder.append("--header \"");
        builder.append(header.toString().trim());
        builder.append("\" ");
    }

    URI uri = request.getURI();

    // If this is a wrapped request, use the URI from the original
    // request instead. getURI() on the wrapper seems to return a
    // relative URI. We want an absolute URI.
    if (request instanceof RequestWrapper) {
        HttpRequest original = ((RequestWrapper) request).getOriginal();
        if (original instanceof HttpUriRequest) {
            uri = ((HttpUriRequest) original).getURI();
        }
    }

    builder.append("\"");
    builder.append(uri);
    builder.append("\"");

    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest entityRequest =
                (HttpEntityEnclosingRequest) request;
        HttpEntity entity = entityRequest.getEntity();
        if (entity != null && entity.isRepeatable()) {
            if (entity.getContentLength() < 1024) {
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                entity.writeTo(stream);
                String entityString = stream.toString();

                // TODO: Check the content type, too.
                builder.append(" --data-ascii \"")
                        .append(entityString)
                        .append("\"");
            } else {
                builder.append(" [TOO MUCH DATA TO INCLUDE]");
            }
        }
    }

    return builder.toString();
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:58,代码来源:AndroidHttpClient.java

示例4: shouldRetry

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
/**
 * Returns true if a failed request should be retried.
 *
 * @param params    Params for the individual request being executed.
 * @param exception The client/service exception from the failed request.
 * @return True if the failed request should be retried.
 */
private boolean shouldRetry(ExecOneRequestParams params, SdkBaseException exception) {
    final int retriesAttempted = params.requestCount - 1;
    final HttpRequestBase method = params.apacheRequest;

    // Never retry on requests containing non-repeatable entity
    if (method instanceof HttpEntityEnclosingRequest) {
        HttpEntity entity = ((HttpEntityEnclosingRequest) method).getEntity();
        if (entity != null && !entity.isRepeatable()) {
            if (log.isDebugEnabled()) {
                log.debug("Entity not repeatable");
            }
            return false;
        }
    }

    // Do not use retry capacity for throttling exceptions
    if (!RetryUtils.isThrottlingException(exception)) {
        // See if we have enough available retry capacity to be able to execute
        // this retry attempt.
        if (!retryCapacity.acquire(THROTTLED_RETRY_COST)) {
            awsRequestMetrics.incrementCounter(ThrottledRetryCount);
            return false;
        }
        executionContext.markRetryCapacityConsumed();
    }

    RetryPolicyContext context = RetryPolicyContext.builder()
            .request(request)
            .originalRequest(requestConfig.getOriginalRequest())
            .exception(exception)
            .retriesAttempted(retriesAttempted)
            .httpStatusCode(params.getStatusCode())
            .build();
    // Finally, pass all the context information to the RetryCondition and let it
    // decide whether it should be retried.
    if (!retryPolicy.shouldRetry(context)) {
        // If the retry policy fails we immediately return consumed capacity to the pool.
        if (executionContext.retryCapacityConsumed()) {
            retryCapacity.release(THROTTLED_RETRY_COST);
        }
        return false;
    }

    return true;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:53,代码来源:AmazonHttpClient.java


注:本文中的org.apache.http.HttpEntity.isRepeatable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。