当前位置: 首页>>代码示例>>Java>>正文


Java SyncBasicHttpContext类代码示例

本文整理汇总了Java中org.apache.http.protocol.SyncBasicHttpContext的典型用法代码示例。如果您正苦于以下问题:Java SyncBasicHttpContext类的具体用法?Java SyncBasicHttpContext怎么用?Java SyncBasicHttpContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SyncBasicHttpContext类属于org.apache.http.protocol包,在下文中一共展示了SyncBasicHttpContext类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
/** 执行网络访问 */
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;
}
 
开发者ID:xfshipan,项目名称:miappstore,代码行数:22,代码来源:HttpHelper.java

示例2: execute

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
/** 执行网络访问 */
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;
}
 
开发者ID:cuilitang,项目名称:CuiMarket,代码行数:23,代码来源:HttpHelper.java

示例3: AsyncHttpClient

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
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));
}
 
开发者ID:vishnudevk,项目名称:MiBandDecompiled,代码行数:26,代码来源:AsyncHttpClient.java

示例4: execute

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
/**
     * 执行网络访问
     */
    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);
                }
            }
        }
    }
 
开发者ID:liaozhoubei,项目名称:NetEasyNews,代码行数:40,代码来源:HttpHelper.java

示例5: HttpDispatcher

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
HttpDispatcher(HttpHost host, HttpContext context){
	this.context = new SyncBasicHttpContext(context);
	this.host = new HttpHost(host);
	
}
 
开发者ID:SanaMobile,项目名称:sana.mobile,代码行数:6,代码来源:HttpDispatcher.java

示例6: DigiDocServiceAccessor

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
public DigiDocServiceAccessor() {
	httpClient = getHttpClient();
	httpContext = new SyncBasicHttpContext(null);
}
 
开发者ID:aleksz,项目名称:driveddoc,代码行数:5,代码来源:DigiDocServiceAccessor.java

示例7: DobroNetwork

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
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);
	}
 
开发者ID:rdmwfs,项目名称:dobroreader-mod,代码行数:51,代码来源:DobroNetwork.java

示例8: setupHttp

import org.apache.http.protocol.SyncBasicHttpContext; //导入依赖的package包/类
private void setupHttp() {

        httpContext = new SyncBasicHttpContext(new BasicHttpContext());

        sHttpClient.setHttpRequestRetryHandler(new RetryHandler(
                DEFAULT_MAX_RETRIES, DEFAULT_RETRY_SLEEP_TIME_MILLIS));
    }
 
开发者ID:islamsamak,项目名称:janadroid,代码行数:8,代码来源:AbstractHttpConnection.java


注:本文中的org.apache.http.protocol.SyncBasicHttpContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。