本文整理汇总了Java中ch.boye.httpclientandroidlib.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于ch.boye.httpclientandroidlib包,在下文中一共展示了HttpResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: handleResponse
import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
public Multistatus handleResponse(HttpResponse response) throws SardineException, IOException
{
super.validateResponse(response);
// Process the response from the server.
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
if (entity == null)
{
throw new SardineException("No entity found in response", statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}
// boolean debug=false;
// //starn: for debug purpose, display the stream on the console
// if (debug){
// String result = convertStreamToString(entity.getContent());
// System.out.println(result);
// InputStream in = new ByteArrayInputStream(result.getBytes());
// return this.getMultistatus(in);
// }
// else {
// return this.getMultistatus(entity.getContent());
// }
Multistatus m = new Multistatus();
new XmlMapper(entity.getContent(),m);
return m;
}
开发者ID:starn,项目名称:encdroidMC,代码行数:29,代码来源:MultiStatusResponseHandler.java
示例17: ConsumingInputStream
import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
/**
* @param response The HTTP response to read from
* @throws IOException If there is a problem reading from the response
* @throws NullPointerException If the response has no message entity
*/
public ConsumingInputStream(final HttpResponse response) throws IOException
{
this.response = response;
HttpEntity entity = response.getEntity();
this.delegate = entity.getContent();
}
开发者ID:starn,项目名称:encdroidMC,代码行数:12,代码来源:ConsumingInputStream.java
示例18: ensurePartialContentIsNotSentToAClientThatDidNotRequestIt
import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private void ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(final HttpRequest request,
final HttpResponse response) throws IOException {
if (request.getFirstHeader(HeaderConstants.RANGE) != null
|| response.getStatusLine().getStatusCode() != HttpStatus.SC_PARTIAL_CONTENT) {
return;
}
consumeBody(response);
throw new ClientProtocolException(UNEXPECTED_PARTIAL_CONTENT);
}
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:11,代码来源:ResponseProtocolCompliance.java
示例19: 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
示例20: requestDidNotExpect100ContinueButResponseIsOne
import ch.boye.httpclientandroidlib.HttpResponse; //导入依赖的package包/类
private void requestDidNotExpect100ContinueButResponseIsOne(final HttpRequestWrapper request,
final HttpResponse response) throws IOException {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) {
return;
}
final HttpRequest originalRequest = request.getOriginal();
if (originalRequest instanceof HttpEntityEnclosingRequest) {
if (((HttpEntityEnclosingRequest)originalRequest).expectContinue()) {
return;
}
}
consumeBody(response);
throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
}
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:16,代码来源:ResponseProtocolCompliance.java
注:本文中的ch.boye.httpclientandroidlib.HttpResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论