Java 类org.apache.http.client.RequestDirector 实例源码

项目:FullRobolectricTestSample    文件:FakeHttpLayer.java   
public HttpResponse emulateRequest(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext, RequestDirector requestDirector) throws HttpException, IOException {
  if (logHttpRequests) {
    System.out.println("  <-- " + httpRequest.getRequestLine());
  }
  HttpResponse httpResponse = findResponse(httpRequest);
  if (logHttpRequests) {
    System.out.println("  --> " + (httpResponse == null ? null : httpResponse.getStatusLine().getStatusCode()));
  }

  if (httpResponse == null) {
    throw new RuntimeException("Unexpected call to execute, no pending responses are available. See Robolectric.addPendingResponse(). Request was: " +
        httpRequest.getRequestLine().getMethod() + " " + httpRequest.getRequestLine().getUri());
  } else {
    HttpParams params = httpResponse.getParams();

    if (HttpConnectionParams.getConnectionTimeout(params) < 0) {
      throw new ConnectTimeoutException("Socket is not connected");
    } else if (HttpConnectionParams.getSoTimeout(params) < 0) {
      throw new ConnectTimeoutException("The operation timed out");
    }
  }

  addRequestInfo(new HttpRequestInfo(httpRequest, httpHost, httpContext, requestDirector));
  addHttpResponse(httpResponse);
  return httpResponse;
}
项目:SoundcloudAPI    文件:ApiWrapper.java   
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
                                             ClientConnectionManager conman,
                                             ConnectionReuseStrategy reustrat,
                                             ConnectionKeepAliveStrategy kastrat,
                                             HttpRoutePlanner rouplan,
                                             HttpProcessor httpProcessor,
                                             HttpRequestRetryHandler retryHandler,
                                             RedirectHandler redirectHandler,
                                             AuthenticationHandler targetAuthHandler,
                                             AuthenticationHandler proxyAuthHandler,
                                             UserTokenHandler stateHandler,
                                             HttpParams params
) {
    return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan,
            httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler,
            stateHandler, params);
}
项目:paperchains    文件:ApiWrapper.java   
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
                                             ClientConnectionManager conman,
                                             ConnectionReuseStrategy reustrat,
                                             ConnectionKeepAliveStrategy kastrat,
                                             HttpRoutePlanner rouplan,
                                             HttpProcessor httpProcessor,
                                             HttpRequestRetryHandler retryHandler,
                                             RedirectHandler redirectHandler,
                                             AuthenticationHandler targetAuthHandler,
                                             AuthenticationHandler proxyAuthHandler,
                                             UserTokenHandler stateHandler,
                                             HttpParams params
) {
    return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan,
            httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler,
            stateHandler, params);
}
项目:lams    文件:AbstractHttpClient.java   
/**
 * @deprecated (4.1) do not use
 */
@Deprecated
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            userTokenHandler,
            params);
}
项目:lams    文件:AbstractHttpClient.java   
/**
 * @deprecated (4.2) do not use
 */
@Deprecated 
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectStrategy redirectStrategy,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            log,
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectStrategy,
            targetAuthHandler,
            proxyAuthHandler,
            userTokenHandler,
            params);
}
项目:lams    文件:AbstractHttpClient.java   
/**
 * @since 4.2
 */
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectStrategy redirectStrategy,
        final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            log,
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectStrategy,
            targetAuthStrategy,
            proxyAuthStrategy,
            userTokenHandler,
            params);
}
项目:purecloud-iot    文件:AbstractHttpClient.java   
/**
 * @deprecated (4.1) do not use
 */
@Deprecated
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            userTokenHandler,
            params);
}
项目:purecloud-iot    文件:AbstractHttpClient.java   
/**
 * @deprecated (4.2) do not use
 */
