List of usage examples for org.apache.http.conn.ssl SSLSocketFactory getSocketFactory
public static SSLSocketFactory getSocketFactory() throws SSLInitializationException
cacerts
file in the security properties directory). From source file:com.nanocrawler.fetcher.PageFetcher.java
public PageFetcher(CrawlConfig config) { this.config = config; HttpParams params = new BasicHttpParams(); HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params); paramsBean.setVersion(HttpVersion.HTTP_1_1); paramsBean.setContentCharset("UTF-8"); paramsBean.setUseExpectContinue(false); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgentString()); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSocketTimeout()); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout()); params.setBooleanParameter("http.protocol.handle-redirects", false); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); if (config.isIncludeHttpsPages()) { schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); }// ww w .j a v a2 s.c o m connectionManager = new PoolingClientConnectionManager(schemeRegistry); connectionManager.setMaxTotal(config.getMaxTotalConnections()); connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerHost()); httpClient = new DefaultHttpClient(connectionManager, params); }
From source file:com.louding.frame.http.download.SimpleDownloader.java
/** * ?httpClient/* w ww . java2 s. com*/ */ private void initHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, config.timeOut); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(config.maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, config.maxConnections); HttpConnectionParams.setSoTimeout(httpParams, config.timeOut); HttpConnectionParams.setConnectionTimeout(httpParams, config.timeOut); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, config.socketBuffer); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, "KJLibrary"); 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); context = new SyncBasicHttpContext(new BasicHttpContext()); client = new DefaultHttpClient(cm, httpParams); client.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } for (Entry<String, String> entry : config.httpHeader.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase("gzip")) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); client.setHttpRequestRetryHandler(new RetryHandler(config.timeOut)); }
From source file:org.onsteroids.eve.api.connector.http.PooledHttpApiConnection.java
/** * Initializses and configures the http client connection pool. *//*from w ww . j a v a 2 s.c o m*/ private void initializeHttpClient() { LOG.debug("Configuring the HttpClientPool with a maximum of {} connections", maxConnections); HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxConnections); ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxConnections); HttpHost serverHost = new HttpHost(serverUri.getHost(), serverUri.getPort()); connPerRoute.setMaxForRoute(new HttpRoute(serverHost), maxConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(cm, params); }
From source file:cn.com.zzwfang.http.HttpClient.java
/** * Cookie/*from w w w. j ava 2s . co m*/ */ // private PersistentCookieStore cookieStore; public HttpClient(Context context) { if (httpClient != null) { return; } // Log.i("--->", "HttpClient ?httpClient-------------"); BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, totalConnections); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, userAgent); 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); httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.setHttpRequestRetryHandler(new InnerRetryHandler(DEFAULT_MAX_RETRIES)); // cookieStore = new PersistentCookieStore(context); // httpContext.setAttribute("http.cookie-store", cookieStore); // httpClient.setCookieStore(cookieStore); }
From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4ClientFactory.java
private void createClient() { BasicHttpParams httpParams = new BasicHttpParams(); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeoutMs); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeoutMs); HttpClientParams.setRedirecting(httpParams, allowRedirects); HttpClientParams.setConnectionManagerTimeout(httpParams, connectionManagerTimeoutMs); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry); connectionManager.setMaxTotal(maxConnections); connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute); DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams); this.client = new HttpClient4Client(httpClient); }
From source file:org.codelibs.empros.agent.operation.rest.RestApiOperation.java
public RestApiOperation() { url = PropertiesUtil.getAsString(EMPROSAPI_PROPERTIES, "emprosUrl", null); if (StringUtil.isBlank(url)) { throw new EmprosSystemException("emprosUrl is empty."); }/*from w w w .ja va 2s .co m*/ eventCapacity = PropertiesUtil.getAsInt(EMPROSAPI_PROPERTIES, "eventCapacity", 100); requestInterval = PropertiesUtil.getAsInt(EMPROSAPI_PROPERTIES, "requestInterval", 100); maxRetryCount = PropertiesUtil.getAsInt(EMPROSAPI_PROPERTIES, "maxRetryCount", 5); apiMonitorInterval = PropertiesUtil.getAsLong(EMPROSAPI_PROPERTIES, "apiMonitorInterval", 1 * 60 * 1000); final long connectionCheckInterval = PropertiesUtil.getAsLong(EMPROSAPI_PROPERTIES, "connectionCheckInterval", 5000); final long idleConnectionTimeout = PropertiesUtil.getAsLong(EMPROSAPI_PROPERTIES, "idleConnectionTimeout", 60 * 1000); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); final ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(schemeRegistry, 5, TimeUnit.MINUTES); httpClient = new DefaultHttpClient(clientConnectionManager); HttpParams httpParams = httpClient.getParams(); // TODO auth HttpConnectionParams.setConnectionTimeout(httpParams, 10 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000); connectionMonitor = new ConnectionMonitor(clientConnectionManager, connectionCheckInterval, idleConnectionTimeout); connectionMonitor.setDaemon(true); connectionMonitor.start(); apiMonitor = new ApiMonitor(); apiMonitorTimer = new Timer(); apiMonitorTimer.schedule(apiMonitor, 0, apiMonitorInterval); }
From source file:com.lightbox.android.network.HttpHelper.java
/** * Create an HttpClient./* w ww . j a v a2s . com*/ * @return a properly set HttpClient */ private static DefaultHttpClient createHttpClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme(STRING_HTTP, PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme(STRING_HTTPS, SSLSocketFactory.getSocketFactory(), 443)); HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT); ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params, SOCKET_BUFFER_SIZE); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, String.format(USER_AGENT_FORMAT_STRING, AndroidUtils.getApplicationLabel(), AndroidUtils.getVersionCode(), android.os.Build.VERSION.RELEASE, android.os.Build.MODEL)); DefaultHttpClient client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); enableGzipCompression(client); return client; }
From source file:com.chatsdk.kenai.jbosh.ApacheHTTPSender.java
private synchronized HttpClient initHttpClient(final BOSHClientConfig config) { // Create and initialize HTTP parameters HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(params, false); if (config != null && config.getProxyHost() != null && config.getProxyPort() != 0) { HttpHost proxy = new HttpHost(config.getProxyHost(), config.getProxyPort()); params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }//from w w w. j a v a 2 s .c om // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslFactory = SSLSocketFactory.getSocketFactory(); sslFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslFactory, 443)); // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(cm, params); }
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); }