Example usage for org.apache.http.impl.client DefaultHttpClient setHttpRequestRetryHandler

List of usage examples for org.apache.http.impl.client DefaultHttpClient setHttpRequestRetryHandler

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient setHttpRequestRetryHandler.

Prototype

public synchronized void setHttpRequestRetryHandler(final HttpRequestRetryHandler handler) 

Source Link

Usage

From source file:me.code4fun.roboq.Request.java

protected HttpClient createHttpClient(int method, String url, Options opts) {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    // retry count
    int retryCount1 = selectValue(retryCount, prepared != null ? prepared.retryCount : null, 1);
    if (retryCount1 <= 0)
        retryCount1 = 1;//www. j  a v  a2  s. co m
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(retryCount1, false));

    // redirect
    boolean redirect1 = selectValue(redirect, prepared != null ? prepared.redirect : null, true);
    if (redirect1) {
        httpClient.setRedirectHandler(new DefaultRedirectHandler());
    } else {
        httpClient.setRedirectHandler(new RedirectHandler() {
            @Override
            public boolean isRedirectRequested(HttpResponse httpResponse, HttpContext httpContext) {
                return false;
            }

            @Override
            public URI getLocationURI(HttpResponse httpResponse, HttpContext httpContext) {
                return null;
            }
        });
    }

    // 
    Integer connTimeout1 = selectValue(connectionTimeout, prepared != null ? prepared.connectionTimeout : null,
            20000);
    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connTimeout1);

    // Socket
    Integer soTimeout1 = selectValue(soTimeout, prepared != null ? prepared.soTimeout : null, 0);
    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout1);

    return httpClient;
}

From source file:org.jfrog.build.client.PreemptiveHttpClient.java

private DefaultHttpClient createHttpClient(String userName, String password, int timeout) {
    BasicHttpParams params = new BasicHttpParams();
    int timeoutMilliSeconds = timeout * 1000;
    HttpConnectionParams.setConnectionTimeout(params, timeoutMilliSeconds);
    HttpConnectionParams.setSoTimeout(params, timeoutMilliSeconds);
    DefaultHttpClient client = new DefaultHttpClient(params);

    if (userName != null && !"".equals(userName)) {
        client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(userName, password));
        localContext = new BasicHttpContext();

        // Generate BASIC scheme object and stick it to the local execution context
        BasicScheme basicAuth = new BasicScheme();
        localContext.setAttribute("preemptive-auth", basicAuth);

        // Add as the first request interceptor
        client.addRequestInterceptor(new PreemptiveAuth(), 0);
    }//www .  j a v  a  2s  .c  o m
    boolean requestSentRetryEnabled = Boolean.parseBoolean(System.getProperty("requestSentRetryEnabled"));
    if (requestSentRetryEnabled) {
        client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, requestSentRetryEnabled));
    }
    // set the following user agent with each request
    String userAgent = "ArtifactoryBuildClient/" + CLIENT_VERSION;
    HttpProtocolParams.setUserAgent(client.getParams(), userAgent);
    return client;
}

From source file:simple.crawler.http.HttpClientFactory.java

