Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.CloseableHttpResponse


                final HttpHost targetForRoute = (target != null) ? target
                        : (HttpHost) determineParams(request).getParameter(
                                ClientPNames.DEFAULT_HOST);
                final HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext);

                CloseableHttpResponse out;
                try {
                    out = CloseableHttpResponseProxy.newProxy(
                            director.execute(target, request, execContext));
                } catch (final RuntimeException re) {
                    if (connectionBackoffStrategy.shouldBackoff(re)) {
View Full Code Here


        context.setAttribute(ClientContext.ROUTE, route);
        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);

        this.httpProcessor.process(request, context);

        final CloseableHttpResponse response = this.requestExecutor.execute(route, request, context, execAware);
        try {
            // Run response protocol interceptors
            context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
            this.httpProcessor.process(response, context);
            return response;
        } catch (final RuntimeException ex) {
            response.close();
            throw ex;
        } catch (final IOException ex) {
            response.close();
            throw ex;
        } catch (final HttpException ex) {
            response.close();
            throw ex;
        }
    }
View Full Code Here

        final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/thing", HttpVersion.HTTP_1_1));
        validate.setHeader("If-None-Match", "\"etag\"");

        final CloseableHttpResponse notModified = Proxies.enhanceResponse(
                new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified"));
        notModified.setHeader("Date", DateUtils.formatDate(now));
        notModified.setHeader("ETag", "\"etag\"");

        mockCache.flushInvalidatedCacheEntriesFor(host, request);
        EasyMock.expect(mockCache.getCacheEntry(host, request)).andReturn(entry);
        EasyMock.expect(
                mockBackend.execute(
View Full Code Here

        impl = new CachingExec(mockBackend, mockCache, config);

        request = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/thing", HttpVersion.HTTP_1_1));

        final CloseableHttpResponse validated = Proxies.enhanceResponse(HttpTestUtils.make200Response());
        validated.setHeader("Cache-Control", "public");
        validated.setHeader("Last-Modified", DateUtils.formatDate(oneYearAgo));
        validated.setHeader("Content-Length", "128");
        validated.setEntity(new ByteArrayEntity(bytes));

        final HttpResponse reconstructed = HttpTestUtils.make200Response();

        final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
View Full Code Here

            final HttpRoute route,
            final HttpRequestWrapper request,
            final HttpClientContext context,
            final HttpExecutionAware execAware) throws IOException, HttpException {
        for (int c = 1;; c++) {
            final CloseableHttpResponse response = this.requestExecutor.execute(
                    route, request, context, execAware);
            try {
                if (this.retryStrategy.retryRequest(response, c, context)) {
                    response.close();
                    final long nextInterval = this.retryStrategy.getRetryInterval();
                    try {
                        this.log.trace("Wait for " + nextInterval);
                        Thread.sleep(nextInterval);
                    } catch (final InterruptedException e) {
                        throw new InterruptedIOException(e.getMessage());
                    }
                } else {
                    return response;
                }
            } catch (final RuntimeException ex) {
                response.close();
                throw ex;
            } catch (final IOException ex) {
                response.close();
                throw ex;
            }
        }
    }
View Full Code Here

        final HttpGet httpget = new HttpGet("https://somehost:444/stuff");

        Mockito.when(client.doExecute(
                new HttpHost("somehost", 444, "https"), httpget, null)).thenReturn(response);

        final CloseableHttpResponse result = client.execute(httpget);
        Assert.assertSame(response, result);
    }
View Full Code Here

    public void testRevalidationCallsHandleBackEndResponseWhenNot200Or304() throws Exception {
        mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);

        final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final CloseableHttpResponse originResponse = Proxies.enhanceResponse(
                new BasicHttpResponse(HttpVersion.HTTP_1_1,  HttpStatus.SC_NOT_FOUND, "Not Found"));
        final CloseableHttpResponse finalResponse = Proxies.enhanceResponse(
                HttpTestUtils.make200Response());

        conditionalRequestBuilderReturns(validate);
        getCurrentDateReturns(requestDate);
        backendExpectsRequestAndReturn(validate, originResponse);
View Full Code Here

    @Test
    public void testTreatsCacheIOExceptionsAsCacheMiss()
        throws Exception {

        impl = new CachingExec(mockBackend, mockCache, CacheConfig.DEFAULT);
        final CloseableHttpResponse resp = Proxies.enhanceResponse(HttpTestUtils.make200Response());

        mockCache.flushInvalidatedCacheEntriesFor(host, request);
        expectLastCall().andThrow(new IOException()).anyTimes();
        mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpResponse.class));
        expectLastCall().anyTimes();
View Full Code Here

        Assert.assertNotNull(result2.getEntity());
    }

    private IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndReturn(
            final HttpResponse response) throws Exception {
        final CloseableHttpResponse resp = mockBackend.execute(
                EasyMock.isA(HttpRoute.class),
                EasyMock.isA(HttpRequestWrapper.class),
                EasyMock.isA(HttpClientContext.class),
                EasyMock.<HttpExecutionAware>isNull());
        return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
View Full Code Here

        return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
    }

    private IExpectationSetters<CloseableHttpResponse> implExpectsAnyRequestAndReturn(
            final CloseableHttpResponse response) throws Exception {
        final CloseableHttpResponse resp = impl.callBackend(
                EasyMock.isA(HttpRoute.class),
                EasyMock.isA(HttpRequestWrapper.class),
                EasyMock.isA(HttpClientContext.class),
                EasyMock.<HttpExecutionAware>isNull());
        return EasyMock.expect(resp).andReturn(response);
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.CloseableHttpResponse

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.