use of org.apache.http.conn.ClientConnectionManager in project XobotOS by xamarin.
the class AndroidHttpClient method newInstance.
/**
* Create a new HttpClient with reasonable defaults (which you can update).
*
* @param userAgent to report in your HTTP requests
* @param context to use for caching SSL sessions (may be null for no caching)
* @return AndroidHttpClient for you to use for all your requests.
*/
public static AndroidHttpClient newInstance(String userAgent, Context context) {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
// Use a session cache for SSL sockets
SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, userAgent);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new AndroidHttpClient(manager, params);
}
use of org.apache.http.conn.ClientConnectionManager in project XobotOS by xamarin.
the class DefaultHttpClient method createClientConnectionManager.
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connManager = null;
HttpParams params = getParams();
ClientConnectionManagerFactory factory = null;
// Try first getting the factory directly as an object.
factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
if (factory == null) {
// then try getting its class name.
String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
if (className != null) {
try {
Class<?> clazz = Class.forName(className);
factory = (ClientConnectionManagerFactory) clazz.newInstance();
} catch (ClassNotFoundException ex) {
throw new IllegalStateException("Invalid class name: " + className);
} catch (IllegalAccessException ex) {
throw new IllegalAccessError(ex.getMessage());
} catch (InstantiationException ex) {
throw new InstantiationError(ex.getMessage());
}
}
}
if (factory != null) {
connManager = factory.newInstance(params, registry);
} else {
connManager = new SingleClientConnManager(getParams(), registry);
}
return connManager;
}
use of org.apache.http.conn.ClientConnectionManager in project newsrob by marianokamp.
the class CountingInputStream method newInstance.
public static NewsRobHttpClient newInstance(boolean followRedirects, Context ctx) {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setStaleCheckingEnabled(params, true);
HttpConnectionParams.setConnectionTimeout(params, 45 * 1000);
HttpConnectionParams.setSoTimeout(params, 45 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// HttpConnectionParams.setTcpNoDelay(params, true);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
// HttpClientParams.setRedirecting(params, false);
HttpClientParams.setRedirecting(params, followRedirects);
if (followRedirects)
params.setIntParameter(ClientPNames.MAX_REDIRECTS, 10);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, USER_AGENT);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new NewsRobHttpClient(manager, params, ctx);
}
use of org.apache.http.conn.ClientConnectionManager in project robovm by robovm.
the class SingleClientConnManager method releaseConnection.
// non-javadoc, see interface ClientConnectionManager
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
assertStillUp();
if (!(conn instanceof ConnAdapter)) {
throw new IllegalArgumentException("Connection class mismatch, " + "connection not obtained from this manager.");
}
if (log.isDebugEnabled()) {
log.debug("Releasing connection " + conn);
}
ConnAdapter sca = (ConnAdapter) conn;
if (sca.poolEntry == null)
// already released
return;
ClientConnectionManager manager = sca.getManager();
if (manager != null && manager != this) {
throw new IllegalArgumentException("Connection not obtained from this manager.");
}
try {
// BEGIN android-changed
// When recycling a Socket, we un-tag it to avoid collecting
// statistics from future users.
final Socket socket = uniquePoolEntry.connection.getSocket();
if (socket != null) {
SocketTagger.get().untag(socket);
}
// make sure that the response has been read completely
if (sca.isOpen() && (this.alwaysShutDown || !sca.isMarkedReusable())) {
if (log.isDebugEnabled()) {
log.debug("Released connection open but not reusable.");
}
// make sure this connection will not be re-used
// we might have gotten here because of a shutdown trigger
// shutdown of the adapter also clears the tracked route
sca.shutdown();
}
} catch (IOException iox) {
//@@@ log as warning? let pass?
if (log.isDebugEnabled())
log.debug("Exception shutting down released connection.", iox);
} finally {
sca.detach();
managedConn = null;
lastReleaseTime = System.currentTimeMillis();
if (validDuration > 0)
connectionExpiresTime = timeUnit.toMillis(validDuration) + lastReleaseTime;
else
connectionExpiresTime = Long.MAX_VALUE;
}
}
use of org.apache.http.conn.ClientConnectionManager in project robovm by robovm.
the class DefaultHttpClient method createClientConnectionManager.
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connManager = null;
HttpParams params = getParams();
ClientConnectionManagerFactory factory = null;
// Try first getting the factory directly as an object.
factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
if (factory == null) {
// then try getting its class name.
String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
if (className != null) {
try {
Class<?> clazz = Class.forName(className);
factory = (ClientConnectionManagerFactory) clazz.newInstance();
} catch (ClassNotFoundException ex) {
throw new IllegalStateException("Invalid class name: " + className);
} catch (IllegalAccessException ex) {
throw new IllegalAccessError(ex.getMessage());
} catch (InstantiationException ex) {
throw new InstantiationError(ex.getMessage());
}
}
}
if (factory != null) {
connManager = factory.newInstance(params, registry);
} else {
connManager = new SingleClientConnManager(getParams(), registry);
}
return connManager;
}
Aggregations