public static DefaultHttpClient createNewDefaultHttpClient() {
    ////w  w  w.j a v a  2s .co m
    HttpParams params = new BasicHttpParams();

    //Determines the connection timeout
    HttpConnectionParams.setConnectionTimeout(params, 1 * 60 * 1000);

    //Determines the socket timeout
    HttpConnectionParams.setSoTimeout(params, 1 * 60 * 1000);

    //Determines whether stale connection check is to be used
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    //The Nagle's algorithm tries to conserve bandwidth by minimizing the number of segments that are sent. 
    //When application wish to decrease network latency and increase performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY)
    //Data will be sent earlier, at the cost of an increase in bandwidth consumption
    HttpConnectionParams.setTcpNoDelay(params, true);

    //
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params,
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.4) Gecko/20100513 Firefox/3.6.4");

    //Create and initialize scheme registry
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    PoolingClientConnectionManager pm = new PoolingClientConnectionManager(schemeRegistry);

    //
    DefaultHttpClient httpclient = new DefaultHttpClient(pm, params);
    //ConnManagerParams.setMaxTotalConnections(params, MAX_HTTP_CONNECTION);
    //ConnManagerParams.setMaxConnectionsPerRoute(params, defaultConnPerRoute);
    //ConnManagerParams.setTimeout(params, 1 * 60 * 1000);
    httpclient.getParams().setParameter("http.conn-manager.max-total", MAX_HTTP_CONNECTION);
    ConnPerRoute defaultConnPerRoute = new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute route) {
            return 4;
        }
    };
    httpclient.getParams().setParameter("http.conn-manager.max-per-route", defaultConnPerRoute);
    httpclient.getParams().setParameter("http.conn-manager.timeout", 1 * 60 * 1000L);
    httpclient.getParams().setParameter("http.protocol.allow-circular-redirects", true);
    httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

    //
    HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (executionCount > 2) {
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                return true;
            }
            if (exception instanceof SSLHandshakeException) {
                return false;
            }
            HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            if (!(request instanceof HttpEntityEnclosingRequest)) {
                return true;
            }
            return false;
        }
    };
    httpclient.setHttpRequestRetryHandler(retryHandler);

    HttpRequestInterceptor requestInterceptor = new HttpRequestInterceptor() {
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip, deflate");
            }
        }
    };

    HttpResponseInterceptor responseInterceptor = new HttpResponseInterceptor() {
        public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            Header header = entity.getContentEncoding();
            if (header != null) {
                HeaderElement[] codecs = header.getElements();
                for (int i = 0; i < codecs.length; i++) {
                    String codecName = codecs[i].getName();
                    if ("gzip".equalsIgnoreCase(codecName)) {
                        response.setEntity(new GzipDecompressingEntity(entity));
                        return;
                    } else if ("deflate".equalsIgnoreCase(codecName)) {
                        response.setEntity(new DeflateDecompressingEntity(entity));
                        return;
                    }
                }
            }
        }
    };

    httpclient.addRequestInterceptor(requestInterceptor);
    httpclient.addResponseInterceptor(responseInterceptor);
    httpclient.setRedirectStrategy(new DefaultRedirectStrategy());

    return httpclient;
}

From source file:org.apache.shindig.gadgets.http.BasicHttpFetcher.java

/**
 * Creates a new fetcher for fetching HTTP objects.  Not really suitable
 * for production use. Use of an HTTP proxy for security is also necessary
 * for production deployment.//from w  w w . ja  va  2  s  . co m
 *
 * @param maxObjSize          Maximum size, in bytes, of the object we will fetch, 0 if no limit..
 * @param connectionTimeoutMs timeout, in milliseconds, for connecting to hosts.
 * @param readTimeoutMs       timeout, in millseconds, for unresponsive connections
 * @param basicHttpFetcherProxy The http proxy to use.
 */
