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:cn.edu.szjm.support.http.IgnitedHttp.java
protected void setupHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) { schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } else {/*from w w w . j av a 2s. c o m*/ // used to work around a bug in Android 1.6: // http://code.google.com/p/android/issues/detail?id=1946 // TODO: is there a less rigorous workaround for this? schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); } ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpClient = new DefaultHttpClient(cm, httpParams); }
From source file:com.hoccer.api.CloudService.java
protected void setupHttpClient() { LOG.info("setting up http client"); BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParams, 70 * 1000); HttpConnectionParams.setConnectionTimeout(httpParams, 10 * 1000); ConnManagerParams.setMaxTotalConnections(httpParams, 200); ConnPerRoute connPerRoute = new ConnPerRouteBean(400); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute); 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); // ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, // HttpClientWithKeystore.getSchemeRegistry()); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, "utf-8"); mHttpClient = new HttpClientWithKeystore(cm, httpParams); mHttpClient.getParams().setParameter("http.useragent", mConfig.getApplicationName()); mHttpClient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); mHttpClient.setReuseStrategy(new NoConnectionReuseStrategy()); }
From source file:com.wso2telco.gsma.shorten.BitlyUrlShorten.java
/** * Gets the new http client./* w w w .ja va 2 s . c o m*/ * * @return the new http client */ @SuppressWarnings("deprecation") public CloseableHttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); org.apache.http.conn.ssl.SSLSocketFactory sf = new SSLSocket(trustStore); sf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.phodev.http.tools.ConnectionHelper.java
private ConnectionHelper() { HttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(httpParams, MAX_TOTAL_CONNECTIONS); ConnPerRouteBean connPerRoute = new ConnPerRouteBean(MAX_CONNECTIONS_PER_HOST); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(httpParams, false); SchemeRegistry reg = new SchemeRegistry(); reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(httpParams, reg); HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS); HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS); HttpClientParams.setCookiePolicy(httpParams, CookiePolicy.BROWSER_COMPATIBILITY); httpClient = new DefaultHttpClient(connectionManager, httpParams); }
From source file:org.transdroid.daemon.util.HttpHelper.java
/** * Creates a standard Apache HttpClient that is thread safe, supports different SSL auth methods and basic * authentication//from w w w.j a v a 2 s. c o m * @param sslTrustAll Whether to trust all SSL certificates * @param sslTrustkey A specific SSL key to accept exclusively * @param timeout The connection timeout for all requests * @param authAddress The authentication domain address * @param authPort The authentication domain port number * @return An HttpClient that should be stored locally and reused for every new request * @throws DaemonException Thrown when information (such as username/password) is missing */ public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password, boolean sslTrustAll, String sslTrustkey, int timeout, String authAddress, int authPort) throws DaemonException { // Register http and https sockets SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); SocketFactory https_socket = sslTrustAll ? new FakeSocketFactory() : sslTrustkey != null ? new FakeSocketFactory(sslTrustkey) : SSLSocketFactory.getSocketFactory(); registry.register(new Scheme("https", https_socket, 443)); // Standard parameters HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, timeout); HttpConnectionParams.setSoTimeout(httpparams, timeout); if (userAgent != null) { HttpProtocolParams.setUserAgent(httpparams, userAgent); } DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams); // Authentication credentials if (userBasicAuth) { if (username == null || password == null) { throw new DaemonException(ExceptionType.AuthenticationFailure, "No username or password was provided while we hadauthentication enabled"); } httpclient.getCredentialsProvider().setCredentials( new AuthScope(authAddress, authPort, AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); } return httpclient; }
From source file:com.taqueue.connection.QueueConnectionManager.java
/** * Sends a POST to the queue with the parameters nvps, returns the result. * @param nvps the NameValuePair of parameters to be sent to the queue server * @return ConnectionResult containing the status code for the attempt and the message returned * message will be null iff the status is not OK */// w w w.ja v a 2 s. c o m private ConnectionResult sendMessage(List<NameValuePair> nvps) { ConnectionResult res = new ConnectionResult(); //default to OK, we'll change in the event of an error res.status = ConnectionStatus.OK; HttpPost post = new HttpPost(HOST + PATH); //DefaultHttpClient client = new DefaultHttpClient(); //set up the timeout HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT); // set up the connection manager if needed if (manager == null) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); manager = new ThreadSafeClientConnManager(httpParams, registry); } DefaultHttpClient client = new DefaultHttpClient(manager, httpParams); try { //set up our POST values post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); //send it along ResponseHandler<String> handler = new BasicResponseHandler(); connectionWatcher watcher = new connectionWatcher(post); Thread t = new Thread(watcher); t.start(); res.message = client.execute(post, handler); watcher.finished(); //and clean up //if any exceptions are thrown return a connection error result } catch (Exception e) { res.status = ConnectionStatus.CONNECTION_ERROR; res.message = null; } finally { post.abort(); } return res; }
From source file:com.ctctlabs.ctctwsjavalib.CTCTConnection.java
public CTCTConnection() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpclient = new DefaultHttpClient(cm, params); }
From source file:foam.littlej.android.app.net.MainHttpClient.java
public MainHttpClient(Context context) { this.context = context; httpParameters = new BasicHttpParams(); httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1); httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1)); httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters, "utf8"); // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme try {// w ww. j av a2s. c o m schemeRegistry.register(new Scheme("https", new TrustedSocketFactory(Preferences.domain, false), 443)); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters, schemeRegistry), httpParameters); httpClient.setParams(httpParameters); }
From source file:HybridIT.com.fourspaces.couchdb.Session.java
/** * Constructor for obtaining a Session with an HTTP-AUTH username/password and (optionally) a secure connection * This isn't supported by CouchDB - you need a proxy in front to use this * @param host - hostname/* ww w . ja v a 2s . c om*/ * @param port - port to use * @param user - username * @param pass - password * @param secure - use an SSL connection? */ public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure) { this.host = host; this.port = port; this.user = user; this.pass = pass; this.usesAuth = usesAuth; this.secure = secure; httpParams = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); DefaultHttpClient defaultClient = new DefaultHttpClient(connManager, httpParams); if (user != null) { defaultClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass)); } this.httpClient = defaultClient; setUserAgent("couchdb4j"); setSocketTimeout((30 * 1000)); setConnectionTimeout((15 * 1000)); }
From source file:org.fourthline.cling.transport.impl.apache.StreamClientImpl.java
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; HttpProtocolParams.setContentCharset(globalParams, getConfiguration().getContentCharset()); HttpProtocolParams.setUseExpectContinue(globalParams, false); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking HttpConnectionParams.setConnectionTimeout(globalParams, (getConfiguration().getTimeoutSeconds() + 5) * 1000); HttpConnectionParams.setSoTimeout(globalParams, (getConfiguration().getTimeoutSeconds() + 5) * 1000); HttpConnectionParams.setStaleCheckingEnabled(globalParams, getConfiguration().getStaleCheckingEnabled()); if (getConfiguration().getSocketBufferSize() != -1) HttpConnectionParams.setSocketBufferSize(globalParams, getConfiguration().getSocketBufferSize()); // Only register 80, not 443 and SSL SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); clientConnectionManager = new ThreadSafeClientConnManager(globalParams, registry); //clientConnectionManager.setMaxTotal(getConfiguration().getMaxTotalConnections()); //clientConnectionManager.setDefaultMaxPerRoute(getConfiguration().getMaxTotalPerRoute()); httpClient = new DefaultHttpClient(clientConnectionManager, globalParams); if (getConfiguration().getRequestRetryCount() != -1) { httpClient.setHttpRequestRetryHandler( new DefaultHttpRequestRetryHandler(getConfiguration().getRequestRetryCount(), false)); }/*from w w w . j a va 2 s. c o m*/ }