Java Code Examples for org.apache.http.conn.scheme.PlainSocketFactory#getSocketFactory()
The following examples show how to use
org.apache.http.conn.scheme.PlainSocketFactory#getSocketFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpService.java From oxAuth with MIT License | 7 votes |
public HttpClient getHttpsClientTrustAll() { try { SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){ @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, new AllowAllHostnameVerifier()); PlainSocketFactory psf = PlainSocketFactory.getSocketFactory(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, psf)); registry.register(new Scheme("https", 443, sf)); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); return new DefaultHttpClient(ccm); } catch (Exception ex) { log.error("Failed to create TrustAll https client", ex); return new DefaultHttpClient(); } }
Example 2
Source File: MyHtttpClient.java From Huochexing12306 with Apache License 2.0 | 6 votes |
public synchronized static DefaultHttpClient getHttpClient() { try { HttpParams params = new BasicHttpParams(); // 设置一些基本参数 HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // 超时设置 // 从连接池中取连接的超时时间 ConnManagerParams.setTimeout(params, 10000); // 连接超时 HttpConnectionParams.setConnectionTimeout(params, 10000); // 请求超时 HttpConnectionParams.setSoTimeout(params, 30000); SchemeRegistry registry = new SchemeRegistry(); Scheme sch1 = new Scheme("http", PlainSocketFactory .getSocketFactory(), 80); registry.register(sch1); // 使用线程安全的连接管理来创建HttpClient ClientConnectionManager conMgr = new ThreadSafeClientConnManager( params, registry); mHttpClient = new DefaultHttpClient(conMgr, params); } catch (Exception e) { e.printStackTrace(); } return mHttpClient; }
Example 3
Source File: HttpLoadTestClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public void run() { SchemeRegistry supportedSchemes = new SchemeRegistry(); SocketFactory sf = PlainSocketFactory.getSocketFactory(); supportedSchemes.register(new Scheme("http", sf, 80)); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(supportedSchemes); connManager.setDefaultMaxPerRoute(1000); DefaultHttpClient client = new DefaultHttpClient(connManager); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 30000); HttpConnectionParams.setSoTimeout(params, 30000); client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { public boolean retryRequest(IOException e, int i, HttpContext httpContext) { return false; } }); //test API call long t1 = System.currentTimeMillis(); testEndpoint(client,apiEndpoint); long t2 = System.currentTimeMillis(); timeElapsedForAPICall = t2 - t1; }
Example 4
Source File: AntennapodHttpClient.java From AntennaPodSP with MIT License | 5 votes |
private static SchemeRegistry prepareSchemeRegistry() { SchemeRegistry sr = new SchemeRegistry(); Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); sr.register(http); Scheme https = new Scheme("https", SSLSocketFactory.getSocketFactory(), 443); sr.register(https); return sr; }
Example 5
Source File: SchemeFactory.java From cloudhopper-commons with Apache License 2.0 | 4 votes |
static public Scheme createHttpScheme() { return new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); }