public BasicHttpFetcher(int maxObjSize, int connectionTimeoutMs, int readTimeoutMs,
        String basicHttpFetcherProxy) {
    // Create and initialize HTTP parameters
    setMaxObjectSizeBytes(maxObjSize);
    setSlowResponseWarning(DEFAULT_SLOW_RESPONSE_WARNING);

    HttpParams params = new BasicHttpParams();

    ConnManagerParams.setTimeout(params, connectionTimeoutMs);

    // These are probably overkill for most sites.
    ConnManagerParams.setMaxTotalConnections(params, 1152);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(256));

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(params, "Apache Shindig");
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    HttpConnectionParams.setConnectionTimeout(params, connectionTimeoutMs);
    HttpConnectionParams.setSoTimeout(params, readTimeoutMs);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);

    HttpClientParams.setRedirecting(params, true);
    HttpClientParams.setAuthenticating(params, false);

    // Create and initialize scheme registry
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    DefaultHttpClient client = new DefaultHttpClient(cm, params);

    // Set proxy if set via guice.
    if (!StringUtils.isEmpty(basicHttpFetcherProxy)) {
        String[] splits = basicHttpFetcherProxy.split(":");
        ConnRouteParams.setDefaultProxy(client.getParams(),
                new HttpHost(splits[0], Integer.parseInt(splits[1]), "http"));
    }

    // try resending the request once
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true));

    // Add hooks for gzip/deflate
    client.addRequestInterceptor(new HttpRequestInterceptor() {
        public void process(final org.apache.http.HttpRequest request, final HttpContext context)
                throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip, deflate");
            }
        }
    });
    client.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(final org.apache.http.HttpResponse response, final HttpContext context)
                throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                Header ceheader = entity.getContentEncoding();
                if (ceheader != null) {
                    for (HeaderElement codec : ceheader.getElements()) {
                        String codecname = codec.getName();
                        if ("gzip".equalsIgnoreCase(codecname)) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            return;
                        } else if ("deflate".equals(codecname)) {
                            response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                            return;
                        }
                    }
                }
            }
        }
    });
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler());

    // Disable automatic storage and sending of cookies (see SHINDIG-1382)
    client.removeRequestInterceptorByClass(RequestAddCookies.class);
    client.removeResponseInterceptorByClass(ResponseProcessCookies.class);

    // Use Java's built-in proxy logic in case no proxy set via guice.
    if (StringUtils.isEmpty(basicHttpFetcherProxy)) {
        ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
                client.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
        client.setRoutePlanner(routePlanner);
    }

    FETCHER = client;
}

From source file:org.apache.marmotta.platform.core.services.http.HttpClientServiceImpl.java

@PostConstruct
protected void initialize() {
    try {//from   w  w w . ja v a  2  s.c  o m
        lock.writeLock().lock();

        httpParams = new BasicHttpParams();
        String userAgentString = "Apache Marmotta/"
                + configurationService.getStringConfiguration("kiwi.version") + " (running at "
                + configurationService.getServerUri() + ")" + " lmf-core/"
                + configurationService.getStringConfiguration("kiwi.version");
        userAgentString = configurationService.getStringConfiguration("core.http.user_agent", userAgentString);

        httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
                configurationService.getIntConfiguration("core.http.so_timeout", 60000));
        httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                configurationService.getIntConfiguration("core.http.connection_timeout", 10000));

        httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
        httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);

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

        PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
        cm.setMaxTotal(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS, 20));
        cm.setDefaultMaxPerRoute(
                configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS_PER_ROUTE, 10));

        final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams);
        hc.setRedirectStrategy(new LMFRedirectStrategy());
        hc.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler());
        hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class);
        hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString));

        if (configurationService.getBooleanConfiguration(CoreOptions.HTTP_CLIENT_CACHE_ENABLE, true)) {
            CacheConfig cacheConfig = new CacheConfig();
            // FIXME: Hardcoded constants - is this useful?
            cacheConfig.setMaxCacheEntries(1000);
            cacheConfig.setMaxObjectSize(81920);

            final HttpCacheStorage cacheStore = new MapHttpCacheStorage(httpCache);

            this.httpClient = new MonitoredHttpClient(new CachingHttpClient(hc, cacheStore, cacheConfig));
        } else {
            this.httpClient = new MonitoredHttpClient(hc);
        }
        bytesSent.set(0);
        bytesReceived.set(0);
        requestsExecuted.set(0);

        idleConnectionMonitorThread = new IdleConnectionMonitorThread(httpClient.getConnectionManager());
        idleConnectionMonitorThread.start();

        StatisticsProvider stats = new StatisticsProvider(cm);
        statisticsService.registerModule(HttpClientService.class.getSimpleName(), stats);
    } finally {
        lock.writeLock().unlock();
    }
}

