Package org.apache.http.client.cache

Examples of org.apache.http.client.cache.HttpCacheEntry


        if (matchingVariant == null) {
            log.debug("304 response did not contain ETag matching one sent in If-None-Match");
            return callBackend(target, request, context);
        }

        final HttpCacheEntry matchedEntry = matchingVariant.getEntry();

        if (revalidationResponseIsTooOld(backendResponse, matchedEntry)) {
            IOUtils.consume(backendResponse.getEntity());
            return retryRequestUnconditionally(target, request, context,
                    matchedEntry);
        }

        recordCacheUpdate(context);

        final HttpCacheEntry responseEntry = getUpdatedVariantEntry(target,
                conditionalRequest, requestDate, responseDate, backendResponse,
                matchingVariant, matchedEntry);

        final HttpResponse resp = responseGenerator.generateResponse(responseEntry);
        tryToUpdateVariantMap(target, request, matchingVariant);
View Full Code Here


    private HttpCacheEntry getUpdatedVariantEntry(final HttpHost target,
            final HttpRequestWrapper conditionalRequest, final Date requestDate,
            final Date responseDate, final HttpResponse backendResponse,
            final Variant matchingVariant, final HttpCacheEntry matchedEntry) {
        HttpCacheEntry responseEntry = matchedEntry;
        try {
            responseEntry = responseCache.updateVariantCacheEntry(target, conditionalRequest,
                    matchedEntry, backendResponse, requestDate, responseDate, matchingVariant.getCacheKey());
        } catch (final IOException ioe) {
            log.warn("Could not update cache entry", ioe);
View Full Code Here

        if (statusCode == HttpStatus.SC_NOT_MODIFIED || statusCode == HttpStatus.SC_OK) {
            recordCacheUpdate(context);
        }

        if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
            final HttpCacheEntry updatedEntry = responseCache.updateCacheEntry(target, request, cacheEntry,
                    backendResponse, requestDate, responseDate);
            if (suitabilityChecker.isConditional(request)
                    && suitabilityChecker.allConditionalsMatch(request, updatedEntry, new Date())) {
                return responseGenerator.generateNotModifiedResponse(updatedEntry);
            }
View Full Code Here

        }
    }

    private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequest 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) {
View Full Code Here

    }

    @Test
    public void testCachePut() throws IOException {
        final String key = "foo";
        final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();

        final Element e = new Element(key, new byte[]{});

        mockSerializer.writeTo(EasyMock.same(value), EasyMock.isA(OutputStream.class));
        mockCache.put(e);
View Full Code Here

        final String key = "foo";

        EasyMock.expect(mockCache.get(key)).andReturn(null);

        replayMocks();
        final HttpCacheEntry resultingEntry = impl.getEntry(key);
        verifyMocks();

        assertNull(resultingEntry);
    }
View Full Code Here

    }

    @Test
    public void testCacheGet() throws IOException {
        final String key = "foo";
        final HttpCacheEntry cachedValue = HttpTestUtils.makeCacheEntry();

        final Element element = new Element(key, new byte[]{});

        EasyMock.expect(mockCache.get(key))
                .andReturn(element);
        EasyMock.expect(mockSerializer.readFrom(EasyMock.isA(InputStream.class)))
                .andReturn(cachedValue);

        replayMocks();
        final HttpCacheEntry resultingEntry = impl.getEntry(key);
        verifyMocks();

        assertSame(cachedValue, resultingEntry);
    }
View Full Code Here

    }

    @Test
    public void testCacheUpdateNullEntry() throws IOException, HttpCacheUpdateException {
        final String key = "foo";
        final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();

        final Element element = new Element(key, new byte[]{});

        final HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){
            public HttpCacheEntry update(final HttpCacheEntry old){
View Full Code Here

    }

    @Test
    public void testCacheUpdate() throws IOException, HttpCacheUpdateException {
        final String key = "foo";
        final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
        final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();

        final Element existingElement = new Element(key, new byte[]{});

        final HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){
            public HttpCacheEntry update(final HttpCacheEntry old){
View Full Code Here

    }

    @Test
    public void testSingleCacheUpdateRetry() throws IOException, HttpCacheUpdateException {
        final String key = "foo";
        final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
        final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();

        final Element existingElement = new Element(key, new byte[]{});

        final HttpCacheUpdateCallback callback = new HttpCacheUpdateCallback(){
            public HttpCacheEntry update(final HttpCacheEntry old){
View Full Code Here

TOP

Related Classes of org.apache.http.client.cache.HttpCacheEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.