use of org.apache.http.conn.scheme.SchemeRegistry in project SmartAndroidSource by jaychou2012.
the class AsyncHttpClient method getDefaultSchemeRegistry.
/**
* Returns default instance of SchemeRegistry
*
* @param fixNoHttpResponseException
* Whether to fix or not issue, by ommiting SSL verification
* @param httpPort
* HTTP port to be used, must be greater than 0
* @param httpsPort
* HTTPS port to be used, must be greater than 0
*/
private static SchemeRegistry getDefaultSchemeRegistry(boolean fixNoHttpResponseException, int httpPort, int httpsPort) {
if (fixNoHttpResponseException) {
Log.d(LOG_TAG, "Beware! Using the fix is insecure, as it doesn't verify SSL certificates.");
}
if (httpPort < 1) {
httpPort = 80;
Log.d(LOG_TAG, "Invalid HTTP port number specified, defaulting to 80");
}
if (httpsPort < 1) {
httpsPort = 443;
Log.d(LOG_TAG, "Invalid HTTPS port number specified, defaulting to 443");
}
// Fix to SSL flaw in API < ICS
// See https://code.google.com/p/android/issues/detail?id=13117
SSLSocketFactory sslSocketFactory;
if (fixNoHttpResponseException)
sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory();
else
sslSocketFactory = SSLSocketFactory.getSocketFactory();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort));
schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort));
return schemeRegistry;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project musicbrainz-android by jdamcd.
the class HttpClient method setupSchemeRegistry.
private static SchemeRegistry setupSchemeRegistry() {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
return schemeRegistry;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project undertow by undertow-io.
the class TestHttpClient method setSSLContext.
public void setSSLContext(final SSLContext sslContext) {
SchemeRegistry registry = getConnectionManager().getSchemeRegistry();
registry.unregister("https");
if (DefaultServer.getHostAddress(DefaultServer.DEFAULT).equals("localhost")) {
registry.register(new Scheme("https", 443, new SSLSocketFactory(sslContext)));
registry.register(new Scheme("https", DefaultServer.getHostSSLPort("default"), new SSLSocketFactory(sslContext)));
} else {
registry.register(new Scheme("https", 443, new SSLSocketFactory(sslContext, NO_OP_VERIFIER)));
registry.register(new Scheme("https", DefaultServer.getHostSSLPort("default"), new SSLSocketFactory(sslContext, NO_OP_VERIFIER)));
}
}
use of org.apache.http.conn.scheme.SchemeRegistry in project baker-android by bakerframework.
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);
Object sessionCache = null;
// Use a session cache for SSL sockets -- Froyo only
if (null != context && null != sSslSessionCacheClass) {
Constructor<?> ct;
try {
ct = sSslSessionCacheClass.getConstructor(Context.class);
sessionCache = ct.newInstance(context);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 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));
SocketFactory sslCertificateSocketFactory = null;
if (null != sessionCache) {
Method getHttpSocketFactoryMethod;
try {
getHttpSocketFactoryMethod = SSLCertificateSocketFactory.class.getDeclaredMethod("getHttpSocketFactory", Integer.TYPE, sSslSessionCacheClass);
sslCertificateSocketFactory = (SocketFactory) getHttpSocketFactoryMethod.invoke(null, SOCKET_OPERATION_TIMEOUT, sessionCache);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null == sslCertificateSocketFactory) {
sslCertificateSocketFactory = SSLSocketFactory.getSocketFactory();
}
schemeRegistry.register(new Scheme("https", sslCertificateSocketFactory, 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.scheme.SchemeRegistry 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);
}
Aggregations