Example usage for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingClientConnectionManager setMaxTotal.

Prototype

public void setMaxTotal(final int max) 

Source Link

Usage

From source file:API.amazon.mws.products.MarketplaceWebServiceProductsClient.java

/**
 * Configure HttpClient with set of defaults as well as configuration from
 * MarketplaceWebServiceProductsConfig instance
 * //w ww.  jav  a 2 s.c  o  m
 */

private HttpClient configureHttpClient(String applicationName, String applicationVersion) {

    // respect a user-provided User-Agent header as-is, but if none is provided
    // then generate one satisfying the MWS User-Agent requirements
    if (config.getUserAgent() == null) {
        config.setUserAgent(quoteAppName(applicationName), quoteAppVersion(applicationVersion),
                quoteAttributeValue("Java/" + System.getProperty("java.version") + "/"
                        + System.getProperty("java.class.version") + "/" + System.getProperty("java.vendor")),

                quoteAttributeName("Platform"),
                quoteAttributeValue("" + System.getProperty("os.name") + "/" + System.getProperty("os.arch")
                        + "/" + System.getProperty("os.version")),

                quoteAttributeName("MWSClientVersion"), quoteAttributeValue(clientVersion));
    }

    defaultHeaders.add(new BasicHeader("X-Amazon-User-Agent", config.getUserAgent()));

    /* Set http client parameters */
    BasicHttpParams httpParams = new BasicHttpParams();

    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());

    /* Set connection parameters */
    HttpConnectionParams.setConnectionTimeout(httpParams, 50000);
    HttpConnectionParams.setSoTimeout(httpParams, 50000);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);

    /* Set connection manager */
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(config.getMaxConnections());
    connectionManager.setDefaultMaxPerRoute(config.getMaxConnections());

    /* Set http client */
    httpClient = new DefaultHttpClient(connectionManager, httpParams);
    httpContext = new BasicHttpContext();

    /* Set proxy if configured */
    if (config.isSetProxyHost() && config.isSetProxyPort()) {
        log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: "
                + config.getProxyPort());
        final HttpHost hostConfiguration = new HttpHost(config.getProxyHost(), config.getProxyPort(),
                (usesHttps(config.getServiceURL()) ? "https" : "http"));
        httpContext = new BasicHttpContext();
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hostConfiguration);

        if (config.isSetProxyUsername() && config.isSetProxyPassword()) {
            credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
                    new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword()));
            httpContext.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        }

    }

    return httpClient;
}

From source file:org.lightcouch.CouchDbClientBase.java

/**
 * @return {@link DefaultHttpClient} instance.
 */// w  w  w.  ja va  2s .  c o  m
private HttpClient createHttpClient(CouchDbProperties props) {
    DefaultHttpClient httpclient = null;
    try {
        SchemeSocketFactory ssf = null;
        if (props.getProtocol().equals("https")) {
            TrustManager trustManager = new X509TrustManager() {
                public void checkClientTrusted(X509Certificate[] chain, String authType)
                        throws CertificateException {
                }

                public void checkServerTrusted(X509Certificate[] chain, String authType)
                        throws CertificateException {
                }

                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            };
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, new TrustManager[] { trustManager }, null);
            ssf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            SSLSocket socket = (SSLSocket) ssf.createSocket(null);
            socket.setEnabledCipherSuites(new String[] { "SSL_RSA_WITH_RC4_128_MD5" });
        } else {
            ssf = PlainSocketFactory.getSocketFactory();
        }
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme(props.getProtocol(), props.getPort(), ssf));
        PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry);
        httpclient = new DefaultHttpClient(ccm);
        host = new HttpHost(props.getHost(), props.getPort(), props.getProtocol());
        context = new BasicHttpContext();
        // Http params
        httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, props.getSocketTimeout());
        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                props.getConnectionTimeout());
        int maxConnections = props.getMaxConnections();
        if (maxConnections != 0) {
            ccm.setMaxTotal(maxConnections);
            ccm.setDefaultMaxPerRoute(maxConnections);
        }
        if (props.getProxyHost() != null) {
            HttpHost proxy = new HttpHost(props.getProxyHost(), props.getProxyPort());
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        // basic authentication
        if (props.getUsername() != null && props.getPassword() != null) {
            httpclient.getCredentialsProvider().setCredentials(new AuthScope(props.getHost(), props.getPort()),
                    new UsernamePasswordCredentials(props.getUsername(), props.getPassword()));
            props.clearPassword();
            AuthCache authCache = new BasicAuthCache();
            BasicScheme basicAuth = new BasicScheme();
            authCache.put(host, basicAuth);
            context.setAttribute(ClientContext.AUTH_CACHE, authCache);
        }
        // request interceptor
        httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
            public void process(final HttpRequest request, final HttpContext context) throws IOException {
                if (log.isInfoEnabled())
                    log.info(">> " + request.getRequestLine());
            }
        });
        // response interceptor
        httpclient.addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(final HttpResponse response, final HttpContext context) throws IOException {
                validate(response);
                if (log.isInfoEnabled())
                    log.info("<< Status: " + response.getStatusLine().getStatusCode());
            }
        });
    } catch (Exception e) {
        log.error("Error Creating HTTP client. " + e.getMessage());
        throw new IllegalStateException(e);
    }
    return httpclient;
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

