本文整理汇总了Java中org.apache.http.conn.scheme.SocketFactory类的典型用法代码示例。如果您正苦于以下问题:Java SocketFactory类的具体用法?Java SocketFactory怎么用?Java SocketFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SocketFactory类属于org.apache.http.conn.scheme包,在下文中一共展示了SocketFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Performs general setup.
* This should be called only once.
*/
private final static void setup() {
// Register the "http" and "https" protocol schemes, they are
// required by the default operator to look up socket factories.
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
sf = SSLSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("https", sf, 80));
// Prepare parameters.
// Since this example doesn't use the full core framework,
// only few parameters are actually required.
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(params, false);
defaultParameters = params;
}
示例2: setup
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Performs general setup.
* This should be called only once.
*/
private final static void setup() {
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
// Prepare parameters.
// Since this example doesn't use the full core framework,
// only few parameters are actually required.
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(params, false);
defaultParameters = params;
}
示例3: initHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* 微信自定义信任管理器X509TrustManager
* @param httpclient
* @return
*/
private static HttpClient initHttpClient(HttpClient httpclient) {
try {
TrustManager[] tm = { new MyX509TrustManager() };
// 取得SSL的SSLContext实例
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
// 初始化SSLContext
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SocketFactory ssf = (SocketFactory) sslContext.getSocketFactory();
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 8443));
HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
httpclient = new DefaultHttpClient(ccm, params);
} catch (Exception ex) {
Exceptions.printException(ex);
}
return httpclient;
}
示例4: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public static final DefaultHttpClient createHttpClient() {
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// Set some client http client parameter defaults.
final HttpParams httpParams = createHttpParams();
HttpClientParams.setRedirecting(httpParams, false);
final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
supportedSchemes);
return new DefaultHttpClient(ccm, httpParams);
}
示例5: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public static final DefaultHttpClient createHttpClient() {
// Shamelessly cribbed from AndroidHttpClient
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);
// Default connection and socket timeout of 10 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
final ClientConnectionManager ccm = new ThreadSafeClientConnManager(params,
supportedSchemes);
return new DefaultHttpClient(ccm, params);
}
示例6: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public static final DefaultHttpClient createHttpClient() {
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
// Set some client http client parameter defaults.
final HttpParams httpParams = createHttpParams();
HttpClientParams.setRedirecting(httpParams, false);
final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
supportedSchemes);
return new DefaultHttpClient(ccm, httpParams);
}
示例7: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* 获取HttpClient,自签名的证书,如果想做签名参考AuthSSLProtocolSocketFactory类
* @return
*/
public DefaultHttpClient createHttpClient(){
BasicHttpParams httpParams = getHttpParams();
if(mIsOpenEasySSL){
// 支持https的 SSL自签名的实现类
EasySSLProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
SchemeRegistry supportedSchemes = new SchemeRegistry();
SocketFactory socketFactory = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", socketFactory, 80));
supportedSchemes.register(new Scheme("https",easySSLProtocolSocketFactory, 443));
//安全的ThreadSafeClientConnManager,否则不能用单例的HttpClient
ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(
httpParams, supportedSchemes);
//取得HttpClient ThreadSafeClientConnManager
mHttpClient = new DefaultHttpClient(connectionManager, httpParams);
}else{
//线程安全的HttpClient
mHttpClient = new DefaultHttpClient(httpParams);
}
//自动重试
mHttpClient.setHttpRequestRetryHandler(mRequestRetryHandler);
mHttpClient.setCookieStore(mCookieStore);
return mHttpClient;
}
示例8: GoogleHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
private GoogleHttpClient(Context paramContext, String paramString, boolean paramBoolean)
{
String str1 = paramString + " (" + Build.DEVICE + " " + Build.ID + ")";
this.mClient = AndroidHttpClient.newInstance(str1 + "; gzip", paramContext);
this.mCookieSourceApplier = new CookieSourceApplier(this.mClient, null, (byte)0);
this.mResolver = paramContext.getContentResolver();
this.mAppName = paramString;
SchemeRegistry localSchemeRegistry = getConnectionManager().getSchemeRegistry();
Iterator localIterator = localSchemeRegistry.getSchemeNames().iterator();
if (localIterator.hasNext())
{
String str2 = (String)localIterator.next();
Scheme localScheme = localSchemeRegistry.unregister(str2);
SocketFactory localSocketFactory = localScheme.getSocketFactory();
if ((localSocketFactory instanceof LayeredSocketFactory)) {}
for (Object localObject = new WrappedLayeredSocketFactory((LayeredSocketFactory)localSocketFactory, (byte)0);; localObject = new WrappedSocketFactory(localSocketFactory, (byte)0))
{
localSchemeRegistry.register(new Scheme(str2, (SocketFactory)localObject, localScheme.getDefaultPort()));
break;
}
}
}
示例9: createDefaultHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
public static DefaultHttpClient createDefaultHttpClient(boolean threadSafe,
boolean enableRedirect) {
HttpParams httpParams = new BasicHttpParams();
HttpClientParams.setRedirecting(httpParams, enableRedirect);
setTimeout(httpParams, Constants.HTTP_REQUEST_TIME_OUT * 1000);
if (threadSafe) {
SchemeRegistry supportedSchemes = new SchemeRegistry();
SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(
httpParams, supportedSchemes);
return new DefaultHttpClient(ccm, httpParams);
} else {
return new DefaultHttpClient(httpParams);
}
}
示例10: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* 获取HttpClient,自签名的证书,如果想做签名参考AuthSSLProtocolSocketFactory类
* @param httpParams
* @return
*/
public DefaultHttpClient createHttpClient(){
BasicHttpParams httpParams = getHttpParams();
if(mIsOpenEasySSL){
// 支持https的 SSL自签名的实现类
EasySSLProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
SchemeRegistry supportedSchemes = new SchemeRegistry();
SocketFactory socketFactory = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", socketFactory, 80));
supportedSchemes.register(new Scheme("https",easySSLProtocolSocketFactory, 443));
//安全的ThreadSafeClientConnManager,否则不能用单例的HttpClient
ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(
httpParams, supportedSchemes);
//取得HttpClient ThreadSafeClientConnManager
mHttpClient = new DefaultHttpClient(connectionManager, httpParams);
}else{
//线程安全的HttpClient
mHttpClient = new DefaultHttpClient(httpParams);
}
//自动重试
mHttpClient.setHttpRequestRetryHandler(mRequestRetryHandler);
mHttpClient.setCookieStore(mCookieStore);
return mHttpClient;
}
示例11: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public static final DefaultHttpClient createHttpClient(Context mContext) {
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// Set some client http client parameter defaults.
final HttpParams httpParams = createHttpParams(mContext);
HttpClientParams.setRedirecting(httpParams, false);
final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
supportedSchemes);
return new DefaultHttpClient(ccm, httpParams);
}
示例12: getSSLHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
private HttpClient getSSLHttpClient() throws Throwable {
KeyStore instance = KeyStore.getInstance(KeyStore.getDefaultType());
instance.load(null, null);
SocketFactory sSLSocketFactoryEx = new SSLSocketFactoryEx(instance);
sSLSocketFactoryEx.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(b.a, sSLSocketFactoryEx, WebSocket.DEFAULT_WSS_PORT));
return new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams,
schemeRegistry), basicHttpParams);
}
示例13: a
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
public static b a() {
if (b == null) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
ConnManagerParams.setTimeout(basicHttpParams, 1000);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, a);
try {
SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(scheme);
schemeRegistry.register(scheme2);
b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
} catch (Exception e) {
b = new b(basicHttpParams);
}
}
return b;
}
示例14: FlowzrSyncTask
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
public FlowzrSyncTask(Context context) {
this.context=context;
BasicHttpParams params = new BasicHttpParams();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
schemeRegistry.register(new Scheme("https", (SocketFactory) sslSocketFactory, 443));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
this.http_client = new DefaultHttpClient(cm, params);
this.dba=new DatabaseAdapter(context);
}
示例15: createHttpClient
import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public final DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setUseExpectContinue(params, true);
// 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);
// Default connection and socket timeout of 30 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10*1000);
HttpConnectionParams.setSoTimeout(params, 20*1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setTimeout(params, 5 * 1000);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(50));
ConnManagerParams.setMaxTotalConnections(params, 200);
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(params,
supportedSchemes);
DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params);
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));
return httpClient;
}