@Deprecated
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectStrategy redirectStrategy,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            log,
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectStrategy,
            targetAuthHandler,
            proxyAuthHandler,
            userTokenHandler,
            params);
}
项目:purecloud-iot    文件:AbstractHttpClient.java   
/**
 * @since 4.2
 */
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectStrategy redirectStrategy,
        final AuthenticationStrategy targetAuthStrategy,
        final AuthenticationStrategy proxyAuthStrategy,
        final UserTokenHandler userTokenHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            log,
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectStrategy,
            targetAuthStrategy,
            proxyAuthStrategy,
            userTokenHandler,
            params);
}
项目:FMTech    文件:AndroidHttpClient.java   
private AndroidHttpClient(ClientConnectionManager paramClientConnectionManager, HttpParams paramHttpParams)
{
  this.delegate = new DefaultHttpClient(paramClientConnectionManager, paramHttpParams)
  {
    protected final RequestDirector createClientRequestDirector(HttpRequestExecutor paramAnonymousHttpRequestExecutor, ClientConnectionManager paramAnonymousClientConnectionManager, ConnectionReuseStrategy paramAnonymousConnectionReuseStrategy, ConnectionKeepAliveStrategy paramAnonymousConnectionKeepAliveStrategy, HttpRoutePlanner paramAnonymousHttpRoutePlanner, HttpProcessor paramAnonymousHttpProcessor, HttpRequestRetryHandler paramAnonymousHttpRequestRetryHandler, RedirectHandler paramAnonymousRedirectHandler, AuthenticationHandler paramAnonymousAuthenticationHandler1, AuthenticationHandler paramAnonymousAuthenticationHandler2, UserTokenHandler paramAnonymousUserTokenHandler, HttpParams paramAnonymousHttpParams)
    {
      return new ElegantRequestDirector(paramAnonymousHttpRequestExecutor, paramAnonymousClientConnectionManager, paramAnonymousConnectionReuseStrategy, paramAnonymousConnectionKeepAliveStrategy, paramAnonymousHttpRoutePlanner, paramAnonymousHttpProcessor, paramAnonymousHttpRequestRetryHandler, paramAnonymousRedirectHandler, paramAnonymousAuthenticationHandler1, paramAnonymousAuthenticationHandler2, paramAnonymousUserTokenHandler, paramAnonymousHttpParams);
    }

    protected final HttpContext createHttpContext()
    {
      BasicHttpContext localBasicHttpContext = new BasicHttpContext();
      localBasicHttpContext.setAttribute("http.authscheme-registry", getAuthSchemes());
      localBasicHttpContext.setAttribute("http.cookiespec-registry", getCookieSpecs());
      localBasicHttpContext.setAttribute("http.auth.credentials-provider", getCredentialsProvider());
      return localBasicHttpContext;
    }

    protected final BasicHttpProcessor createHttpProcessor()
    {
      BasicHttpProcessor localBasicHttpProcessor = super.createHttpProcessor();
      localBasicHttpProcessor.addRequestInterceptor(AndroidHttpClient.sThreadCheckInterceptor);
      localBasicHttpProcessor.addRequestInterceptor(new AndroidHttpClient.CurlLogger(AndroidHttpClient.this, (byte)0));
      return localBasicHttpProcessor;
    }
  };
}
项目:cJUnit-mc626    文件:AbstractHttpClient.java   
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler stateHandler,
        final HttpParams params) {
    return new DefaultRequestDirector(
            log,
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            stateHandler,
            params);
}
项目:YiBo    文件:LibHttpClient.java   
@Override
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler stateHandler,
        final HttpParams params) {
    return new LibRequestDirector(
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            stateHandler,
            params);
}
项目:yibo-library    文件:YiBoHttpClient.java   
@Override
protected RequestDirector createClientRequestDirector(
        final HttpRequestExecutor requestExec,
        final ClientConnectionManager conman,
        final ConnectionReuseStrategy reustrat,
        final ConnectionKeepAliveStrategy kastrat,
        final HttpRoutePlanner rouplan,
        final HttpProcessor httpProcessor,
        final HttpRequestRetryHandler retryHandler,
        final RedirectHandler redirectHandler,
        final AuthenticationHandler targetAuthHandler,
        final AuthenticationHandler proxyAuthHandler,
        final UserTokenHandler stateHandler,
        final HttpParams params) {
    return new YiBoRequestDirector(
            requestExec,
            conman,
            reustrat,
            kastrat,
            rouplan,
            httpProcessor,
            retryHandler,
            redirectHandler,
            targetAuthHandler,
            proxyAuthHandler,
            stateHandler,
            params);
}
项目:BigSemanticsJava    文件:RedirectHttpClient.java   
@Override
protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec,
                                                      ClientConnectionManager conman,
                                                      ConnectionReuseStrategy reustrat,
                                                      ConnectionKeepAliveStrategy kastrat,
                                                      HttpRoutePlanner rouplan,
                                                      HttpProcessor httpProcessor,
                                                      HttpRequestRetryHandler retryHandler,
                                                      RedirectStrategy redirectStrategy,
                                                      AuthenticationStrategy targetAuthStrategy,
                                                      AuthenticationStrategy proxyAuthStrategy,
                                                      UserTokenHandler userTokenHandler,
                                                      HttpParams params)
{
  return new RedirectRequestDirector(log,
                                     requestExec,
                                     conman,
                                     reustrat,
                                     kastrat,
                                     rouplan,
                                     httpProcessor,
                                     retryHandler,
                                     redirectStrategy,
                                     targetAuthStrategy,
                                     proxyAuthStrategy,
                                     userTokenHandler,
                                     params);
}
项目:SecureShareLib    文件:ApiWrapper.java   
/** This method mainly exists to make the wrapper more testable. oh, apache's insanity. */
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
                                             ClientConnectionManager conman,
                                             ConnectionReuseStrategy reustrat,
                                             ConnectionKeepAliveStrategy kastrat,
                                             HttpRoutePlanner rouplan,
                                             HttpProcessor httpProcessor,
                                             HttpRequestRetryHandler retryHandler,
                                             RedirectHandler redirectHandler,
                                             AuthenticationHandler targetAuthHandler,
                                             AuthenticationHandler proxyAuthHandler,
                                             UserTokenHandler stateHandler,
                                             HttpParams params
) {
    return new DefaultRequestDirector(requestExec, conman, reustrat, kastrat, rouplan,
            httpProcessor, retryHandler, redirectHandler, targetAuthHandler, proxyAuthHandler,
            stateHandler, params);
}
项目:FullRobolectricTestSample    文件:HttpRequestInfo.java   
public HttpRequestInfo(HttpRequest httpRequest, HttpHost httpHost, HttpContext httpContext, RequestDirector requestDirector) {
  this.httpRequest = httpRequest;
  this.httpHost = httpHost;
  this.httpContext = httpContext;
  this.requestDirector = requestDirector;
}
项目:FullRobolectricTestSample    文件:HttpRequestInfo.java   
public RequestDirector getRequestDirector() {
  return requestDirector;
}
项目:SoundcloudAPI    文件:ApiWrapper.java   
/** @return The HttpClient instance used to make the calls */
public HttpClient getHttpClient() {
    if (httpClient == null) {
        final HttpParams params = getParams();
        HttpClientParams.setRedirecting(params, false);
        HttpProtocolParams.setUserAgent(params, getUserAgent());

        final SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", getSocketFactory(), 80));
        final SSLSocketFactory sslFactory = getSSLSocketFactory();
        registry.register(new Scheme("https", sslFactory, 443));
        httpClient = new DefaultHttpClient(
                new ThreadSafeClientConnManager(params, registry),
                params) {
            {
                setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
                    @Override
                    public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
                        return KEEPALIVE_TIMEOUT;
                    }
                });

                getCredentialsProvider().setCredentials(
                    new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, CloudAPI.REALM, OAUTH_SCHEME),
                    OAuth2Scheme.EmptyCredentials.INSTANCE);

                getAuthSchemes().register(CloudAPI.OAUTH_SCHEME, new OAuth2Scheme.Factory(ApiWrapper.this));

                addResponseInterceptor(new HttpResponseInterceptor() {
                    @Override
                    public void process(HttpResponse response, HttpContext context)
                            throws HttpException, IOException {
                        if (response == null || response.getEntity() == null) return;

                        HttpEntity entity = response.getEntity();
                        Header header = entity.getContentEncoding();
                        if (header != null) {
                            for (HeaderElement codec : header.getElements()) {
                                if (codec.getName().equalsIgnoreCase("gzip")) {
                                    response.setEntity(new GzipDecompressingEntity(entity));
                                    break;
                                }
                            }
                        }
                    }
                });
            }

            @Override protected HttpContext createHttpContext() {
                HttpContext ctxt = super.createHttpContext();
                ctxt.setAttribute(ClientContext.AUTH_SCHEME_PREF,
                        Arrays.asList(CloudAPI.OAUTH_SCHEME, "digest", "basic"));
                return ctxt;
            }

            @Override protected BasicHttpProcessor createHttpProcessor() {
                BasicHttpProcessor processor = super.createHttpProcessor();
                processor.addInterceptor(new OAuth2HttpRequestInterceptor());
                return processor;
            }

            // for testability only
            @Override protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec,
                                                                  ClientConnectionManager conman,
                                                                  ConnectionReuseStrategy reustrat,
                                                                  ConnectionKeepAliveStrategy kastrat,
                                                                  HttpRoutePlanner rouplan,
                                                                  HttpProcessor httpProcessor,
                                                                  HttpRequestRetryHandler retryHandler,
                                                                  RedirectHandler redirectHandler,
                                                                  AuthenticationHandler targetAuthHandler,
                                                                  AuthenticationHandler proxyAuthHandler,
                                                                  UserTokenHandler stateHandler,
                                                                  HttpParams params) {
                return getRequestDirector(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
                        redirectHandler, targetAuthHandler, proxyAuthHandler, stateHandler, params);
            }
        };
    }
    return httpClient;
}
项目:paperchains    文件:ApiWrapper.java   
/** @return The HttpClient instance used to make the calls */
public HttpClient getHttpClient() {
    if (httpClient == null) {
        final HttpParams params = getParams();
        HttpClientParams.setRedirecting(params, false);
        HttpProtocolParams.setUserAgent(params, getUserAgent());

        final SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", getSocketFactory(), 80));
        final SSLSocketFactory sslFactory = getSSLSocketFactory();
        registry.register(new Scheme("https", sslFactory, 443));
        httpClient = new DefaultHttpClient(
                new ThreadSafeClientConnManager(params, registry),
                params) {
            {
                setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
                    @Override
                    public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
                        return KEEPALIVE_TIMEOUT;
                    }
                });

                getCredentialsProvider().setCredentials(
                        new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, CloudAPI.REALM, OAUTH_SCHEME),
                        OAuth2Scheme.EmptyCredentials.INSTANCE);

                getAuthSchemes().register(CloudAPI.OAUTH_SCHEME, new OAuth2Scheme.Factory(ApiWrapper.this));

                addResponseInterceptor(new HttpResponseInterceptor() {
                    @Override
                    public void process(HttpResponse response, HttpContext context)
                            throws HttpException, IOException {
                        if (response == null || response.getEntity() == null) return;

                        HttpEntity entity = response.getEntity();
                        Header header = entity.getContentEncoding();
                        if (header != null) {
                            for (HeaderElement codec : header.getElements()) {
                                if (codec.getName().equalsIgnoreCase("gzip")) {
                                    response.setEntity(new GzipDecompressingEntity(entity));
                                    break;
                                }
                            }
                        }
                    }
                });
            }

            @Override protected HttpContext createHttpContext() {
                HttpContext ctxt = super.createHttpContext();
                ctxt.setAttribute(ClientContext.AUTH_SCHEME_PREF,
                        Arrays.asList(CloudAPI.OAUTH_SCHEME, "digest", "basic"));
                return ctxt;
            }

            @Override protected BasicHttpProcessor createHttpProcessor() {
                BasicHttpProcessor processor = super.createHttpProcessor();
                processor.addInterceptor(new OAuth2HttpRequestInterceptor());
                return processor;
            }

            // for testability only
            @Override protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec,
                                                                            ClientConnectionManager conman,
                                                                            ConnectionReuseStrategy reustrat,
                                                                            ConnectionKeepAliveStrategy kastrat,
                                                                            HttpRoutePlanner rouplan,
                                                                            HttpProcessor httpProcessor,
                                                                            HttpRequestRetryHandler retryHandler,
                                                                            RedirectHandler redirectHandler,
                                                                            AuthenticationHandler targetAuthHandler,
                                                                            AuthenticationHandler proxyAuthHandler,
                                                                            UserTokenHandler stateHandler,
                                                                            HttpParams params) {
                return getRequestDirector(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
                        redirectHandler, targetAuthHandler, proxyAuthHandler, stateHandler, params);
            }
        };
    }
    return httpClient;
}
项目:SecureShareLib    文件:ApiWrapper.java   
/** @return The HttpClient instance used to make the calls */
public HttpClient getHttpClient() {
    if (httpClient == null) {
        final HttpParams params = getParams();
        HttpClientParams.setRedirecting(params, false);
        HttpProtocolParams.setUserAgent(params, getUserAgent());

        final SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", getSocketFactory(), 80));
        final SSLSocketFactory sslFactory = getSSLSocketFactory();
        registry.register(new Scheme("https", sslFactory, 443));
        httpClient = new DefaultHttpClient(
                new ThreadSafeClientConnManager(params, registry),
                params) {
            {
                setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
                    @Override
                    public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
                        return KEEPALIVE_TIMEOUT;
                    }
                });

                getCredentialsProvider().setCredentials(
                    new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, CloudAPI.REALM, OAUTH_SCHEME),
                    OAuth2Scheme.EmptyCredentials.INSTANCE);

                getAuthSchemes().register(CloudAPI.OAUTH_SCHEME, new OAuth2Scheme.Factory(ApiWrapper.this));

                addResponseInterceptor(new HttpResponseInterceptor() {
                    @Override
                    public void process(HttpResponse response, HttpContext context)
                            throws HttpException, IOException {
                        if (response == null || response.getEntity() == null) return;

                        HttpEntity entity = response.getEntity();
                        Header header = entity.getContentEncoding();
                        if (header != null) {
                            for (HeaderElement codec : header.getElements()) {
                                if (codec.getName().equalsIgnoreCase("gzip")) {
                                    response.setEntity(new GzipDecompressingEntity(entity));
                                    break;
                                }
                            }
                        }
                    }
                });
            }

            @Override protected HttpContext createHttpContext() {
                HttpContext ctxt = super.createHttpContext();
                ctxt.setAttribute(ClientContext.AUTH_SCHEME_PREF,
                        Arrays.asList(CloudAPI.OAUTH_SCHEME, "digest", "basic"));
                return ctxt;
            }

            @Override protected BasicHttpProcessor createHttpProcessor() {
                BasicHttpProcessor processor = super.createHttpProcessor();
                processor.addInterceptor(new OAuth2HttpRequestInterceptor());
                return processor;
            }

            // for testability only
            @Override protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec,
                                                                  ClientConnectionManager conman,
                                                                  ConnectionReuseStrategy reustrat,
                                                                  ConnectionKeepAliveStrategy kastrat,
                                                                  HttpRoutePlanner rouplan,
                                                                  HttpProcessor httpProcessor,
                                                                  HttpRequestRetryHandler retryHandler,
                                                                  RedirectHandler redirectHandler,
                                                                  AuthenticationHandler targetAuthHandler,
                                                                  AuthenticationHandler proxyAuthHandler,
                                                                  UserTokenHandler stateHandler,
                                                                  HttpParams params) {
                return getRequestDirector(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
                        redirectHandler, targetAuthHandler, proxyAuthHandler, stateHandler, params);
            }
        };
    }
    return httpClient;
}