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


Java HttpResponse.setEntity方法代码示例

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


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

示例1: handleException

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    final byte[] msg = EncodingUtils.getAsciiBytes(message);
    final ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:28,代码来源:HttpService.java

示例2: generateResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * If I was able to use a {@link CacheEntity} to response to the {@link ch.boye.httpclientandroidlib.HttpRequest} then
 * generate an {@link HttpResponse} based on the cache entry.
 * @param entry
 *            {@link CacheEntity} to transform into an {@link HttpResponse}
 * @return {@link HttpResponse} that was constructed
 */
CloseableHttpResponse generateResponse(final HttpCacheEntry entry) {

    final Date now = new Date();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, entry
            .getStatusCode(), entry.getReasonPhrase());

    response.setHeaders(entry.getAllHeaders());

    if (entry.getResource() != null) {
        final HttpEntity entity = new CacheEntity(entry);
        addMissingContentLengthHeader(response, entity);
        response.setEntity(entity);
    }

    final long age = this.validityStrategy.getCurrentAgeSecs(entry, now);
    if (age > 0) {
        if (age >= Integer.MAX_VALUE) {
            response.setHeader(HeaderConstants.AGE, "2147483648");
        } else {
            response.setHeader(HeaderConstants.AGE, "" + ((int) age));
        }
    }

    return Proxies.enhanceResponse(response);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:33,代码来源:CachedHttpResponseGenerator.java

示例3: getReconstructedResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
CloseableHttpResponse getReconstructedResponse() throws IOException {
    ensureConsumed();
    final HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine());
    reconstructed.setHeaders(response.getAllHeaders());

    final CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
    final HttpEntity entity = response.getEntity();
    if (entity != null) {
        combinedEntity.setContentType(entity.getContentType());
        combinedEntity.setContentEncoding(entity.getContentEncoding());
        combinedEntity.setChunked(entity.isChunked());
    }
    reconstructed.setEntity(combinedEntity);
    return (CloseableHttpResponse) Proxy.newProxyInstance(
            ResponseProxyHandler.class.getClassLoader(),
            new Class<?>[] { CloseableHttpResponse.class },
            new ResponseProxyHandler(reconstructed) {

                @Override
                public void close() throws IOException {
                    response.close();
                }

            });
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:SizeLimitedResponseReader.java

示例4: process

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    final HttpEntity entity = response.getEntity();

    // entity can be null in case of 304 Not Modified, 204 No Content or similar
    // check for zero length entity.
    if (entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            final HeaderElement[] codecs = ceheader.getElements();
            boolean uncompressed = false;
            for (final HeaderElement codec : codecs) {
                final String codecname = codec.getName().toLowerCase(Locale.ENGLISH);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    uncompressed = true;
                    break;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
            if (uncompressed) {
                response.removeHeaders("Content-Length");
                response.removeHeaders("Content-Encoding");
                response.removeHeaders("Content-MD5");
            }
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:53,代码来源:ResponseContentEncoding.java

示例5: receiveResponseEntity

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public void receiveResponseEntity(final HttpResponse response)
        throws HttpException, IOException {
    Args.notNull(response, "HTTP response");
    assertOpen();
    final HttpEntity entity = this.entitydeserializer.deserialize(this.inbuffer, response);
    response.setEntity(entity);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:AbstractHttpClientConnection.java

示例6: generateIncompleteResponseError

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
CloseableHttpResponse generateIncompleteResponseError(
        final HttpResponse response, final Resource resource) {
    final int contentLength = Integer.parseInt(response.getFirstHeader(HTTP.CONTENT_LEN).getValue());
    final HttpResponse error =
        new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_GATEWAY, "Bad Gateway");
    error.setHeader("Content-Type","text/plain;charset=UTF-8");
    final String msg = String.format("Received incomplete response " +
            "with Content-Length %d but actual body length %d",
            contentLength, resource.length());
    final byte[] msgBytes = msg.getBytes();
    error.setHeader("Content-Length", Integer.toString(msgBytes.length));
    error.setEntity(new ByteArrayEntity(msgBytes));
    return Proxies.enhanceResponse(error);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:15,代码来源:BasicHttpCache.java

示例7: receiveResponseEntity

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public void receiveResponseEntity(
        final HttpResponse response) throws HttpException, IOException {
    Args.notNull(response, "HTTP response");
    ensureOpen();
    final HttpEntity entity = prepareInput(response);
    response.setEntity(entity);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:DefaultBHttpClientConnection.java

示例8: enchance

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public static void enchance(final HttpResponse response, final ConnectionHolder connHolder) {
    final HttpEntity entity = response.getEntity();
    if (entity != null && entity.isStreaming() && connHolder != null) {
        response.setEntity(new ResponseEntityProxy(entity, connHolder));
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:7,代码来源:ResponseEntityProxy.java

示例9: ensureProtocolCompliance

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * When we get a response from a down stream server (Origin Server)
 * we attempt to see if it is HTTP 1.1 Compliant and if not, attempt to
 * make it so.
 *
 * @param request The {@link HttpRequest} that generated an origin hit and response
 * @param response The {@link HttpResponse} from the origin server
 * @throws IOException Bad things happened
 */
public void ensureProtocolCompliance(final HttpRequestWrapper request, final HttpResponse response)
        throws IOException {
    if (backendResponseMustNotHaveBody(request, response)) {
        consumeBody(response);
        response.setEntity(null);
    }

    requestDidNotExpect100ContinueButResponseIsOne(request, response);

    transferEncodingIsNotReturnedTo1_0Client(request, response);

    ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(request, response);

    ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(request, response);

    ensure206ContainsDateHeader(response);

    ensure304DoesNotContainExtraEntityHeaders(response);

    identityIsNotUsedInContentEncoding(response);

    warningsWithNonMatchingWarnDatesAreRemoved(response);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:33,代码来源:ResponseProtocolCompliance.java

示例10: updateEntity

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Updates an entity in a response by first consuming an existing entity, then setting the new one.
 *
 * @param response the response with an entity to update; must not be null.
 * @param entity the entity to set in the response.
 * @throws IOException if an error occurs while reading the input stream on the existing
 * entity.
 * @throws IllegalArgumentException if response is null.
 *
 * @since 4.3
 */
public static void updateEntity(
        final HttpResponse response, final HttpEntity entity) throws IOException {
    Args.notNull(response, "Response");
    consume(response.getEntity());
    response.setEntity(entity);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:EntityUtils.java


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