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


Java HttpResponse类代码示例

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


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

示例1: isNotStale

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
/**
 * Try to detect if the returned response is generated from a stale cache entry.
 * @param httpResponse the response to be checked
 * @return whether the response is stale or not
 */
private boolean isNotStale(final HttpResponse httpResponse) {
    final Header[] warnings = httpResponse.getHeaders(HeaderConstants.WARNING);
    if (warnings != null)
    {
        for (final Header warning : warnings)
        {
            /**
             * warn-codes
             * 110 = Response is stale
             * 111 = Revalidation failed
             */
            final String warningValue = warning.getValue();
            if (warningValue.startsWith("110") || warningValue.startsWith("111"))
            {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:AsynchronousValidationRequest.java

示例2: LoggingManagedHttpClientConnection

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
public LoggingManagedHttpClientConnection(
        final String id,
        final HttpClientAndroidLog log,
        final HttpClientAndroidLog headerlog,
        final HttpClientAndroidLog wirelog,
        final int buffersize,
        final int fragmentSizeHint,
        final CharsetDecoder chardecoder,
        final CharsetEncoder charencoder,
        final MessageConstraints constraints,
        final ContentLengthStrategy incomingContentStrategy,
        final ContentLengthStrategy outgoingContentStrategy,
        final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
        final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
    super(id, buffersize, fragmentSizeHint, chardecoder, charencoder,
            constraints, incomingContentStrategy, outgoingContentStrategy,
            requestWriterFactory, responseParserFactory);
    this.log = log;
    this.headerlog = headerlog;
    this.wire = new Wire(wirelog, id);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:22,代码来源:LoggingManagedHttpClientConnection.java

示例3: flushInvalidatedCacheEntries

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
/** Flushes entries that were invalidated by the given response
 * received for the given host/request pair.
 */
public void flushInvalidatedCacheEntries(final HttpHost host,
        final HttpRequest request, final HttpResponse response) {
    final int status = response.getStatusLine().getStatusCode();
    if (status < 200 || status > 299) {
        return;
    }
    final URL reqURL = getAbsoluteURL(cacheKeyGenerator.getURI(host, request));
    if (reqURL == null) {
        return;
    }
    final URL contentLocation = getContentLocationURL(reqURL, response);
    if (contentLocation != null) {
        flushLocationCacheEntry(reqURL, response, contentLocation);
    }
    final URL location = getLocationURL(reqURL, response);
    if (location != null) {
        flushLocationCacheEntry(reqURL, response, location);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:CacheInvalidator.java

示例4: expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private boolean expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(
        final HttpResponse response) {
    if (response.getFirstHeader(HeaderConstants.CACHE_CONTROL) != null) {
        return false;
    }
    final Header expiresHdr = response.getFirstHeader(HeaderConstants.EXPIRES);
    final Header dateHdr = response.getFirstHeader(HTTP.DATE_HEADER);
    if (expiresHdr == null || dateHdr == null) {
        return false;
    }
    final Date expires = DateUtils.parseDate(expiresHdr.getValue());
    final Date date = DateUtils.parseDate(dateHdr.getValue());
    if (expires == null || date == null) {
        return false;
    }
    return expires.equals(date) || expires.before(date);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:ResponseCachingPolicy.java

示例5: handleHttpResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse response) {
  // Skew.
  SkewHandler skewHandler = SkewHandler.getSkewHandlerForResource(resource);
  skewHandler.updateSkew(response, System.currentTimeMillis());

  // Extract backoff regardless of whether this was an error response, and
  // Retry-After for 503 responses. The error will be handled elsewhere.)
  SyncResponse res = new SyncResponse(response);
  final boolean includeRetryAfter = res.getStatusCode() == 503;
  int backoffInSeconds = res.totalBackoffInSeconds(includeRetryAfter);
  if (backoffInSeconds > -1) {
    client.notifyBackoff(delegate, backoffInSeconds);
  }

  try {
    TokenServerToken token = client.processResponse(res);
    client.invokeHandleSuccess(delegate, token);
  } catch (TokenServerException e) {
    client.invokeHandleFailure(delegate, e);
  }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:TokenServerClient.java

示例6: isRedirected

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");

    final int statusCode = response.getStatusLine().getStatusCode();
    final String method = request.getRequestLine().getMethod();
    final Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:DefaultRedirectStrategy.java

示例7: validateResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
/**
 * Intepret a response from the auth server.
 * <p>
 * Throw an appropriate exception on errors; otherwise, return the response's
 * status code.
 *
 * @return response's HTTP status code.
 * @throws FxAccountClientException
 */
public static int validateResponse(HttpResponse response) throws FxAccountClientRemoteException {
  final int status = response.getStatusLine().getStatusCode();
  if (status == 200) {
    return status;
  }
  int code;
  int errno;
  String error;
  String message;
  String info;
  ExtendedJSONObject body;
  try {
    body = new SyncStorageResponse(response).jsonObjectBody();
    body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
    body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
    code = body.getLong(JSON_KEY_CODE).intValue();
    errno = body.getLong(JSON_KEY_ERRNO).intValue();
    error = body.getString(JSON_KEY_ERROR);
    message = body.getString(JSON_KEY_MESSAGE);
    info = body.getString(JSON_KEY_INFO);
  } catch (Exception e) {
    throw new FxAccountClientMalformedResponseException(response);
  }
  throw new FxAccountClientRemoteException(response, code, errno, error, message, info, body);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:35,代码来源:FxAccountClient20.java

示例8: 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

示例9: flushLocationCacheEntry

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private void flushLocationCacheEntry(final URL reqURL,
        final HttpResponse response, final URL location) {
    final String cacheKey = cacheKeyGenerator.canonicalizeUri(location.toString());
    final HttpCacheEntry entry = getEntry(cacheKey);
    if (entry == null) {
        return;
    }

    // do not invalidate if response is strictly older than entry
    // or if the etags match

    if (responseDateOlderThanEntryDate(response, entry)) {
        return;
    }
    if (!responseAndEntryEtagsDiffer(response, entry)) {
        return;
    }

    flushUriIfSameHost(reqURL, location);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:21,代码来源:CacheInvalidator.java

示例10: alreadyHaveNewerCacheEntry

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequestWrapper request,
        final HttpResponse backendResponse) {
    HttpCacheEntry existing = null;
    try {
        existing = responseCache.getCacheEntry(target, request);
    } catch (final IOException ioe) {
        // nop
    }
    if (existing == null) {
        return false;
    }
    final Header entryDateHeader = existing.getFirstHeader(HTTP.DATE_HEADER);
    if (entryDateHeader == null) {
        return false;
    }
    final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
    if (responseDateHeader == null) {
        return false;
    }
    final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
    final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue());
    if (entryDate == null || responseDate == null) {
        return false;
    }
    return responseDate.before(entryDate);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:27,代码来源:CachingExec.java

示例11: isIncompleteResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
boolean isIncompleteResponse(final HttpResponse resp, final Resource resource) {
    final int status = resp.getStatusLine().getStatusCode();
    if (status != HttpStatus.SC_OK
        && status != HttpStatus.SC_PARTIAL_CONTENT) {
        return false;
    }
    final Header hdr = resp.getFirstHeader(HTTP.CONTENT_LEN);
    if (hdr == null) {
        return false;
    }
    final int contentLength;
    try {
        contentLength = Integer.parseInt(hdr.getValue());
    } catch (final NumberFormatException nfe) {
        return false;
    }
    return (resource.length() < contentLength);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:19,代码来源:BasicHttpCache.java

示例12: process

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
public void process(
        final HttpResponse response,
        final HttpContext context) throws IOException, HttpException {
    for (final HttpResponseInterceptor responseInterceptor : this.responseInterceptors) {
        responseInterceptor.process(response, context);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:ImmutableHttpProcessor.java

示例13: entryAndResponseHaveDateHeader

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private boolean entryAndResponseHaveDateHeader(final HttpCacheEntry entry, final HttpResponse response) {
    if (entry.getFirstHeader(HTTP.DATE_HEADER) != null
            && response.getFirstHeader(HTTP.DATE_HEADER) != null) {
        return true;
    }

    return false;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:9,代码来源:CacheEntryUpdater.java

示例14: canResponseHaveBody

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
/**
 * Decide whether a response comes with an entity.
 * The implementation in this class is based on RFC 2616.
 * <br/>
 * Derived executors can override this method to handle
 * methods and response codes not specified in RFC 2616.
 *
 * @param request   the request, to obtain the executed method
 * @param response  the response, to obtain the status code
 */
protected boolean canResponseHaveBody(final HttpRequest request,
                                      final HttpResponse response) {

    if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
        return false;
    }
    final int status = response.getStatusLine().getStatusCode();
    return status >= HttpStatus.SC_OK
        && status != HttpStatus.SC_NO_CONTENT
        && status != HttpStatus.SC_NOT_MODIFIED
        && status != HttpStatus.SC_RESET_CONTENT;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:HttpRequestExecutor.java

示例15: parseHead

import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
@Override
protected HttpResponse parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    final int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new NoHttpResponseException("The target server failed to respond");
    }
    //create the status line from the status string
    final ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:DefaultHttpResponseParser.java


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