Package org.apache.http.client.cache

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


    @Test
    public void testRecognizesComplete206Response()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_PARTIAL_CONTENT, "Partial Content");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));
        resp.setHeader("Content-Length","128");
        resp.setHeader("Content-Range","bytes 0-127/255");

        assertFalse(impl.isIncompleteResponse(resp, resource));
View Full Code Here


    @Test
    public void testRecognizesIncomplete200Response()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));
        resp.setHeader("Content-Length","256");

        assertTrue(impl.isIncompleteResponse(resp, resource));
    }
View Full Code Here

    @Test
    public void testIgnoresIncompleteNon200Or206Responses()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_FORBIDDEN, "Forbidden");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));
        resp.setHeader("Content-Length","256");

        assertFalse(impl.isIncompleteResponse(resp, resource));
    }
View Full Code Here

    @Test
    public void testResponsesWithoutExplicitContentLengthAreComplete()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));

        assertFalse(impl.isIncompleteResponse(resp, resource));
    }
View Full Code Here

    @Test
    public void testResponsesWithUnparseableContentLengthHeaderAreComplete()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setHeader("Content-Length","foo");
        resp.setEntity(new ByteArrayEntity(bytes));

        assertFalse(impl.isIncompleteResponse(resp, resource));
    }
View Full Code Here

    @Test
    public void testIncompleteResponseErrorProvidesPlainTextErrorMessage()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));
        resp.setHeader("Content-Length","256");

        HttpResponse result = impl.generateIncompleteResponseError(resp, resource);
        Header ctype = result.getFirstHeader("Content-Type");
View Full Code Here

    @Test
    public void testIncompleteResponseErrorProvidesNonEmptyErrorMessage()
        throws Exception {
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        byte[] bytes = HttpTestUtils.getRandomBytes(128);
        Resource resource = new HeapResource(bytes);
        resp.setEntity(new ByteArrayEntity(bytes));
        resp.setHeader("Content-Length","256");

        HttpResponse result = impl.generateIncompleteResponseError(resp, resource);
        int clen = Integer.parseInt(result.getFirstHeader("Content-Length").getValue());
View Full Code Here

public class TestCombinedEntity {

    @Test
    public void testCombinedEntityBasics() throws Exception {
        Resource resource = EasyMock.createNiceMock(Resource.class);
        EasyMock.expect(resource.getInputStream()).andReturn(
                new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
        resource.dispose();
        EasyMock.replay(resource);

        ByteArrayInputStream instream = new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 });
        CombinedEntity entity = new CombinedEntity(resource, instream);
        Assert.assertEquals(-1, entity.getContentLength());
View Full Code Here

            Date responseDate,
            HttpResponse response) throws IOException {
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_MODIFIED)
            throw new IllegalArgumentException("Response must have 304 status code");
        Header[] mergedHeaders = mergeHeaders(entry, response);
        Resource oldResource = entry.getResource();
        Resource resource = null;
        if (oldResource != null) {
            resource = resourceFactory.copy(requestId, entry.getResource());
            oldResource.dispose();
        }
        return new HttpCacheEntry(
View Full Code Here

        HttpCacheEntry src = existing;
        if (src == null) {
            src = entry;
        }

        Resource oldResource = entry.getResource();
        Resource resource = null;
        if (oldResource != null) {
            resource = resourceFactory.copy(requestId, entry.getResource());
        }
        Map<String,String> variantMap = new HashMap<String,String>(src.getVariantMap());
        variantMap.put(variantKey, variantCacheKey);
View Full Code Here

TOP

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

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.