private AnalyticsAPIHttpClient(String protocol, String hostname, int port, int maxPerRoute, int maxConnection,
        int socketTimeout, int connectionTimeout, String trustStoreLocation, String trustStorePassword) {
    this.hostname = hostname;
    this.port = port;
    this.protocol = protocol;
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    if (this.protocol.equalsIgnoreCase(AnalyticsDataConstants.HTTP_PROTOCOL)) {
        schemeRegistry.register(new Scheme(this.protocol, port, PlainSocketFactory.getSocketFactory()));
    } else {/*from   w  w w.  j  av  a2 s. com*/
        System.setProperty(AnalyticsDataConstants.SSL_TRUST_STORE_SYS_PROP, trustStoreLocation);
        System.setProperty(AnalyticsDataConstants.SSL_TRUST_STORE_PASSWORD_SYS_PROP, trustStorePassword);
        schemeRegistry.register(new Scheme(this.protocol, port, SSLSocketFactory.getSocketFactory()));
    }
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setDefaultMaxPerRoute(maxPerRoute);
    connectionManager.setMaxTotal(maxConnection);
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(AllClientPNames.SO_TIMEOUT, socketTimeout);
    params.setParameter(AllClientPNames.CONNECTION_TIMEOUT, connectionTimeout);
    this.httpClient = new DefaultHttpClient(connectionManager, params);
    gson = new GsonBuilder().create();
}

From source file:edu.ehu.galan.lite.utils.wikiminer.WikiminnerHelper.java

