List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager
@Deprecated public ThreadSafeClientConnManager(final HttpParams params, final SchemeRegistry schreg)
From source file:com.jayqqaa12.abase.core.AHttp.java
public AHttp() { HttpParams params = new BasicHttpParams(); ConnManagerParams.setTimeout(params, AHttp.DEFAULT_CONN_TIMEOUT); HttpConnectionParams.setSoTimeout(params, AHttp.DEFAULT_CONN_TIMEOUT); HttpConnectionParams.setConnectionTimeout(params, AHttp.DEFAULT_CONN_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(10)); ConnManagerParams.setMaxTotalConnections(params, 10); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 1024 * 8); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", DefaultSSLSocketFactory.getSocketFactory(), 443)); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_RETRY_TIMES)); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override/*from w w w . j a va 2s. c om*/ public void process(org.apache.http.HttpRequest httpRequest, HttpContext httpContext) throws org.apache.http.HttpException, IOException { if (!httpRequest.containsHeader(HEADER_ACCEPT_ENCODING)) { httpRequest.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext httpContext) throws org.apache.http.HttpException, IOException { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase("gzip")) { response.setEntity(new GZipDecompressingEntity(response.getEntity())); return; } } } } }); }
From source file:httpclient.conn.ManagerConnectDirect.java
private final static ClientConnectionManager createManager() { return new ThreadSafeClientConnManager(getParams(), supportedSchemes); }
From source file:com.wialon.remote.ApacheSdkHttpClient.java
private void initDefaultClient() { BasicHttpParams httpParams = getBasicHttpParams(DEFAULT_SOCKET_TIMEOUT); KeyStore trustStore;//from w ww . ja v a 2s . com SSLSocketFactory sf = null; try { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); sf = new TrustAllSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception e) { e.printStackTrace(); } registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (sf != null) registry.register(new Scheme("https", sf, 443)); ThreadSafeClientConnManager clientConnectionManager = new ThreadSafeClientConnManager(httpParams, registry); defaultHttpClient = new DefaultHttpClient(clientConnectionManager, httpParams); }
From source file:com.rackspacecloud.client.service_registry.clients.BaseClient.java
public BaseClient(AuthClient authClient, String apiUrl) { this(new DefaultHttpClient() { protected HttpParams createHttpParams() { BasicHttpParams params = new BasicHttpParams(); org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 10000); params.setParameter("http.socket.timeout", 10000); return params; }//ww w .jav a2 s . c om @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); return new ThreadSafeClientConnManager(createHttpParams(), schemeRegistry); } }, authClient, apiUrl); }
From source file:com.xorcode.andtweet.net.ConnectionOAuth.java
public ConnectionOAuth(SharedPreferences sp) { super(sp);//from w w w . ja va 2 s .c o m HttpParams parameters = new BasicHttpParams(); HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(parameters, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(parameters, false); HttpConnectionParams.setTcpNoDelay(parameters, true); HttpConnectionParams.setSocketBufferSize(parameters, 8192); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager tsccm = new ThreadSafeClientConnManager(parameters, schReg); mClient = new DefaultHttpClient(tsccm, parameters); mConsumer = new CommonsHttpOAuthConsumer(OAuthKeys.TWITTER_CONSUMER_KEY, OAuthKeys.TWITTER_CONSUMER_SECRET); loadSavedKeys(sp); }
From source file:de.codesourcery.eve.skills.market.impl.EveCentralClient.java
/** * Must <b>only</b> be called while {@link #CLIENT_LOCK} * is being held.//from w ww .j a va 2 s . c o m * * @return */ protected ThreadSafeClientConnManager getConnectionManager() { if (connectionManager == null) { // Create and initialize HTTP parameters final HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 30); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); } return connectionManager; }
From source file:com.mymed.android.myjam.controller.CallManager.java
/** * Private constructor.//from www .ja v a2 s .c om * * @throws KeyManagementException * @throws NoSuchAlgorithmException * @throws KeyStoreException * @throws UnrecoverableKeyException */ private CallManager(Context context) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException { // Create and initialize HTTP parameters HttpParams httpParams = new BasicHttpParams(); /** Sets the version of the HTTP protocol to 1.1 */ HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); /** Sets a timeout until a request is established. [ms] */ HttpConnectionParams.setConnectionTimeout(httpParams, 10000); /** Sets a timeout for waiting for data. [ms] */ HttpConnectionParams.setSoTimeout(httpParams, 5000); /** Set the maximum number of total connections. */ ConnManagerParams.setMaxTotalConnections(httpParams, lpPoolSize + 1); /** Set the maximum number of connections per route. */ ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(lpPoolSize + 1)); SchemeRegistry schemeRegistry = createSchemeRegistry(context); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpClient = new DefaultHttpClient(connManager, httpParams); lowPriorityPool = Executors.newFixedThreadPool(lpPoolSize); // highPriorityPool = Executors.newFixedThreadPool(hpPoolSize); Log.i(TAG, "Executor pool created"); }
From source file:cn.xdf.thinkutils.http.HttpUtils.java
public HttpUtils(int connTimeout, String userAgent) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setTimeout(params, connTimeout); HttpConnectionParams.setSoTimeout(params, connTimeout); HttpConnectionParams.setConnectionTimeout(params, connTimeout); if (TextUtils.isEmpty(userAgent)) { userAgent = OtherUtils.getUserAgent(null); }/*from w w w.j a v a 2 s. c om*/ HttpProtocolParams.setUserAgent(params, userAgent); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(10)); ConnManagerParams.setMaxTotalConnections(params, 10); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 1024 * 8); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", DefaultSSLSocketFactory.getSocketFactory(), 443)); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_RETRY_TIMES)); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(org.apache.http.HttpRequest httpRequest, HttpContext httpContext) throws org.apache.http.HttpException, IOException { if (!httpRequest.containsHeader(HEADER_ACCEPT_ENCODING)) { httpRequest.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext httpContext) throws org.apache.http.HttpException, IOException { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase("gzip")) { response.setEntity(new GZipDecompressingEntity(response.getEntity())); return; } } } } }); }
From source file:org.couch4j.http.HttpConnectionManager.java
public HttpConnectionManager() { // Create and initialize HTTP parameters HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, MAX_TOTAL_CONNECTIONS); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(http);//from w w w .j a va2s. com // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); this.client = new DefaultHttpClient(cm, params); }
From source file:com.idsmanager.eagleeye.net.UploadHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { //create post http request HttpPost httpPost = new HttpPost(request.getUrl()); httpPost.setEntity(((IDsManagerMultiPartRequest) request).getEntity()); addHeaders(httpPost, additionalHeaders); addHeaders(httpPost, request.getHeaders()); onPrepareRequest(httpPost);//from w w w. ja v a 2 s. c om HttpParams httpParams = httpPost.getParams(); int timeoutMs = request.getTimeoutMs(); HttpConnectionParams.setConnectionTimeout(httpParams, 50000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); /* Register schemes, HTTP and HTTPS */ SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory sslSocketFactory; if (mIsConnectingToYourServer) { sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory(); } else { sslSocketFactory = SSLSocketFactory.getSocketFactory(); } registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sslSocketFactory, 443)); /* Make a thread safe connection manager for the client */ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParams, registry); HttpClient httpClient = new DefaultHttpClient(manager, httpParams); return httpClient.execute(httpPost); }