Java 类org.apache.http.protocol.SyncBasicHttpContext 实例源码

项目:miappstore    文件:HttpHelper.java   
/** 执行网络访问 */
private static HttpResult execute(String url, HttpRequestBase requestBase) {
    boolean isHttps = url.startsWith("https://");//判断是否需要采用https
    AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
    HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
    HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//获取重试机制
    int retryCount = 0;
    boolean retry = true;
    while (retry) {
        try {
            HttpResponse response = httpClient.execute(requestBase, httpContext);//访问网络
            if (response != null) {
                return new HttpResult(response, httpClient, requestBase);
            }
        } catch (Exception e) {
            IOException ioException = new IOException(e.getMessage());
            retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把错误异常交给重试机制,以判断是否需要采取从事
        }
    }
    return null;
}
项目:CuiMarket    文件:HttpHelper.java   
/** 执行网络访问 */
private static HttpResult execute(String url, HttpRequestBase requestBase) {
    boolean isHttps = url.startsWith("https://");//判断是否需要采用https
    AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
    HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
    HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//获取重试机制
    int retryCount = 0;
    boolean retry = true;
    while (retry) {
        try {
            HttpResponse response = httpClient.execute(requestBase, httpContext);//访问网络
            if (response != null) {
                return new HttpResult(response, httpClient, requestBase);
            }
        } catch (Exception e) {
            IOException ioException = new IOException(e.getMessage());
            retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把错误异常交给重试机制,以判断是否需要采取从事
            LogUtils.e(e);
        }
    }
    return null;
}
项目:MiBandDecompiled    文件:AsyncHttpClient.java   
public AsyncHttpClient(SchemeRegistry schemeregistry)
{
    a = 10;
    b = 10000;
    h = true;
    BasicHttpParams basichttpparams = new BasicHttpParams();
    ConnManagerParams.setTimeout(basichttpparams, b);
    ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a));
    ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
    HttpConnectionParams.setSoTimeout(basichttpparams, b);
    HttpConnectionParams.setConnectionTimeout(basichttpparams, b);
    HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
    HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
    HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
    ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry);
    e = getDefaultThreadPool();
    f = new WeakHashMap();
    g = new HashMap();
    d = new SyncBasicHttpContext(new BasicHttpContext());
    c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams);
    c.addRequestInterceptor(new a(this));
    c.addResponseInterceptor(new b(this));
    c.addRequestInterceptor(new c(this), 0);
    c.setHttpRequestRetryHandler(new z(5, 1500));
}
项目:NetEasyNews    文件:HttpHelper.java   
/**
     * 执行网络访问
     */
    private static void execute(String url, HttpRequestBase requestBase, HttpCallbackListener httpCallbackListener) {
        boolean isHttps = url.startsWith("https://");//判断是否需要采用https
        AbstractHttpClient httpClient = HttpClientFactory.create(isHttps);
        HttpContext httpContext = new SyncBasicHttpContext(new BasicHttpContext());
        HttpRequestRetryHandler retryHandler = httpClient.getHttpRequestRetryHandler();//获取重试机制
        int retryCount = 0;
        boolean retry = true;
        while (retry) {
            try {
                HttpResponse response = httpClient.execute(requestBase, httpContext);//访问网络
                int stateCode  = response.getStatusLine().getStatusCode();
//                LogUtils.e(TAG, "http状态码:" + stateCode);
                if (response != null) {
                    if (stateCode == HttpURLConnection.HTTP_OK){
                        HttpResult httpResult = new HttpResult(response, httpClient, requestBase);
                        String result = httpResult.getString();
                        if (!TextUtils.isEmpty(result)){
                            httpCallbackListener.onSuccess(result);
                            return;
                        } else {
                            throw new RuntimeException("数据为空");
                        }
                    } else {
                        throw new RuntimeException(HttpRequestCode.ReturnCode(stateCode));
                    }
                }
            } catch (Exception e) {
                IOException ioException = new IOException(e.getMessage());
                retry = retryHandler.retryRequest(ioException, ++retryCount, httpContext);//把错误异常交给重试机制,以判断是否需要采取从事
                LogUtils.e(TAG, "重复次数:" + retryCount + "   :"+ e);
                if (!retry){
                    httpCallbackListener.onError(e);
                }
            }
        }
    }
项目:sana.mobile    文件:HttpDispatcher.java   
HttpDispatcher(HttpHost host, HttpContext context){
    this.context = new SyncBasicHttpContext(context);
    this.host = new HttpHost(host);

}
项目:driveddoc    文件:DigiDocServiceAccessor.java   
public DigiDocServiceAccessor() {
    httpClient = getHttpClient();
    httpContext = new SyncBasicHttpContext(null);
}
项目:dobroreader-mod    文件:DobroNetwork.java   
public DobroNetwork(DobroApplication context) {

        BasicHttpParams httpParams = new BasicHttpParams();

        ConnManagerParams.setTimeout(httpParams, 10000);
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(20));
        ConnManagerParams.setMaxTotalConnections(httpParams, 20);

        HttpConnectionParams.setSoTimeout(httpParams, 10000);
        HttpConnectionParams.setTcpNoDelay(httpParams, true);
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);

        HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUserAgent(httpParams, getUserAgent());

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

        m_http_context = new SyncBasicHttpContext(new BasicHttpContext());
        m_httpclient = new DefaultHttpClient(cm, httpParams);

        m_cookie_store = new BasicCookieStore();
        loadCookies();
        m_http_context.setAttribute(ClientContext.COOKIE_STORE, m_cookie_store);
        createDownloadReceiver();


        File cacheDir = StorageUtils.getIndividualCacheDirectory(context);
        disc_cache = new TotalSizeLimitedDiscCache(cacheDir, 30 * 1024 * 1024);
        memory_cache = new UsingFreqLimitedMemoryCache(2 * 1024 * 1024);
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .threadPoolSize(5)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .memoryCache(memory_cache)
                .discCache(disc_cache)
                .imageDownloader(new HttpClientImageDownloader(context, m_httpclient))
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .defaultDisplayImageOptions(new DisplayImageOptions.Builder()
                    .cacheInMemory()
                    .cacheOnDisc()
                    .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                    .bitmapConfig(Bitmap.Config.ARGB_8888)
                    .displayer(new SimpleBitmapDisplayer())
                    .build())
                .enableLogging()
                .build();
        ImageLoader.getInstance().init(config);
    }
项目:janadroid    文件:AbstractHttpConnection.java   
private void setupHttp() {

        httpContext = new SyncBasicHttpContext(new BasicHttpContext());

        sHttpClient.setHttpRequestRetryHandler(new RetryHandler(
                DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
    }