private WikiminnerHelper(String pPropDirs) {
    //PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    // Increase max total connection to 200
    // cm.setMaxTotal(100);
    // Increase default max connection per route to 20
    // cm.setDefaultMaxPerRoute(20);
    // Increase max connections for localhost:80 to 50
    PoolingClientConnectionManager pm = new PoolingClientConnectionManager();
    pm.setDefaultMaxPerRoute(20);//ww w .  ja  va  2 s.  c  o m
    pm.setMaxTotal(200);
    httpClient = new DefaultHttpClient(pm);
    //        ConnectionConfig connectionConfig = ConnectionConfig.custom()
    //                .setMalformedInputAction(CodingErrorAction.IGNORE)
    //                .setUnmappableInputAction(CodingErrorAction.IGNORE)
    //                .setCharset(Consts.UTF_8).build();
    //        cm.setDefaultConnectionConfig(connectionConfig);

    //        httpClient = HttpClients.custom()
    //                .setConnectionManager(cm)
    //                .build();
    httpClient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    cache = CacheManager.getInstance().getCache("LiteCache");
    props = new Properties();
    caches = new Caches();
    try {
        props.load(new FileInputStream(new File(pPropDirs + "lite/configs/general.conf")));
        wikiminerUrl = props.getProperty("serviceUrl");
        maxTopics = Integer.parseInt(props.getProperty("maxTopics"));
    } catch (IOException ex) {
        logger.error("Error while setting WikiminerHelper properties files, check dirs", ex);
    }
    localMode = !props.get("localMode").equals("false");
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.meridiowrapper.MeridioWrapper.java

/** The Meridio Wrapper constructor that calls the Meridio login method
*
*@param log                                     a handle to a Log4j logger
*@param meridioDmwsUrl          the URL to the Meridio Document Management Web Service
*@param meridioRmwsUrl          the URL to the Meridio Records Management Web Service
*@param dmwsProxyHost           the proxy for DMWS, or null if none
*@param dmwsProxyPort           the proxy port for DMWS, or -1 if default
*@param rmwsProxyHost           the proxy for RMWS, or null if none
*@param rmwsProxyPort           the proxy port for RMWS, or -1 if default
*@param userName                        the username of the user to log in as, must include the Windows, e.g. domain\\user
*@param password                        the password of the user who is logging in
*@param clientWorkstation       an identifier for the client workstation, could be the IP address, for auditing purposes
*@param protocolFactory         the protocol factory object to use for https communication
*@param engineConfigurationFile the engine configuration object to use to communicate with the web services
*
*@throws RemoteException        if an error is encountered logging into Meridio
*/// w  ww.java2 s .  c  o m
public MeridioWrapper(Logger log, URL meridioDmwsUrl, URL meridioRmwsUrl, URL meridioManifoldCFWSUrl,
        String dmwsProxyHost, String dmwsProxyPort, String rmwsProxyHost, String rmwsProxyPort,
        String mcwsProxyHost, String mcwsProxyPort, String userName, String password, String clientWorkstation,
        javax.net.ssl.SSLSocketFactory mySSLFactory, Class resourceClass, String engineConfigurationFile)
        throws RemoteException, NumberFormatException {
    // Initialize local instance variables
    oLog = log;
    this.engineConfiguration = new ResourceProvider(resourceClass, engineConfigurationFile);
    this.clientWorkstation = clientWorkstation;

    // Set up the pool.
    // We have a choice: We can either have one httpclient instance, which gets reinitialized for every service
    // it connects with (because each one has a potentially different proxy setup), OR we can have a different
    // httpclient for each service.  The latter approach is obviously the more efficient, so I've chosen to do it
    // that way.
    PoolingClientConnectionManager localConnectionManager = new PoolingClientConnectionManager();
    localConnectionManager.setMaxTotal(1);
    if (mySSLFactory != null) {
        SSLSocketFactory myFactory = new SSLSocketFactory(mySSLFactory, new BrowserCompatHostnameVerifier());
        Scheme myHttpsProtocol = new Scheme("https", 443, myFactory);
        localConnectionManager.getSchemeRegistry().register(myHttpsProtocol);
    }
    connectionManager = localConnectionManager;

    // Parse the user and password values
    int index = userName.indexOf("\\");
    String domainUser;
    String domain;
    if (index != -1) {
        domainUser = userName.substring(index + 1);
        domain = userName.substring(0, index);
        if (oLog != null && oLog.isDebugEnabled())
            oLog.debug("Meridio: User is '" + domainUser + "', domain is '" + domain + "'");
    } else {
        domain = null;
        domainUser = userName;
        if (oLog != null && oLog.isDebugEnabled())
            oLog.debug("Meridio: User is '" + domainUser + "'; there is no domain specified");
    }

    if (oLog != null && oLog.isDebugEnabled()) {
        if (password != null && password.length() > 0)
            oLog.debug("Meridio: Password exists");
        else
            oLog.debug("Meridio: Password is null");
    }

    // Initialize the three httpclient objects

    // dmws first
    BasicHttpParams dmwsParams = new BasicHttpParams();
    dmwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
    dmwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    dmwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
    dmwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
    dmwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    DefaultHttpClient localDmwsHttpClient = new DefaultHttpClient(connectionManager, dmwsParams);
    // No retries
    localDmwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            return false;
        }

    });

    localDmwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    if (domainUser != null) {
        localDmwsHttpClient.getCredentialsProvider().setCredentials(
                new AuthScope(meridioDmwsUrl.getHost(), meridioDmwsUrl.getPort()),
                new NTCredentials(domainUser, password, currentHost, domain));
    }
    // Initialize proxy
    if (dmwsProxyHost != null && dmwsProxyHost.length() > 0) {
        int port = (dmwsProxyPort == null || dmwsProxyPort.length() == 0) ? 8080
                : Integer.parseInt(dmwsProxyPort);
        // Configure proxy authentication
        if (domainUser != null && domainUser.length() > 0) {
            localDmwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(dmwsProxyHost, port),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }

        HttpHost proxy = new HttpHost(dmwsProxyHost, port);
        localDmwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    dmwsHttpClient = localDmwsHttpClient;

    // rmws
    BasicHttpParams rmwsParams = new BasicHttpParams();
    rmwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
    rmwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    rmwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
    rmwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
    rmwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    DefaultHttpClient localRmwsHttpClient = new DefaultHttpClient(connectionManager, rmwsParams);
    // No retries
    localRmwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            return false;
        }

    });

    localRmwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    if (domainUser != null) {
        localRmwsHttpClient.getCredentialsProvider().setCredentials(
                new AuthScope(meridioRmwsUrl.getHost(), meridioRmwsUrl.getPort()),
                new NTCredentials(domainUser, password, currentHost, domain));
    }
    // Initialize proxy
    if (rmwsProxyHost != null && rmwsProxyHost.length() > 0) {
        int port = (rmwsProxyPort == null || rmwsProxyPort.length() == 0) ? 8080
                : Integer.parseInt(rmwsProxyPort);
        // Configure proxy authentication
        if (domainUser != null && domainUser.length() > 0) {
            localRmwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(rmwsProxyHost, port),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }

        HttpHost proxy = new HttpHost(rmwsProxyHost, port);
        localRmwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    rmwsHttpClient = localRmwsHttpClient;

    // mcws
    if (meridioManifoldCFWSUrl != null) {
        BasicHttpParams mcwsParams = new BasicHttpParams();
        mcwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
        mcwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
        mcwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
        mcwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
        mcwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
        DefaultHttpClient localMcwsHttpClient = new DefaultHttpClient(connectionManager, mcwsParams);
        // No retries
        localMcwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
            public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                return false;
            }

        });

        localMcwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
        if (domainUser != null) {
            localMcwsHttpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(meridioManifoldCFWSUrl.getHost(), meridioManifoldCFWSUrl.getPort()),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }
        // Initialize proxy
        if (mcwsProxyHost != null && mcwsProxyHost.length() > 0) {
            int port = (mcwsProxyPort == null || mcwsProxyPort.length() == 0) ? 8080
                    : Integer.parseInt(mcwsProxyPort);
            // Configure proxy authentication
            if (domainUser != null && domainUser.length() > 0) {
                localMcwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(mcwsProxyHost, port),
                        new NTCredentials(domainUser, password, currentHost, domain));
            }

            HttpHost proxy = new HttpHost(mcwsProxyHost, port);
            localMcwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        mcwsHttpClient = localMcwsHttpClient;
    } else
        mcwsHttpClient = null;

    // Set up the stub handles
    /*=================================================================
    * Get a handle to the DMWS
    *================================================================*/
    MeridioDMLocator meridioDMLocator = new MeridioDMLocator(engineConfiguration);
    MeridioDMSoapStub meridioDMWebService = new MeridioDMSoapStub(meridioDmwsUrl, meridioDMLocator);

    meridioDMWebService.setPortName(meridioDMLocator.getMeridioDMSoapWSDDServiceName());
    meridioDMWebService.setUsername(userName);
    meridioDMWebService.setPassword(password);
    meridioDMWebService._setProperty(HTTPCLIENT_PROPERTY, dmwsHttpClient);

    meridioDMWebService_ = meridioDMWebService;

    /*=================================================================
    * Get a handle to the RMWS
    *================================================================*/
    MeridioRMLocator meridioRMLocator = new MeridioRMLocator(engineConfiguration);
    MeridioRMSoapStub meridioRMWebService = new MeridioRMSoapStub(meridioRmwsUrl, meridioRMLocator);

    meridioRMWebService.setPortName(meridioRMLocator.getMeridioRMSoapWSDDServiceName());
    meridioRMWebService.setUsername(userName);
    meridioRMWebService.setPassword(password);
    meridioRMWebService._setProperty(HTTPCLIENT_PROPERTY, rmwsHttpClient);

    meridioRMWebService_ = meridioRMWebService;

    /*=================================================================
    * Get a handle to the MeridioMetaCarta Web Service
    *================================================================*/
    if (meridioManifoldCFWSUrl != null) {
        MetaCartaLocator meridioMCWS = new MetaCartaLocator(engineConfiguration);
        Service McWsService = null;
        MetaCartaSoapStub meridioMetaCartaWebService = new MetaCartaSoapStub(meridioManifoldCFWSUrl,
                McWsService);

        meridioMetaCartaWebService.setPortName(meridioMCWS.getMetaCartaSoapWSDDServiceName());
        meridioMetaCartaWebService.setUsername(userName);
        meridioMetaCartaWebService.setPassword(password);
        meridioMetaCartaWebService._setProperty(HTTPCLIENT_PROPERTY, mcwsHttpClient);

        meridioMCWS_ = meridioMetaCartaWebService;
    }

    this.loginUnified();
}

