本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}