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

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

Introduction

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

Prototype

public Date getResponseDate() 

Source Link

Document

Returns the time the origin response was received by the caching module.

Usage

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

private byte[] serialize(HttpCacheEntry o) {
    ObjectOutputStream oos = null;
    try {/*from w  w  w.j  a  va  2s  .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 w  w  w  .  jav  a2  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  w  w w  .  ja va  2 s  . c  o m

    return true;
}