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:uk.co.unclealex.googleauth.ApacheHttpTransport.java
/** * Creates a new instance of the Apache HTTP client that is used by the * {@link #ApacheHttpTransport()} constructor. * * <p>// w w w .ja v a 2 s. c o m * Use this constructor if you want to customize the default Apache HTTP client. Settings: * </p> * <ul> * <li>The client connection manager is set to {@link ThreadSafeClientConnManager}.</li> * <li>The socket buffer size is set to 8192 using * {@link HttpConnectionParams#setSocketBufferSize}.</li> * <li><The retry mechanism is turned off by setting * {@code new DefaultHttpRequestRetryHandler(0, false)}</li> * </ul> * * @return new instance of the Apache HTTP client * @since 1.6 */ public static DefaultHttpClient newDefaultHttpClient() { // 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. HttpParams params = new BasicHttpParams(); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setSocketBufferSize(params, 8192); ConnManagerParams.setMaxTotalConnections(params, 200); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20)); // See http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, params); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return defaultHttpClient; }
From source file:org.andstatus.app.net.HttpApacheUtils.java
static HttpClient getHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); // This is done to get rid of the "javax.net.ssl.SSLException: hostname in certificate didn't match" error // See e.g. http://stackoverflow.com/questions/8839541/hostname-in-certificate-didnt-match socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", socketFactory, 443)); HttpParams params = getHttpParams(); ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(clientConnectionManager, params); }
From source file:com.phonty.improved.Rates.java
public void getsms(String country, String url) { APIURL = url;/*from w w w . j a v a2 s . c o m*/ httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); 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", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); type = "SMS:"; get(country); }
From source file:cz.tomas.StockAnalyze.Application.java
@Override public Object getSystemService(String name) { if (UPDATE_SCHEDULER_SERVICE.equals(name)) { return this.scheduler; } else if (DATA_MANAGER_SERVICE.equals(name)) { return this.dataManager; } else if (PORTFOLIO_SERVICE.equals(name)) { if (this.portfolio == null) { this.portfolio = new Portfolio(this); }/*from w w w . j av a 2 s . c o m*/ return portfolio; } else if (HTTP_CLIENT_SERVICE.equals(name)) { if (sDefaultHttpClient == null) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, false); ConnManagerParams.setMaxTotalConnections(params, 10); HttpConnectionParams.setConnectionTimeout(params, 10 * 1000); HttpConnectionParams.setSoTimeout(params, 10 * 1000); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); sDefaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schReg), params); } return sDefaultHttpClient; } else if (RSS_SERVICE.equals(name)) { if (this.rss == null) { this.rss = new Rss(this); } return this.rss; } else if (REST_SERVICE.equals(name)) { if (this.restInfrastructure == null) { this.restInfrastructure = new Infrastructure(this); } return this.restInfrastructure; } else if (JOURNAL_SERVICE.equals(name)) { if (this.journal == null) { this.journal = new Journal(this); } return this.journal; } return super.getSystemService(name); }
From source file:com.yp.enstudy.http.FinalHttp.java
public FinalHttp() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, 10); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); 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); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); // HTTPClient?? httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); }// www .j ava 2 s .co m for (String header : clientHeaderMap.keySet()) { request.addHeader(header, clientHeaderMap.get(header)); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { 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(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(maxRetries)); clientHeaderMap = new HashMap<String, String>(); }
From source file:com.kurento.kmf.content.internal.StreamingProxy.java
/** * After constructor method; it created the HTTP client using configuration * parameters {@link ContentApiConfiguration}. * /* w w w . ja v a 2s. c o m*/ * @see ContentApiConfiguration */ @PostConstruct public void afterPropertiesSet() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, configuration.getProxyConnectionTimeout()); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, configuration.getProxySocketTimeout()); // Thread-safe configuration (using PoolingClientConnectionManager) SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(configuration.getProxyMaxConnections()); cm.setDefaultMaxPerRoute(configuration.getProxyMaxConnectionsPerRoute()); httpClient = new DefaultHttpClient(cm, params); }
From source file:com.up.testjavasdkdemo.ssltest.Http.java
public Http(Context context) { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, 10); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); 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); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); }// ww w. ja v a2 s . c om for (String header : clientHeaderMap.keySet()) { request.addHeader(header, clientHeaderMap.get(header)); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { 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(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); clientHeaderMap = new HashMap<String, String>(); }
From source file:com.my.cloudcontact.http.FinalHttp.java
public FinalHttp() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, 10); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); 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); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); }// w w w . j ava2 s . com // initClientHeader(requestHeader); // for (String header : clientHeaderMap.keySet()) { // request.addHeader(header, clientHeaderMap.get(header)); // } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { 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(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(maxRetries)); clientHeaderMap = new HashMap<String, String>(); }
From source file:com.phonty.improved.Calls.java
public void getsms(String country, String url) { APIURL = url;/*from ww w .jav a 2 s . c o m*/ httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); 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", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); type = "SMS:"; get(country); }
From source file:com.mygame.myfellowship.http.FinalHttp.java
public FinalHttp() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, 10); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); 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); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.setParams(httpParams);/*from w w w .j av a 2 s . c o m*/ httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } // initClientHeader(requestHeader); // for (String header : clientHeaderMap.keySet()) { // request.addHeader(header, clientHeaderMap.get(header)); // } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { 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(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(maxRetries)); clientHeaderMap = new HashMap<String, String>(); }