From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java

private void createClient() {
    log.info("Connecting to Opal: {}", opalURI);
    DefaultHttpClient httpClient = new DefaultHttpClient();
    if (keyStore == null)
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
    httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, Boolean.TRUE);
    httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
            Collections.singletonList(OpalAuth.CREDENTIALS_HEADER));
    httpClient.getParams().setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME,
            OpalClientConnectionManagerFactory.class.getName());
    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout);
    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout);
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(DEFAULT_MAX_ATTEMPT, false));
    httpClient.getAuthSchemes().register(OpalAuth.CREDENTIALS_HEADER, new OpalAuthScheme.Factory());

    try {//w  w  w.  j  av  a2s. c o m
        httpClient.getConnectionManager().getSchemeRegistry()
                .register(new Scheme("https", HTTPS_PORT, getSocketFactory()));
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException(e);
    }
    client = enableCaching(httpClient);

    ctx = new BasicHttpContext();
    ctx.setAttribute(ClientContext.COOKIE_STORE, new BasicCookieStore());
}

From source file:net.timbusproject.extractors.pojo.CallBack.java

public synchronized void doCallBack(long key, RequestExtractionList extractionList, boolean success)
        throws URISyntaxException, IOException {
    CallBackInfo info = extractionList.getCallbackInfo();
    System.out.println("IN CALLBACK. REQUEST TYPE: " + info.getFinalOriginRequestType());
    if (info == null)
        System.out.println("No callback information provided");
    else {/*w  ww  .ja v  a2s.  c  o  m*/
        if (info.getMails() != null) {
            setMailConfiguration();
            for (String a : info.getMails()) {
                System.out.println("Email adress is: " + a);
                if (isValidEmailAddress(a)) {
                    sendEmail(a, "End of extraction request",
                            "The extractions were completed. Please, check out /extractors/api/requests/ to view the results");
                    System.out.println("Sent email: " + a);
                }
            }
        } else
            System.out.println("No e-mail adress(es) provided");
        if (info.getEndPoints() != null) {
            for (String a : info.getEndPoints()) {
                HttpResponse response;
                if (info.requestType != null && info.requestType.toLowerCase().equals("post")) {
                    try {
                        JSONObject jsonResult = new JSONObject().put("id", key);
                        if (success)
                            jsonResult.put("result", "completed");
                        else
                            jsonResult.put("result", "failed");
                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        HttpPost postRequest = new HttpPost(a);
                        postRequest.setEntity(new StringEntity(jsonResult.toString(),
                                ContentType.create("application/json")));
                        response = httpClient.execute(postRequest);
                        System.out.println("Sent POST request to " + a);
                        System.out.println("Endpoint " + a + " says: " + response.getStatusLine());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    System.out.println("Sending GET request to: " + a);
                    String uri = a;
                    if (!uri.startsWith("http://"))
                        uri = "http://" + uri;
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
                    response = httpClient.execute(new HttpGet(uri));
                    System.out.println("Sent GET request to " + uri);
                    System.out.println("Endpoint " + a + " says: " + response.getStatusLine());
                }
            }
        } else {
            System.out.println("No foreign endpoints for callback provided");
        }
        if (info.getOriginEndpoint() != null) {
            HttpResponse response;
            if (info.getFinalOriginRequestType().equals("post")) {
                System.out
                        .println("Preparing POST request for endpoint " + "http://" + info.getOriginEndpoint());
                try {
                    JSONObject jsonResult = new JSONObject().put("id", key);
                    if (success)
                        jsonResult.put("result", "completed");
                    else
                        jsonResult.put("result", "failed");
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    HttpPost postRequest = new HttpPost("http://" + info.getOriginEndpoint());
                    postRequest.setEntity(
                            new StringEntity(jsonResult.toString(), ContentType.create("application/json")));
                    response = httpClient.execute(postRequest);
                    System.out.println("Sent POST request to " + "http://" + info.getOriginEndpoint());
                    System.out.println("Endpoint " + "http://" + info.getOriginEndpoint() + " says: "
                            + response.getStatusLine());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                System.out
                        .println("Preparing GET request for endpoint " + "http://" + info.getOriginEndpoint());
                DefaultHttpClient httpClient = new DefaultHttpClient();
                httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
                response = httpClient.execute(new HttpGet("http://" + info.getOriginEndpoint()));
            }
        } else {
            System.out.println("No port or path provided for origin endpoint callback");
        }
    }
}

From source file:org.ovirt.engine.sdk.web.ConnectionsPool.java

private void injectHttpRequestRetryHandler(DefaultHttpClient httpclient) {
    HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {

        @Override//from   ww  w . j av a2  s .c  om
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (executionCount >= MAX_RETRY_REQUEST) {
                // Do not retry if over max retry count
                return false;
            }
            if (exception instanceof InterruptedIOException) {
                // Timeout
                return false;
            }
            if (exception instanceof UnknownHostException) {
                // Unknown host
                return false;
            }
            if (exception instanceof ConnectException) {
                // Connection refused
                return false;
            }
            if (exception instanceof SSLException) {
                // SSL handshake exception
                return false;
            }
            HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
            if (idempotent) {
                // Retry if the request is considered idempotent
                return true;
            }
            return false;
        }
    };

    httpclient.setHttpRequestRetryHandler(myRetryHandler);
}

From source file:net.vexelon.mobileops.GLBClient.java

/**
 * Initialize Http Client/* w w w . j a v a 2s . co m*/
 */
private void initHttpClient() {

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setParameter(CoreProtocolPNames.USER_AGENT, UserAgentHelper.getRandomUserAgent());
    //params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8);
    // Bugfix #1: The target server failed to respond
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);

    DefaultHttpClient client = new DefaultHttpClient(params);

    httpCookieStore = new BasicCookieStore();
    client.setCookieStore(httpCookieStore);

    httpContext = new BasicHttpContext();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, httpCookieStore);

    // Bugfix #1: Adding retry handler to repeat failed requests
    HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {

        @Override
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

            if (executionCount >= MAX_REQUEST_RETRIES) {
                return false;
            }

            if (exception instanceof NoHttpResponseException || exception instanceof ClientProtocolException) {
                return true;
            }

            return false;
        }
    };
    client.setHttpRequestRetryHandler(retryHandler);

    // SSL
    HostnameVerifier verifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

    try {
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", new PlainSocketFactory(), 80));
        registry.register(new Scheme("https", new TrustAllSocketFactory(), 443));

        SingleClientConnManager connMgr = new SingleClientConnManager(client.getParams(), registry);

        httpClient = new DefaultHttpClient(connMgr, client.getParams());
    } catch (InvalidAlgorithmParameterException e) {
        //         Log.e(Defs.LOG_TAG, "", e);

        // init without connection manager
        httpClient = new DefaultHttpClient(client.getParams());
    }

    HttpsURLConnection.setDefaultHostnameVerifier(verifier);

}

From source file:org.jets3t.apps.uploader.Uploader.java

private HttpClient initHttpConnection() {
    // Set client parameters.
    HttpParams params = RestUtils.createDefaultHttpParams();
    HttpProtocolParams.setUserAgent(params, ServiceUtils.getUserAgentDescription(APPLICATION_DESCRIPTION));

    // Set connection parameters.
    HttpConnectionParams.setConnectionTimeout(params, HTTP_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_CONNECTION_TIMEOUT);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    DefaultHttpClient httpClient = new DefaultHttpClient(params);
    // Replace default error retry handler.
    httpClient.setHttpRequestRetryHandler(new RestUtils.JetS3tRetryHandler(MAX_CONNECTION_RETRIES, null));

    return httpClient;
}