From source file:com.emc.esu.api.rest.EsuRestApiApache.java

/**
 * Creates a new EsuRestApiApache object.
 * /* w  w  w .j  a  v a 2 s .  c  om*/
 * @param host the hostname or IP address of the ESU server
 * @param port the port on the server to communicate with. Generally this is
 *            80 for HTTP and 443 for HTTPS.
 * @param uid the username to use when connecting to the server
 * @param sharedSecret the Base64 encoded shared secret to use to sign
 *            requests to the server.
 */
public EsuRestApiApache(String host, int port, String uid, String sharedSecret) {
    super(host, port, uid, sharedSecret);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("https", port, SSLSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("http", port, PlainSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    // Increase max total connection to 200
    cm.setMaxTotal(200);
    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(200);

    httpClient = new DefaultHttpClient(cm, null);
}

From source file:API.amazon.mws.feeds.service.MarketplaceWebServiceClient.java

/**
 * Configure HttpClient with set of defaults as well as configuration
 * from MarketplaceWebServiceConfig instance
 *
 *///from  w w w . ja  v  a  2 s  .c  o m
private HttpClient configureHttpClient(String applicationName, String applicationVersion) {

    // respect a user-provided User-Agent header as-is, but if none is provided
    // then generate one satisfying the MWS User-Agent requirements
    if (config.getUserAgent() == null) {
        config.setUserAgent(quoteAppName(applicationName), quoteAppVersion(applicationVersion),
                quoteAttributeValue("Java/" + System.getProperty("java.version") + "/"
                        + System.getProperty("java.class.version") + "/" + System.getProperty("java.vendor")),

                quoteAttributeName("Platform"),
                quoteAttributeValue("" + System.getProperty("os.name") + "/" + System.getProperty("os.arch")
                        + "/" + System.getProperty("os.version")),

                quoteAttributeName("MWSClientVersion"), quoteAttributeValue(mwsClientLibraryVersion));
    }

    defaultHeaders.add(new BasicHeader("X-Amazon-User-Agent", config.getUserAgent()));

    /* Set http client parameters */
    BasicHttpParams httpParams = new BasicHttpParams();

    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());

    /* Set connection parameters */
    HttpConnectionParams.setConnectionTimeout(httpParams, config.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(httpParams, config.getSoTimeout());
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);

    /* Set connection manager */
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(config.getMaxAsyncQueueSize());
    connectionManager.setDefaultMaxPerRoute(config.getMaxAsyncQueueSize());

    /* Set http client */
    httpClient = new DefaultHttpClient(connectionManager, httpParams);
    httpContext = new BasicHttpContext();

    /* Set proxy if configured */
    if (config.isSetProxyHost() && config.isSetProxyPort()) {
        log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: "
                + config.getProxyPort());
        final HttpHost hostConfiguration = new HttpHost(config.getProxyHost(), config.getProxyPort(),
                (usesHttps(config.getServiceURL()) ? "https" : "http"));
        httpContext = new BasicHttpContext();
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hostConfiguration);

        if (config.isSetProxyUsername() && config.isSetProxyPassword()) {
            credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
                    new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword()));
            httpContext.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        }

    }

    return httpClient;
}