Package org.apache.http.client.methods

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


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

    protected IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndThrows(
        final Throwable throwable) 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).andThrow(throwable);
    }
View Full Code Here


        return EasyMock.expect(resp).andThrow(throwable);
    }

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

    @Test
    public void testTreatsCacheIOExceptionsAsCacheMiss() throws Exception {

        impl = createCachingExecChain(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));
View Full Code Here

        assertEquals(2, backend.getExecutions());
    }

    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));
    }

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

    HttpGet method = new HttpGet(builder.build());
    if (headers != null) {
      for (String headerName : headers.keySet())
        method.addHeader(headerName, headers.get(headerName));
    }
    CloseableHttpResponse response = null;
    try {
      HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());

      HttpClientContext localcontext = HttpClientContext.create();
      if (isAuthConfigured) {
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);
        localcontext.setAuthCache(authCache);
      }

      response = httpclient.execute(targetHost, method, localcontext);
      int statusCode = response.getStatusLine().getStatusCode();
      byte[] responseContent = null;
      if (response.getEntity() != null) {
        responseContent = EntityUtils.toByteArray(response.getEntity());
      }
      if (statusCode != HttpStatus.SC_OK) {
        throw new HttpCallException(url, statusCode, responseContent != null ? new String(responseContent) : "");
      }
      Header h = response.getFirstHeader("Content-Type");

      return new HttpResponseContent(h != null ? h.getValue() : null, responseContent);
    } finally {
      if (response != null)
        response.close();
      method.releaseConnection();
    }
  }
View Full Code Here

            @Override
            public void completed(final HttpResponse httpResponse) {
                httpResponse.addHeader(HeaderConstants.VIA, generateViaHeader(httpResponse));
                try {
                    final CloseableHttpResponse backendResponse = handleBackendResponse(
                            target, request, requestDate, getCurrentDate(),
                            Proxies.enhanceResponse(httpResponse));
                    super.completed(backendResponse);
                } catch (final IOException e) {
                    super.failed(e);
View Full Code Here

            future.completed(cachedResponse);
            return;
        }

        try {
            final CloseableHttpResponse backendResponse = handleBackendResponse(
                    target, conditionalRequest, requestDate, responseDate,
                    Proxies.enhanceResponse(httpResponse));
            future.completed(backendResponse);
        } catch (final IOException e) {
            future.failed(e);
View Full Code Here

        HttpGet getMethod = new HttpGet( url );

        try
        {
            CloseableHttpResponse response = execute( getMethod );
            try {
                int statusCode = response.getStatusLine().getStatusCode();

                fireTransferDebug( url + " - Status code: " + statusCode );

                switch ( statusCode )
                {
                    case HttpStatus.SC_OK:
                        break;

                    case HttpStatus.SC_FORBIDDEN:
                        throw new AuthorizationException( "Access denied to: " + url );

                    case HttpStatus.SC_UNAUTHORIZED:
                        throw new AuthorizationException( "Not authorized." );

                    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
                        throw new AuthorizationException( "Not authorized by proxy." );

                    case HttpStatus.SC_NOT_FOUND:
                        throw new ResourceDoesNotExistException( "File: " + url + " does not exist" );

                        //add more entries here
                    default:
                        throw new TransferFailedException(
                            "Failed to transfer file: " + url + ". Return code is: " + statusCode );
                }
                HttpEntity entity = response.getEntity();
                if ( entity != null )
                {
                    return HtmlFileListParser.parseFileList( url, entity.getContent() );
                }
                else
                {
                    return Collections.emptyList();
                }

            }
            finally
            {
                response.close();
            }
        }
        catch ( IOException e )
        {
            throw new TransferFailedException( "Could not read response body.", e );
View Full Code Here

        try
        {
            putMethod.setEntity( httpEntity );

            CloseableHttpResponse response = execute( putMethod );
            try
            {
                int statusCode = response.getStatusLine().getStatusCode();
                String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
                fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );

                // Check that we didn't run out of retries.
                switch ( statusCode )
                {
                    // Success Codes
                    case HttpStatus.SC_OK: // 200
                    case HttpStatus.SC_CREATED: // 201
                    case HttpStatus.SC_ACCEPTED: // 202
                    case HttpStatus.SC_NO_CONTENT:  // 204
                        break;
                    // handle all redirect even if http specs says " the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user"
                    case HttpStatus.SC_MOVED_PERMANENTLY: // 301
                    case HttpStatus.SC_MOVED_TEMPORARILY: // 302
                    case HttpStatus.SC_SEE_OTHER: // 303
                        put( resource, source, httpEntity, calculateRelocatedUrl( response ) );
                        return;
                    case HttpStatus.SC_FORBIDDEN:
                        fireSessionConnectionRefused();
                        throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );

                    case HttpStatus.SC_NOT_FOUND:
                        throw new ResourceDoesNotExistException( "File: " + url + " does not exist" + reasonPhrase );

                        //add more entries here
                    default:
                    {
                        TransferFailedException e = new TransferFailedException(
                            "Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
                        fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
                        throw e;
                    }
                }

                firePutCompleted( resource, source );

                EntityUtils.consume( response.getEntity() );
            }
            finally
            {
                response.close();
            }
        }
        catch ( IOException e )
        {
            fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
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.