Example usage for org.apache.http.client.cache HttpCacheEntry getAllHeaders

List of usage examples for org.apache.http.client.cache HttpCacheEntry getAllHeaders

Introduction

In this page you can find the example usage for org.apache.http.client.cache HttpCacheEntry getAllHeaders.

Prototype

public Header[] getAllHeaders() 

Source Link

Document

Returns all the headers that were on the origin response.

Usage

From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java

/*******************************************************************************************************************
 *
 * /*  w  ww. j a v  a 2s . c  o  m*/
 *
 ******************************************************************************************************************/
@Nonnull
private static HttpResponse responseFrom(final @Nonnull HttpCacheEntry entry) {
    final BasicHttpResponse response = new BasicHttpResponse(entry.getStatusLine());
    response.setHeaders(entry.getAllHeaders());
    return response;
}

From source file:gr.wavesoft.webng.io.cache.DiskCacheStorage.java

private byte[] serialize(HttpCacheEntry o) {
    ObjectOutputStream oos = null;
    try {/*from   w  w  w . j av a 2  s. c  o  m*/

        // Setut vars
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        // Dump object
        oos = new ObjectOutputStream(bos);
        oos.writeLong(o.getRequestDate().getTime());
        oos.writeLong(o.getResponseDate().getTime());
        oos.writeObject(o.getStatusLine());
        oos.writeObject(o.getAllHeaders());

        // Complete stream
        oos.close();

        // Get byte array
        return bos.toByteArray();

    } catch (IOException ex) {
        systemLogger.except(ex);
    } finally {
        try {
            oos.close();
        } catch (IOException ex) {
            systemLogger.error("Error closing serialization buffer ", ex);
        }
    }
    return null;

}

From source file:org.apache.http.impl.client.cache.BasicHttpCache.java

HttpCacheEntry doGetUpdatedParentEntry(final String requestId, final HttpCacheEntry existing,
        final HttpCacheEntry entry, final String variantKey, final String variantCacheKey) throws IOException {
    HttpCacheEntry src = existing;
    if (src == null) {
        src = entry;/*from   ww  w  .j a  va2  s  .  co  m*/
    }

    Resource resource = resourceFactory.copy(requestId, src.getResource());
    Map<String, String> variantMap = new HashMap<String, String>(src.getVariantMap());
    variantMap.put(variantKey, variantCacheKey);
    return new HttpCacheEntry(src.getRequestDate(), src.getResponseDate(), src.getStatusLine(),
            src.getAllHeaders(), resource, variantMap);
}

From source file:org.apache.http.impl.client.cache.TestHttpCacheEntrySerializers.java

private boolean areEqual(HttpCacheEntry one, HttpCacheEntry two) throws IOException {
    // dates are only stored with second precision, so scrub milliseconds
    if (!((one.getRequestDate().getTime() / 1000) == (two.getRequestDate().getTime() / 1000)))
        return false;
    if (!((one.getResponseDate().getTime() / 1000) == (two.getResponseDate().getTime() / 1000)))
        return false;
    if (!one.getProtocolVersion().equals(two.getProtocolVersion()))
        return false;

    byte[] onesByteArray = resourceToBytes(one.getResource());
    byte[] twosByteArray = resourceToBytes(two.getResource());

    if (!Arrays.equals(onesByteArray, twosByteArray))
        return false;

    Header[] oneHeaders = one.getAllHeaders();
    Header[] twoHeaders = two.getAllHeaders();
    if (!(oneHeaders.length == twoHeaders.length))
        return false;
    for (int i = 0; i < oneHeaders.length; i++) {
        if (!oneHeaders[i].getName().equals(twoHeaders[i].getName()))
            return false;
        if (!oneHeaders[i].getValue().equals(twoHeaders[i].getValue()))
            return false;
    }/*from  ww w  .j av a 2 s  .c  o m*/

    return true;
}