Java Code Examples for org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.

Source file: Flickr.java

  20 
vote

private void Flickr(){
  final HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,"UTF-8");
  final SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  final ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(params,registry);
  mClient=new DefaultHttpClient(manager,params);
}
 

Example 2

From project DirectMemory, under directory /server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/providers/httpclient/.

Source file: HttpClientDirectMemoryHttpClient.java

  18 
vote

public void configure(DirectMemoryClientConfiguration configuration){
  this.configuration=configuration;
  ThreadSafeClientConnManager threadSafeClientConnManager=new ThreadSafeClientConnManager();
  threadSafeClientConnManager.setDefaultMaxPerRoute(configuration.getMaxConcurentConnections());
  this.httpClient=new DefaultHttpClient(threadSafeClientConnManager);
}
 

Example 3

From project dreamDroid, under directory /src/net/reichholf/dreamdroid/helpers/.

Source file: SimpleHttpClient.java

  18 
vote

/** 
 * @return ThreadSafeClientConnManager Instance
 */
public ThreadSafeClientConnManager getEasySSLClientConnectionManager(){
  BasicHttpParams params=new BasicHttpParams();
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443));
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  return cm;
}
 

Example 4

From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/http/.

Source file: HttpClient.java

  18 
vote

/** 
 * Setup DefaultHttpClient Use ThreadSafeClientConnManager.
 */
private void prepareHttpClient(){
  if (DEBUG) {
    enableDebug();
  }
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,10);
  HttpProtocolParams.setVersion(params,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(params,schemeRegistry);
  mClient=new DefaultHttpClient(cm,params);
  mClient.addResponseInterceptor(gzipResponseIntercepter);
}
 

Example 5

From project httpcache4j, under directory /resolvers/resolvers-httpcomponents-httpclient/src/main/java/org/codehaus/httpcache4j/resolver/.

Source file: HTTPClientResponseResolver.java

  18 
vote

public static HTTPClientResponseResolver createMultithreadedInstance(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(new BasicHttpParams(),schemeRegistry);
  return new HTTPClientResponseResolver(new DefaultHttpClient(cm,new BasicHttpParams()));
}
 

Example 6

From project httpClient, under directory /ctct/src/main/java/weden/jason/qa/ctct/.

Source file: HttpConnector.java

  18 
vote

public void initialize(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory()));
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
  cm.setMaxTotal(200);
  cm.setDefaultMaxPerRoute(200);
  httpclient=new DefaultHttpClient(cm);
}
 

Example 7

From project ptest-server, under directory /src/main/java/com/mnxfst/testing/client/.

Source file: TSClientPlanResultCollectCallable.java

  18 
vote

public TSClientPlanResultCollectCallable(String hostname,int port,String uri){
  this.httpHost=new HttpHost(hostname,port);
  this.getMethod=new HttpGet(uri.toString());
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory()));
  ThreadSafeClientConnManager threadSafeClientConnectionManager=new ThreadSafeClientConnManager(schemeRegistry);
  threadSafeClientConnectionManager.setMaxTotal(20);
  threadSafeClientConnectionManager.setDefaultMaxPerRoute(20);
  this.httpClient=new DefaultHttpClient(threadSafeClientConnectionManager);
}
 

Example 8

From project ServiceFramework, under directory /src/net/csdn/modules/transport/.

Source file: DefaultHttpTransportService.java

  18 
vote

public DefaultHttpTransportService(){
  ThreadSafeClientConnManager threadSafeClientConnManager=new ThreadSafeClientConnManager();
  threadSafeClientConnManager.setDefaultMaxPerRoute(1000);
  threadSafeClientConnManager.setMaxTotal(10000);
  httpClient=new DefaultHttpClient(threadSafeClientConnManager);
}
 

Example 9

From project spring-android, under directory /spring-android-rest-template/src/main/java/org/springframework/http/client/.

Source file: HttpComponentsClientHttpRequestFactory.java

  18 
vote

/** 
 * Create a new instance of the  {@code HttpComponentsClientHttpRequestFactory} with a default {@link HttpClient}that uses a default  {@link ThreadSafeClientConnManager}.
 */
public HttpComponentsClientHttpRequestFactory(){
  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 connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  ConnManagerParams.setMaxTotalConnections(params,DEFAULT_MAX_TOTAL_CONNECTIONS);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS_PER_ROUTE));
  this.httpClient=new DefaultHttpClient(connectionManager,null);
  setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
}
 

Example 10

From project UDJ-Android-Client, under directory /src/org/klnusbaum/udj/network/.

Source file: ServerConnection.java

  18 
vote

public static DefaultHttpClient getHttpClient() throws IOException {
  if (httpClient == null) {
    SchemeRegistry schemeReg=new SchemeRegistry();
    schemeReg.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),SERVER_PORT));
    BasicHttpParams params=new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params,100);
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    HttpProtocolParams.setUseExpectContinue(params,true);
    ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(params,schemeReg);
    httpClient=new DefaultHttpClient(cm,params);
  }
  return httpClient;
}
 

Example 11

From project Vega, under directory /platform/com.subgraph.vega.http.requests/src/com/subgraph/vega/internal/http/requests/.

Source file: HttpRequestEngineFactory.java

  18 
vote

private void configureClient(HttpClient client,IHttpRequestEngineConfig config){
  final ClientConnectionManager connectionManager=client.getConnectionManager();
  if (connectionManager instanceof ThreadSafeClientConnManager) {
    ThreadSafeClientConnManager ccm=(ThreadSafeClientConnManager)connectionManager;
    ccm.setMaxTotal(config.getMaxConnections());
    ccm.setDefaultMaxPerRoute(config.getMaxConnectionsPerRoute());
  }
}
 

Example 12

From project WebproxyPortlet, under directory /src/main/java/edu/wisc/my/webproxy/beans/http/.

Source file: HttpManagerImpl.java

  18 
vote

/** 
 * Creates a new ClientConnectionManager to be used by the  {@link HttpClient}. Configures the  {@link SchemeRegistry}as well as setting up connection related  {@link HttpParams}
 */
protected ClientConnectionManager createClientConnectionManager(PortletRequest request,HttpParams params){
  if (this.clientConnectionManager != null) {
    return this.clientConnectionManager;
  }
  final int maxConnections=ConfigUtils.parseInt(request.getPreferences().getValue(HttpClientConfigImpl.MAX_CONNECTIONS,"50"),50);
  final int maxConnectionsPerRoute=ConfigUtils.parseInt(request.getPreferences().getValue(HttpClientConfigImpl.MAX_CONNECTIONS_PER_ROUTE,"10"),10);
  final ThreadSafeClientConnManager threadSafeClientConnManager=new ThreadSafeClientConnManager(this.schemeRegistry,300,TimeUnit.SECONDS);
  threadSafeClientConnManager.setMaxTotal(maxConnections);
  threadSafeClientConnManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
  return threadSafeClientConnManager;
}
 

Example 13

From project wiremock, under directory /src/main/java/com/github/tomakehurst/wiremock/http/.

Source file: HttpClientFactory.java

  18 
vote

public static HttpClient createClient(int maxConnections,int timeoutMilliseconds){
  ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager();
  connectionManager.setMaxTotal(maxConnections);
  connectionManager.setDefaultMaxPerRoute(maxConnections);
  HttpClient client=new DefaultHttpClient(connectionManager);
  HttpParams params=client.getParams();
  params.setParameter(HANDLE_REDIRECTS,false);
  HttpConnectionParams.setConnectionTimeout(params,timeoutMilliseconds);
  HttpConnectionParams.setSoTimeout(params,timeoutMilliseconds);
  return client;
}
 

Example 14

From project wrml-prototype, under directory /src/main/java/org/wrml/core/www/.

Source file: WebClient.java

  18 
vote

public WebClient(Context context){
  super(context);
  final ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager();
  connectionManager.setMaxTotal(100);
  _HttpClient=new DefaultHttpClient(connectionManager);
  _DefaultFormatter=new DefaultFormatter();
}
 

Example 15

From project zen-project, under directory /zen-webservice/src/main/java/com/nominanuda/web/http/.

Source file: HttpCoreHelper.java

  18 
vote

public HttpClient createClient(int maxConnPerRoute,long connTimeoutMillis,long soTimeoutMillis){
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager();
  cm.setMaxTotal(maxConnPerRoute);
  cm.setDefaultMaxPerRoute(maxConnPerRoute);
  HttpParams p=new BasicHttpParams();
  p.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,new Long(connTimeoutMillis).intValue());
  p.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,new Long(soTimeoutMillis).intValue());
  HttpClient httpClient=new DefaultHttpClient(cm,p);
  return httpClient;
}
 

Example 16

From project Airports, under directory /src/com/nadmm/airports/utils/.

Source file: NetworkUtils.java

  17 
vote

public static HttpClient getHttpClient(){
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  HttpParams params=new BasicHttpParams();
  ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry);
  HttpClient client=new DefaultHttpClient(cm,params);
  return client;
}
 

Example 17

From project androidquery, under directory /src/com/androidquery/callback/.

Source file: AbstractAjaxCallback.java

  17 
vote

private static DefaultHttpClient getClient(){
  if (client == null || !REUSE_CLIENT) {
    AQUtility.debug("creating http client");
    HttpParams httpParams=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,NET_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams,NET_TIMEOUT);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(25));
    HttpConnectionParams.setSocketBufferSize(httpParams,8192);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",ssf == null ? SSLSocketFactory.getSocketFactory() : ssf,443));
    ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,registry);
    client=new DefaultHttpClient(cm,httpParams);
  }
  return client;
}
 

Example 18

From project capedwarf-blue, under directory /urlfetch/src/main/java/org/jboss/capedwarf/urlfetch/.

Source file: JBossURLFetchService.java

  17 
vote

protected HttpClient getClient(){
  if (client == null) {
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory()));
    HttpParams params=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params,30 * 1000);
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,"UTF-8");
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(schemeRegistry);
    client=new DefaultHttpClient(ccm,params);
  }
  return client;
}
 

Example 19

From project couchdb4j, under directory /src/java/com/fourspaces/couchdb/.

Source file: Session.java

  17 
vote

/** 
 * Constructor for obtaining a Session with an HTTP-AUTH username/password and (optionally) a secure connection This isn't supported by CouchDB - you need a proxy in front to use this
 * @param host - hostname
 * @param port - port to use
 * @param user - username
 * @param pass - password
 * @param secure  - use an SSL connection?
 */
public Session(String host,int port,String user,String pass,boolean usesAuth,boolean secure){
  this.host=host;
  this.port=port;
  this.user=user;
  this.pass=pass;
  this.usesAuth=usesAuth;
  this.secure=secure;
  httpParams=new BasicHttpParams();
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ThreadSafeClientConnManager connManager=new ThreadSafeClientConnManager(httpParams,schemeRegistry);
  DefaultHttpClient defaultClient=new DefaultHttpClient(connManager,httpParams);
  if (user != null) {
    defaultClient.getCredentialsProvider().setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(user,pass));
  }
  this.httpClient=defaultClient;
  setUserAgent("couchdb4j");
  setSocketTimeout((30 * 1000));
  setConnectionTimeout((15 * 1000));
}
 

Example 20

From project crest, under directory /core/src/test/java/org/codegist/crest/io/http/.

Source file: HttpClientFactoryTest.java

  17 
vote

@Test public void createWithMoreThanOneShouldCreateDefaultHttpClientWithConnectionManagerSetup() throws Exception {
  DefaultHttpClient expected=mock(DefaultHttpClient.class);
  ProxySelectorRoutePlanner planner=mock(ProxySelectorRoutePlanner.class);
  ClientConnectionManager clientConnectionManager=mock(ClientConnectionManager.class);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  ProxySelector proxySelector=mock(ProxySelector.class);
  BasicHttpParams httpParams=mock(BasicHttpParams.class);
  ConnPerRouteBean routeBean=mock(ConnPerRouteBean.class);
  PlainSocketFactory plainSocketFactory=mock(PlainSocketFactory.class);
  SSLSocketFactory sslSocketFactory=mock(SSLSocketFactory.class);
  Scheme plainScheme=new Scheme("http",plainSocketFactory,80);
  Scheme sslScheme=new Scheme("https",sslSocketFactory,443);
  ThreadSafeClientConnManager threadSafeClientConnManager=mock(ThreadSafeClientConnManager.class);
  when(expected.getConnectionManager()).thenReturn(clientConnectionManager);
  when(clientConnectionManager.getSchemeRegistry()).thenReturn(schemeRegistry);
  mockStatic(ProxySelector.class);
  when(ProxySelector.getDefault()).thenReturn(proxySelector);
  mockStatic(PlainSocketFactory.class);
  when(PlainSocketFactory.getSocketFactory()).thenReturn(plainSocketFactory);
  mockStatic(SSLSocketFactory.class);
  when(SSLSocketFactory.getSocketFactory()).thenReturn(sslSocketFactory);
  whenNew(SchemeRegistry.class).withNoArguments().thenReturn(schemeRegistry);
  whenNew(Scheme.class).withArguments("http",plainSocketFactory,80).thenReturn(plainScheme);
  whenNew(Scheme.class).withArguments("https",sslSocketFactory,443).thenReturn(sslScheme);
  whenNew(ThreadSafeClientConnManager.class).withArguments(httpParams,schemeRegistry).thenReturn(threadSafeClientConnManager);
  whenNew(ConnPerRouteBean.class).withArguments(2).thenReturn(routeBean);
  whenNew(BasicHttpParams.class).withNoArguments().thenReturn(httpParams);
  whenNew(DefaultHttpClient.class).withArguments(threadSafeClientConnManager,httpParams).thenReturn(expected);
  whenNew(ProxySelectorRoutePlanner.class).withArguments(schemeRegistry,proxySelector).thenReturn(planner);
  when(crestConfig.getConcurrencyLevel()).thenReturn(2);
  HttpClient actual=HttpClientFactory.create(crestConfig,getClass());
  assertSame(expected,actual);
  verify(expected).setRoutePlanner(planner);
  verify(httpParams).setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
  verify(httpParams).setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,routeBean);
  verify(httpParams).setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,2);
  assertSame(plainScheme,schemeRegistry.getScheme("http"));
  assertSame(sslScheme,schemeRegistry.getScheme("https"));
}
 

Example 21

From project DeliciousDroid, under directory /src/com/deliciousdroid/client/.

Source file: HttpClientFactory.java

  17 
vote

public static HttpClient getThreadSafeClient(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,100);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT);
  ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry);
  HttpClient client=new DefaultHttpClient(mgr,params);
  return client;
}
 

Example 22

From project DiscogsForAndroid, under directory /src/com/discogs/services/.

Source file: NetworkHelper.java

  17 
vote

private void initHTTPClient(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setContentCharset(params,"utf-8");
  params.setBooleanParameter("http.protocol.expect-continue",false);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(params,true);
  ThreadSafeClientConnManager connectionManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connectionManager,params);
  httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,false));
  httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    final HttpRequest request,    final HttpContext context) throws HttpException, IOException {
      if (!request.containsHeader("Accept-Encoding")) {
        request.addHeader("Accept-Encoding","gzip");
      }
    }
  }
);
  httpClient.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    final HttpResponse response,    final HttpContext context) throws HttpException, IOException {
      HttpEntity entity=response.getEntity();
      if (entity != null) {
        Header ceheader=entity.getContentEncoding();
        if (ceheader != null) {
          HeaderElement[] codecs=ceheader.getElements();
          for (int i=0; i < codecs.length; i++) {
            if (codecs[i].getName().equalsIgnoreCase("gzip")) {
              response.setEntity(new GzipDecompressingEntity(response.getEntity()));
              return;
            }
          }
        }
      }
    }
  }
);
}
 

Example 23

From project droid-fu, under directory /src/main/java/com/github/droidfu/http/.

Source file: BetterHttp.java

  17 
vote

public static void setupHttpClient(){
  BasicHttpParams httpParams=new BasicHttpParams();
  ConnManagerParams.setTimeout(httpParams,socketTimeout);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections));
  ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS);
  HttpConnectionParams.setSoTimeout(httpParams,socketTimeout);
  HttpConnectionParams.setTcpNoDelay(httpParams,true);
  HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(httpParams,httpUserAgent);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  if (DiagnosticSupport.ANDROID_API_LEVEL >= 7) {
    schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  }
 else {
    schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443));
  }
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry);
  httpClient=new DefaultHttpClient(cm,httpParams);
}
 

Example 24

From project eve-api, under directory /cdi/src/main/java/org/onsteroids/eve/api/connector/http/.

Source file: PooledHttpApiConnection.java

  17 
vote

/** 
 * Initializses and configures the http client connection pool.
 */
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);
}
 

Example 25

From project exo.social.client, under directory /src/main/java/org/exoplatform/social/client/core/net/.

Source file: SocialHttpClientImpl.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults.
 * @return SocialHttpClient for you to use for all your requests.
 */
public static SocialHttpClient newInstance(){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_OPERATION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_OPERATION_TIMEOUT);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry);
  return new SocialHttpClientImpl(manager,params);
}
 

Example 26

From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/client/.

Source file: HttpClientFactory.java

  17 
vote

public static synchronized HttpClient getHttpClient(){
  if (client == null) {
    HttpParams params=new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params,MAX_TOTAL_CONNECTIONS);
    ConnPerRouteBean connPerRoute=new ConnPerRouteBean(MAX_PER_ROUTE);
    ConnManagerParams.setMaxConnectionsPerRoute(params,connPerRoute);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    ClientConnectionManager cm=new ThreadSafeClientConnManager(params,registry);
    client=new DefaultHttpClient(cm,params);
  }
  System.out.println("return cached client");
  return client;
}
 

Example 27

From project Fotolia-API, under directory /java/libs/httpcomponents-client-4.1.2/examples/org/apache/http/examples/client/.

Source file: ClientEvictExpiredConnections.java

  17 
vote

public static void main(String[] args) throws Exception {
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager();
  cm.setMaxTotal(100);
  HttpClient httpclient=new DefaultHttpClient(cm);
  try {
    String[] urisToGet={"http://jakarta.apache.org/","http://jakarta.apache.org/commons/","http://jakarta.apache.org/commons/httpclient/","http://svn.apache.org/viewvc/jakarta/httpcomponents/"};
    IdleConnectionEvictor connEvictor=new IdleConnectionEvictor(cm);
    connEvictor.start();
    for (int i=0; i < urisToGet.length; i++) {
      String requestURI=urisToGet[i];
      HttpGet req=new HttpGet(requestURI);
      System.out.println("executing request " + requestURI);
      HttpResponse rsp=httpclient.execute(req);
      HttpEntity entity=rsp.getEntity();
      System.out.println("----------------------------------------");
      System.out.println(rsp.getStatusLine());
      if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
      }
      System.out.println("----------------------------------------");
      EntityUtils.consume(entity);
    }
    Thread.sleep(20000);
    connEvictor.shutdown();
    connEvictor.join();
  }
  finally {
    httpclient.getConnectionManager().shutdown();
  }
}
 

Example 28

From project Game_3, under directory /android/src/playn/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 29

From project httpbuilder, under directory /src/main/java/groovyx/net/http/.

Source file: AsyncHTTPBuilder.java

  17 
vote

/** 
 * Initializes threading parameters for the HTTPClient's  {@link ThreadSafeClientConnManager}, and this class' ThreadPoolExecutor. 
 */
protected void initThreadPools(final int poolSize,final ExecutorService threadPool){
  if (poolSize < 1)   throw new IllegalArgumentException("poolSize may not be < 1");
  HttpParams params=client != null ? client.getParams() : new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,poolSize);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(poolSize));
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  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);
  super.client=new DefaultHttpClient(cm,params);
  this.threadPool=threadPool != null ? threadPool : new ThreadPoolExecutor(poolSize,poolSize,120,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());
}
 

Example 30

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 31

From project ignition, under directory /ignition-support/ignition-support-lib/src/main/java/com/github/ignition/support/http/.

Source file: IgnitedHttp.java

  17 
vote

protected void setupHttpClient(){
  BasicHttpParams httpParams=new BasicHttpParams();
  ConnManagerParams.setTimeout(httpParams,DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
  ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS);
  HttpConnectionParams.setSoTimeout(httpParams,DEFAULT_SOCKET_TIMEOUT);
  HttpConnectionParams.setTcpNoDelay(httpParams,true);
  HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(httpParams,DEFAULT_HTTP_USER_AGENT);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) {
    schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  }
 else {
    schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443));
  }
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry);
  httpClient=new DefaultHttpClient(cm,httpParams);
}
 

Example 32

From project ihatovgram, under directory /src/client/android/ihatovgram/lib/httpcomponents-client-4.1.3/examples/org/apache/http/examples/client/.

Source file: ClientEvictExpiredConnections.java

  17 
vote

public static void main(String[] args) throws Exception {
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager();
  cm.setMaxTotal(100);
  HttpClient httpclient=new DefaultHttpClient(cm);
  try {
    String[] urisToGet={"http://jakarta.apache.org/","http://jakarta.apache.org/commons/","http://jakarta.apache.org/commons/httpclient/","http://svn.apache.org/viewvc/jakarta/httpcomponents/"};
    IdleConnectionEvictor connEvictor=new IdleConnectionEvictor(cm);
    connEvictor.start();
    for (int i=0; i < urisToGet.length; i++) {
      String requestURI=urisToGet[i];
      HttpGet req=new HttpGet(requestURI);
      System.out.println("executing request " + requestURI);
      HttpResponse rsp=httpclient.execute(req);
      HttpEntity entity=rsp.getEntity();
      System.out.println("----------------------------------------");
      System.out.println(rsp.getStatusLine());
      if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
      }
      System.out.println("----------------------------------------");
      EntityUtils.consume(entity);
    }
    Thread.sleep(20000);
    connEvictor.shutdown();
    connEvictor.join();
  }
  finally {
    httpclient.getConnectionManager().shutdown();
  }
}
 

Example 33

From project janbanery, under directory /janbanery-android/src/main/java/pl/project13/janbanery/android/rest/.

Source file: AndroidCompatibleRestClient.java

  17 
vote

public DefaultHttpClient getClient(){
  DefaultHttpClient ret;
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,new ProtocolVersion("HTTP",1,1));
  HttpProtocolParams.setContentCharset(params,"UTF-8");
  params.setBooleanParameter("http.protocol.expect-continue",false);
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  final SSLSocketFactory sslSocketFactory=SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
  registry.register(new Scheme("https",sslSocketFactory,443));
  ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(params,registry);
  ret=new DefaultHttpClient(manager,params);
  return ret;
}
 

Example 34

From project jetty-project, under directory /jetty-reverse-http/reverse-http-client/src/test/java/org/mortbay/jetty/rhttp/client/.

Source file: ApacheClientTest.java

  17 
vote

protected RHTTPClient createClient(int port,String targetId) throws Exception {
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),port));
  connectionManager=new ThreadSafeClientConnManager(new BasicHttpParams(),schemeRegistry);
  HttpParams httpParams=new BasicHttpParams();
  httpParams.setParameter("http.default-host",new HttpHost("localhost",port));
  DefaultHttpClient httpClient=new DefaultHttpClient(connectionManager,httpParams);
  httpClient.setHttpRequestRetryHandler(new NoRetryHandler());
  return new ApacheClient(httpClient,"",targetId);
}
 

Example 35

From project leviathan, under directory /httpclient/src/main/java/ar/com/zauber/leviathan/impl/.

Source file: BulkURIFetchers.java

  17 
vote

/** 
 * create a safe  {@link URIFetcher} 
 */
public static URIFetcher createSafeHttpClientURIFetcher(){
  final Map<String,Scheme> registries=new HashMap<String,Scheme>();
  registries.put("http",new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  registries.put("https",new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  final SchemeRegistry schemaRegistry=new SchemeRegistry();
  schemaRegistry.setItems(registries);
  final HttpParams params=createHttpParams();
  final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemaRegistry);
  final HttpClient httpclient=new DefaultHttpClient(cm,params);
  final CharsetStrategy charsetStrategy=new ChainedCharsetStrategy(asList(new DefaultHttpCharsetStrategy(),new FixedCharsetStrategy("utf-8")));
  return new HTTPClientURIFetcher(httpclient,charsetStrategy);
}
 

Example 36

From project Locast-Android, under directory /src/edu/mit/mobile/android/locast/net/.

Source file: NetworkClient.java

  17 
vote

@Override protected ClientConnectionManager createClientConnectionManager(){
  final SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  return new ThreadSafeClientConnManager(getParams(),registry);
}
 

Example 37

From project Maimonides, under directory /src/com/codeko/apps/maimonides/seneca/.

Source file: ClienteSeneca.java

  17 
vote

public HttpClient getCliente(){
  if (cliente == null) {
    try {
      SSLContext ctx=SSLContext.getInstance("TLS");
      X509TrustManager tm=new X509TrustManager(){
        @Override public void checkClientTrusted(        X509Certificate[] xcs,        String string) throws CertificateException {
        }
        @Override public void checkServerTrusted(        X509Certificate[] xcs,        String string) throws CertificateException {
        }
        @Override public X509Certificate[] getAcceptedIssuers(){
          return null;
        }
      }
;
      ctx.init(null,new TrustManager[]{tm},null);
      SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      SchemeRegistry schemeRegistry=new SchemeRegistry();
      schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
      schemeRegistry.register(new Scheme("https",443,ssf));
      HttpParams params=new BasicHttpParams();
      HttpProtocolParams.setUserAgent(params,"Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12");
      ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
      cm.setDefaultMaxPerRoute(10);
      cm.setMaxTotal(20);
      HttpConnectionParams.setConnectionTimeout(params,1000);
      cliente=new DefaultHttpClient(cm,params);
    }
 catch (    Exception ex) {
      Logger.getLogger(ClienteSeneca.class.getName()).log(Level.SEVERE,null,ex);
      setUltimoError("Error conectando con S?neca: " + ex.getLocalizedMessage());
      setUltimaExcepcion(ex);
    }
  }
  ThreadSafeClientConnManager man=(ThreadSafeClientConnManager)cliente.getConnectionManager();
  man.closeExpiredConnections();
  man.closeIdleConnections(10,TimeUnit.SECONDS);
  Logger.getLogger(ClienteSeneca.class.getName()).log(Level.INFO,"Hay {0} conexiones abiertas.",man.getConnectionsInPool());
  return cliente;
}
 

Example 38

From project MIT-Mobile-for-Android, under directory /src/com/google/zxing/client/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 39

From project nuxeo-distribution, under directory /nuxeo-startup-wizard/src/main/java/org/nuxeo/wizard/download/.

Source file: PackageDownloader.java

  17 
vote

protected PackageDownloader(){
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  HttpParams httpParams=new BasicHttpParams();
  HttpProtocolParams.setUseExpectContinue(httpParams,false);
  ConnManagerParams.setMaxTotalConnections(httpParams,NB_DOWNLOAD_THREADS);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRoute(){
    @Override public int getMaxForRoute(    HttpRoute arg0){
      return NB_DOWNLOAD_THREADS;
    }
  }
);
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,registry);
  httpClient=new DefaultHttpClient(cm,httpParams);
}
 

Example 40

From project OAK, under directory /oak-library/src/main/java/oak/external/com/github/droidfu/http/.

Source file: BetterHttp.java

  17 
vote

public static void setupHttpClient(){
  BasicHttpParams httpParams=new BasicHttpParams();
  ConnManagerParams.setTimeout(httpParams,socketTimeout);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections));
  ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS);
  HttpConnectionParams.setSoTimeout(httpParams,socketTimeout);
  HttpConnectionParams.setTcpNoDelay(httpParams,true);
  HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(httpParams,httpUserAgent);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  if (DiagnosticSupport.ANDROID_API_LEVEL >= 7) {
    schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  }
 else {
    schemeRegistry.register(new Scheme("https",new EasySSLSocketFactory(),443));
  }
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(httpParams,schemeRegistry);
  httpClient=new DefaultHttpClient(cm,httpParams);
}
 

Example 41

From project Orweb, under directory /src/info/guardianproject/browser/.

Source file: AnonProxy.java

  17 
vote

/** 
 * Set the port for the HTTP proxy
 * @param port
 */
public AnonProxy(){
  HttpHost proxy=new HttpHost(Browser.DEFAULT_PROXY_HOST,Integer.parseInt(Browser.DEFAULT_PROXY_PORT),"http");
  SchemeRegistry supportedSchemes=new SchemeRegistry();
  supportedSchemes.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  supportedSchemes.register(new Scheme("https",ModSSLSocketFactory.getSocketFactory(),443));
  HttpParams hparams=new BasicHttpParams();
  HttpProtocolParams.setVersion(hparams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(hparams,"UTF-8");
  HttpProtocolParams.setUseExpectContinue(hparams,true);
  ClientConnectionManager ccm=new ThreadSafeClientConnManager(hparams,supportedSchemes);
  mClient=new DefaultHttpClient(ccm,hparams);
  mClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
}
 

Example 42

From project osgi-tests, under directory /test/glassfish-derby/src/test/java/org/ancoron/osgi/test/glassfish/.

Source file: GlassfishDerbyTest.java

  17 
vote

protected DefaultHttpClient getHTTPClient() throws NoSuchAlgorithmException, KeyManagementException {
  SSLContext sslContext=SSLContext.getInstance("SSL");
  sslContext.init(null,new TrustManager[]{new X509TrustManager(){
    @Override public X509Certificate[] getAcceptedIssuers(){
      System.out.println("getAcceptedIssuers =============");
      return null;
    }
    @Override public void checkClientTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkClientTrusted =============");
    }
    @Override public void checkServerTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkServerTrusted =============");
    }
  }
},new SecureRandom());
  SSLSocketFactory sf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  Scheme httpsScheme=new Scheme("https",8181,sf);
  PlainSocketFactory plain=new PlainSocketFactory();
  Scheme httpScheme=new Scheme("http",8080,plain);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(httpsScheme);
  schemeRegistry.register(httpScheme);
  HttpParams params=new BasicHttpParams();
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
  cm.setMaxTotal(200);
  cm.setDefaultMaxPerRoute(20);
  DefaultHttpClient httpClient=new DefaultHttpClient(cm,params);
  httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
  httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
  return httpClient;
}
 

Example 43

From project PartyWare, under directory /android/src/com/google/zxing/client/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 44

From project PinDroid, under directory /src/com/pindroid/client/.

Source file: HttpClientFactory.java

  17 
vote

public static HttpClient getThreadSafeClient(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,100);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT);
  ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry);
  HttpClient client=new DefaultHttpClient(mgr,params);
  return client;
}
 

Example 45

From project Playlist, under directory /src/com/google/zxing/client/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 46

From project playn, under directory /android/src/playn/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 47

From project proxy-servlet, under directory /src/main/java/com/woonoz/proxy/servlet/.

Source file: ProxyServlet.java

  17 
vote

public void init(ProxyServletConfig config){
  targetServer=config.getTargetUrl();
  if (targetServer != null) {
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    schemeRegistry.register(new Scheme(targetServer.getProtocol(),getPortOrDefault(targetServer.getPort()),PlainSocketFactory.getSocketFactory()));
    BasicHttpParams httpParams=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,config.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(httpParams,config.getSocketTimeout());
    ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
    cm.setDefaultMaxPerRoute(config.getMaxConnections());
    cm.setMaxTotal(config.getMaxConnections());
    client=new DefaultHttpClient(cm,httpParams);
    client.removeResponseInterceptorByClass(ResponseProcessCookies.class);
    client.removeRequestInterceptorByClass(RequestAddCookies.class);
    final String remoteUserHeader=config.getRemoteUserHeader();
    if (null != remoteUserHeader) {
      client.addRequestInterceptor(new HttpRequestInterceptor(){
        @Override public void process(        HttpRequest request,        HttpContext context) throws HttpException, IOException {
          request.removeHeaders(remoteUserHeader);
          HttpRequestHandler handler;
          if (context != null && (handler=(HttpRequestHandler)context.getAttribute(HttpRequestHandler.class.getName())) != null) {
            String remoteUser=handler.getRequest().getRemoteUser();
            if (remoteUser != null) {
              request.addHeader(remoteUserHeader,remoteUser);
            }
          }
        }
      }
);
    }
  }
}
 

Example 48

From project proxydroid, under directory /src/com/github/droidfu/http/.

Source file: BetterHttp.java

  17 
vote

public static void setupHttpClient(){
  BasicHttpParams httpParams=new BasicHttpParams();
  ConnManagerParams.setTimeout(httpParams,socketTimeout);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams,new ConnPerRouteBean(maxConnections));
  ConnManagerParams.setMaxTotalConnections(httpParams,DEFAULT_MAX_CONNECTIONS);
  HttpConnectionParams.setSoTimeout(httpParams,socketTimeout);
  HttpConnectionParams.setTcpNoDelay(httpParams,true);
  HttpProtocolParams.setVersion(httpParams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(httpParams,httpUserAgent);
  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);
  httpClient=new DefaultHttpClient(cm,httpParams);
}
 

Example 49

From project ReGalAndroid, under directory /g2-java-client/src/main/java/net/dahanne/gallery/g2/java/client/business/.

Source file: G2Client.java

  17 
vote

private DefaultHttpClient createHttpClient(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",new FakeSocketFactory(),443));
  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);
  ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  return new DefaultHttpClient(cm,params);
}
 

Example 50

From project Rhybudd, under directory /src/net/networksaremadeofstring/rhybudd/.

Source file: ZenossAPIv2.java

  17 
vote

private void PrepareSSLHTTPClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
  client=new DefaultHttpClient();
  SchemeRegistry registry=new SchemeRegistry();
  SocketFactory socketFactory=null;
  socketFactory=TrustAllSSLSocketFactory.getDefault();
  registry.register(new Scheme("https",socketFactory,443));
  mgr=new ThreadSafeClientConnManager(client.getParams(),registry);
  httpclient=new DefaultHttpClient(mgr,client.getParams());
}
 

Example 51

From project riak-java-client, under directory /src/main/java/com/basho/riak/client/raw/http/.

Source file: HTTPClusterClient.java

  17 
vote

@Override protected RawClient[] fromConfig(ClusterConfig<HTTPClientConfig> clusterConfig) throws IOException {
  List<RawClient> clients=new ArrayList<RawClient>();
  int maxTotal=clusterConfig.getTotalMaximumConnections();
  if (maxTotal == ClusterConfig.UNLIMITED_CONNECTIONS) {
    HTTPRiakClientFactory fac=HTTPRiakClientFactory.getInstance();
    for (    HTTPClientConfig node : clusterConfig.getClients()) {
      clients.add(fac.newClient(node));
    }
  }
 else {
    ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager();
    cm.setMaxTotal(maxTotal);
    for (    HTTPClientConfig node : clusterConfig.getClients()) {
      if (node.getMaxConnections() != null) {
        cm.setMaxForRoute(makeRoute(node.getUrl()),node.getMaxConnections());
      }
      DefaultHttpClient httpClient=new DefaultHttpClient(cm);
      if (node.getRetryHandler() != null) {
        httpClient.setHttpRequestRetryHandler(node.getRetryHandler());
      }
      RiakConfig riakConfig=new RiakConfig(node.getUrl());
      riakConfig.setMapReducePath(node.getMapreducePath());
      riakConfig.setTimeout(node.getTimeout());
      riakConfig.setHttpClient(httpClient);
      clients.add(new HTTPClientAdapter(new RiakClient(riakConfig)));
    }
  }
  return clients.toArray(new RawClient[clients.size()]);
}
 

Example 52

From project SchoolPlanner4Untis, under directory /src/edu/htl3r/schoolplanner/backend/network/.

Source file: Network.java

  17 
vote

public Network(){
  initSSLSocketFactories();
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20000);
  HttpConnectionParams.setSoTimeout(params,10000);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
  HttpProtocolParams.setUseExpectContinue(params,false);
  SchemeRegistry registry=new SchemeRegistry();
  ClientConnectionManager connman=new ThreadSafeClientConnManager(params,registry);
  client=new DefaultHttpClient(connman,params);
}
 

Example 53

From project ShortcutLink, under directory /src/org/bibimbap/shortcutlink/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 54

From project SMSSync, under directory /smssync/src/org/addhen/smssync/net/.

Source file: MainHttpClient.java

  17 
vote

public MainHttpClient(String url){
  this.url=url;
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(url,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  ThreadSafeClientConnManager manager=new ThreadSafeClientConnManager(httpParameters,schemeRegistry);
  httpclient=new DefaultHttpClient(manager,httpParameters);
}
 

Example 55

From project spark, under directory /spark-http-client/src/main/java/spark/protocol/.

Source file: ProtocolDataSource.java

  17 
vote

/** 
 * Creates a new thread-safe HTTP connection pool for use with a data source.
 * @param poolSize The size of the connection pool.
 * @return A new connection pool with the given size.
 */
private HttpClient createPooledClient(){
  HttpParams connMgrParams=new BasicHttpParams();
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme(HTTP_SCHEME,PlainSocketFactory.getSocketFactory(),HTTP_PORT));
  schemeRegistry.register(new Scheme(HTTPS_SCHEME,SSLSocketFactory.getSocketFactory(),HTTPS_PORT));
  ConnManagerParams.setMaxTotalConnections(connMgrParams,poolSize);
  ConnManagerParams.setMaxConnectionsPerRoute(connMgrParams,new ConnPerRouteBean(poolSize));
  ClientConnectionManager ccm=new ThreadSafeClientConnManager(connMgrParams,schemeRegistry);
  HttpParams httpParams=new BasicHttpParams();
  HttpProtocolParams.setUseExpectContinue(httpParams,false);
  ConnManagerParams.setTimeout(httpParams,acquireTimeout * 1000);
  return new DefaultHttpClient(ccm,httpParams);
}
 

Example 56

From project subsonic, under directory /subsonic-android/src/github/daneren2005/dsub/service/.

Source file: RESTMusicService.java

  17 
vote

public RESTMusicService(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20));
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443));
  connManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connManager,params);
}
 

Example 57

From project Subsonic-Android, under directory /src/net/sourceforge/subsonic/androidapp/service/.

Source file: RESTMusicService.java

  17 
vote

public RESTMusicService(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20));
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443));
  connManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connManager,params);
}
 

Example 58

From project subsonic_1, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.

Source file: RESTMusicService.java

  17 
vote

public RESTMusicService(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20));
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443));
  connManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connManager,params);
}
 

Example 59

From project subsonic_2, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.

Source file: RESTMusicService.java

  17 
vote

public RESTMusicService(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20));
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443));
  connManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connManager,params);
}
 

Example 60

From project Supersonic, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.

Source file: RESTMusicService.java

  17 
vote

public RESTMusicService(){
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(20));
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_READ_TIMEOUT_DEFAULT);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",createSSLSocketFactory(),443));
  connManager=new ThreadSafeClientConnManager(params,schemeRegistry);
  httpClient=new DefaultHttpClient(connManager,params);
}
 

Example 61

From project twitter4j_1, under directory /twitter4j-httpclient-support/src/main/java/twitter4j/internal/http/alternative/.

Source file: HttpClientImpl.java

  17 
vote

public HttpClientImpl(HttpClientConfiguration conf){
  this.conf=conf;
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  schemeRegistry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory()));
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager(schemeRegistry);
  cm.setMaxTotal(conf.getHttpMaxTotalConnections());
  cm.setDefaultMaxPerRoute(conf.getHttpDefaultMaxPerRoute());
  DefaultHttpClient client=new DefaultHttpClient(cm);
  HttpParams params=client.getParams();
  HttpConnectionParams.setConnectionTimeout(params,conf.getHttpConnectionTimeout());
  HttpConnectionParams.setSoTimeout(params,conf.getHttpReadTimeout());
  if (conf.getHttpProxyHost() != null && !conf.getHttpProxyHost().equals("")) {
    HttpHost proxy=new HttpHost(conf.getHttpProxyHost(),conf.getHttpProxyPort());
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
    if (conf.getHttpProxyUser() != null && !conf.getHttpProxyUser().equals("")) {
      if (logger.isDebugEnabled()) {
        logger.debug("Proxy AuthUser: " + conf.getHttpProxyUser());
        logger.debug("Proxy AuthPassword: " + z_T4JInternalStringUtil.maskString(conf.getHttpProxyPassword()));
      }
      client.getCredentialsProvider().setCredentials(new AuthScope(conf.getHttpProxyHost(),conf.getHttpProxyPort()),new UsernamePasswordCredentials(conf.getHttpProxyUser(),conf.getHttpProxyPassword()));
    }
  }
  this.client=client;
}
 

Example 62

From project zeitgeist-api, under directory /deps/httpcomponents-client/examples/org/apache/http/examples/client/.

Source file: ClientEvictExpiredConnections.java

  17 
vote

public static void main(String[] args) throws Exception {
  ThreadSafeClientConnManager cm=new ThreadSafeClientConnManager();
  cm.setMaxTotal(100);
  HttpClient httpclient=new DefaultHttpClient(cm);
  try {
    String[] urisToGet={"http://jakarta.apache.org/","http://jakarta.apache.org/commons/","http://jakarta.apache.org/commons/httpclient/","http://svn.apache.org/viewvc/jakarta/httpcomponents/"};
    IdleConnectionEvictor connEvictor=new IdleConnectionEvictor(cm);
    connEvictor.start();
    for (int i=0; i < urisToGet.length; i++) {
      String requestURI=urisToGet[i];
      HttpGet req=new HttpGet(requestURI);
      System.out.println("executing request " + requestURI);
      HttpResponse rsp=httpclient.execute(req);
      HttpEntity entity=rsp.getEntity();
      System.out.println("----------------------------------------");
      System.out.println(rsp.getStatusLine());
      if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
      }
      System.out.println("----------------------------------------");
      EntityUtils.consume(entity);
    }
    Thread.sleep(20000);
    connEvictor.shutdown();
    connEvictor.join();
  }
  finally {
    httpclient.getConnectionManager().shutdown();
  }
}
 

Example 63

From project zirco-browser, under directory /src/org/emergent/android/weave/client/.

Source file: WeaveTransport.java

  17 
vote

private ClientConnectionManager createClientConnectionManager(boolean threadSafe){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),HTTP_PORT_DEFAULT));
  schemeRegistry.register(new Scheme("https",m_sslSocketFactory,HTTPS_PORT_DEFAULT));
  if (threadSafe) {
    return new ThreadSafeClientConnManager(sm_httpParams,schemeRegistry);
  }
 else {
    return new SingleClientConnManager(sm_httpParams,schemeRegistry);
  }
}
 

Example 64

From project zxing-iphone, under directory /android/src/com/google/zxing/client/android/.

Source file: AndroidHttpClient.java

  17 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,userAgent);
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 65

From project 4308Cirrus, under directory /tendril-android-lib/src/main/java/edu/colorado/cs/cirrus/android/.

Source file: HttpUtils.java

  16 
vote

public static HttpClient getNewHttpClient(){
  try {
    KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    SSLSocketFactory sf=new EasySSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",sf,443));
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    return new DefaultHttpClient(ccm,params);
  }
 catch (  Exception e) {
    return new DefaultHttpClient();
  }
}
 

Example 66

From project android-bankdroid, under directory /src/eu/nullbyte/android/urllib/.

Source file: Urllib.java

  16 
vote

public Urllib(boolean acceptInvalidCertificates,boolean allowCircularRedirects){
  this.acceptInvalidCertificates=acceptInvalidCertificates;
  this.headers=new HashMap<String,String>();
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,this.charset);
  params.setBooleanParameter("http.protocol.expect-continue",false);
  if (allowCircularRedirects)   params.setBooleanParameter("http.protocol.allow-circular-redirects",true);
  if (acceptInvalidCertificates) {
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",new EasySSLSocketFactory(),443));
    ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry);
    httpclient=new DefaultHttpClient(manager,params);
  }
 else {
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
    ClientConnectionManager manager=new ThreadSafeClientConnManager(params,registry);
    httpclient=new DefaultHttpClient(manager,params);
  }
  context=new BasicHttpContext();
}
 

Example 67

From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/config/.

Source file: ApacheHCHttpCommandExecutorServiceModule.java

  16 
vote

@Singleton @Provides ClientConnectionManager newClientConnectionManager(HttpParams params,X509HostnameVerifier verifier,Closer closer) throws NoSuchAlgorithmException, KeyManagementException {
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  Scheme http=new Scheme("http",PlainSocketFactory.getSocketFactory(),80);
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(null,null,null);
  SSLSocketFactory sf=new SSLSocketFactory(context);
  sf.setHostnameVerifier(verifier);
  Scheme https=new Scheme("https",sf,443);
  SchemeRegistry sr=new SchemeRegistry();
  sr.register(http);
  sr.register(https);
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  closer.addToClose(new Closeable(){
    @Override public void close() throws IOException {
      cm.shutdown();
    }
  }
);
  return cm;
}
 

Example 68

From project andstatus, under directory /src/org/andstatus/app/net/.

Source file: ConnectionOAuth.java

  16 
vote

public ConnectionOAuth(MyAccount ma){
  super(ma);
  mOauthBaseUrl=ma.getOauthBaseUrl();
  HttpParams parameters=new BasicHttpParams();
  HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(parameters,false);
  HttpConnectionParams.setTcpNoDelay(parameters,true);
  HttpConnectionParams.setSocketBufferSize(parameters,8192);
  SchemeRegistry schReg=new SchemeRegistry();
  schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg);
  mClient=new DefaultHttpClient(tsccm,parameters);
  OAuthKeys oak=new OAuthKeys(ma.getOriginId());
  mConsumer=new CommonsHttpOAuthConsumer(oak.getConsumerKey(),oak.getConsumerSecret());
  mProvider=new CommonsHttpOAuthProvider(getApiUrl(apiEnum.OAUTH_REQUEST_TOKEN),getApiUrl(apiEnum.OAUTH_ACCESS_TOKEN),getApiUrl(apiEnum.OAUTH_AUTHORIZE));
  mProvider.setOAuth10a(true);
  if (ma.dataContains(ConnectionOAuth.USER_TOKEN) && ma.dataContains(ConnectionOAuth.USER_SECRET)) {
    setAuthInformation(ma.getDataString(ConnectionOAuth.USER_TOKEN,null),ma.getDataString(ConnectionOAuth.USER_SECRET,null));
  }
}
 

Example 69

From project andtweet, under directory /src/com/xorcode/andtweet/net/.

Source file: ConnectionOAuth.java

  16 
vote

public ConnectionOAuth(SharedPreferences sp){
  super(sp);
  HttpParams parameters=new BasicHttpParams();
  HttpProtocolParams.setVersion(parameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(parameters,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(parameters,false);
  HttpConnectionParams.setTcpNoDelay(parameters,true);
  HttpConnectionParams.setSocketBufferSize(parameters,8192);
  SchemeRegistry schReg=new SchemeRegistry();
  schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  ClientConnectionManager tsccm=new ThreadSafeClientConnManager(parameters,schReg);
  mClient=new DefaultHttpClient(tsccm,parameters);
  mConsumer=new CommonsHttpOAuthConsumer(OAuthKeys.TWITTER_CONSUMER_KEY,OAuthKeys.TWITTER_CONSUMER_SECRET);
  loadSavedKeys(sp);
}
 

Example 70

From project cloudify, under directory /rest-client/src/main/java/org/cloudifysource/restclient/.

Source file: GSRestClient.java

  16 
vote

/** 
 * Returns a HTTP client configured to use SSL.
 * @return HTTP client configured to use SSL
 * @throws RestException Reporting different failures while creating the HTTP client
 */
public final DefaultHttpClient getSSLHttpClient() throws RestException {
  try {
    final KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    final SSLSocketFactory sf=new RestSSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    final HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    final SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme(HTTPS,sf,url.getPort()));
    final ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    return new DefaultHttpClient(ccm,params);
  }
 catch (  final KeyStoreException e) {
    throw new RestException(e);
  }
catch (  final NoSuchAlgorithmException e) {
    throw new RestException(e);
  }
catch (  final CertificateException e) {
    throw new RestException(e);
  }
catch (  final IOException e) {
    throw new RestException(e);
  }
catch (  final KeyManagementException e) {
    throw new RestException(e);
  }
catch (  final UnrecoverableKeyException e) {
    throw new RestException(e);
  }
}
 

Example 71

From project components-ness-httpclient, under directory /client/src/main/java/com/nesscomputing/httpclient/factory/httpclient4/.

Source file: ApacheHttpClient4Factory.java

  16 
vote

public ApacheHttpClient4Factory(final HttpClientDefaults clientDefaults,@Nullable final Set<? extends HttpClientObserver> httpClientObservers){
  Preconditions.checkArgument(clientDefaults != null,"clientDefaults can not be null!");
  this.httpClientObservers=httpClientObservers;
  initParams();
  registry.register(HTTP_SCHEME);
  try {
    final TrustManager[] trustManagers=new TrustManager[]{getTrustManager(clientDefaults)};
    final KeyManager[] keyManagers=getKeyManagers(clientDefaults);
    final SSLContext sslContext=SSLContext.getInstance("TLS");
    sslContext.init(keyManagers,trustManagers,null);
    final SSLSocketFactory sslSocketFactory=new SSLSocketFactory(sslContext);
    registry.register(new Scheme("https",HTTPS_PORT,sslSocketFactory));
  }
 catch (  GeneralSecurityException ce) {
    throw new IllegalStateException(ce);
  }
catch (  IOException ioe) {
    throw new IllegalStateException(ioe);
  }
  connectionManager=new ThreadSafeClientConnManager(registry);
}
 

Example 72

From project fed4j, under directory /src/main/java/com/jute/fed4j/engine/component/http/.

Source file: HttpDispatcherImpl_Jakarta.java

  16 
vote

/** 
 * get a connection manager
 * @param params
 * @return
 */
private ClientConnectionManager getConnectionManager(HttpParams params,boolean enablePersistentConnection){
  ClientConnectionManager connectionManager;
  if (enablePersistentConnection) {
    if (sharedConnectionManager == null) {
synchronized (locker) {
        if (sharedConnectionManager == null) {
          ConnManagerParams.setMaxTotalConnections(params,100);
          HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
          ConnManagerParams.setTimeout(params,10);
          sharedConnectionManager=new ThreadSafeClientConnManager(params,schemeRegistry);
        }
      }
    }
    connectionManager=sharedConnectionManager;
  }
 else {
    connectionManager=new SingleClientConnManager(params,schemeRegistry);
  }
  return connectionManager;
}
 

Example 73

From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.

Source file: TwAjax.java

  16 
vote

public DefaultHttpClient getNewHttpClient(){
  if (ignoreSSLCerts) {
    try {
      KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
      trustStore.load(null,null);
      SSLSocketFactory sf=new IgnoreCertsSSLSocketFactory(trustStore);
      sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      HttpParams params=new BasicHttpParams();
      HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
      HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
      SchemeRegistry registry=new SchemeRegistry();
      registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
      registry.register(new Scheme("https",sf,443));
      ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
      return new DefaultHttpClient(ccm,params);
    }
 catch (    Exception e) {
      return new DefaultHttpClient();
    }
  }
 else {
    return new DefaultHttpClient();
  }
}
 

Example 74

From project LRJavaLib, under directory /src/com/navnorth/learningregistry/.

Source file: LRClient.java

  16 
vote

public static HttpClient getHttpClient(String scheme){
  if (scheme.equals("https")) {
    try {
      KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
      trustStore.load(null,null);
      SSLSocketFactory sf=new SelfSignSSLSocketFactory(trustStore);
      sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      HttpParams params=new BasicHttpParams();
      HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
      HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
      SchemeRegistry registry=new SchemeRegistry();
      registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
      registry.register(new Scheme("https",sf,443));
      ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
      return new DefaultHttpClient(ccm,params);
    }
 catch (    Exception e) {
      return new DefaultHttpClient();
    }
  }
 else {
    return new DefaultHttpClient();
  }
}
 

Example 75

From project MobiPerf, under directory /android/src/com/mobiperf/speedometer/.

Source file: Checkin.java

  16 
vote

/** 
 * Return an appropriately-configured HTTP client.
 */
private HttpClient getNewHttpClient(){
  DefaultHttpClient client;
  try {
    KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    SSLSocketFactory sf=new MySSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    HttpConnectionParams.setConnectionTimeout(params,POST_TIMEOUT_MILLISEC);
    HttpConnectionParams.setSoTimeout(params,POST_TIMEOUT_MILLISEC);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",sf,443));
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    client=new DefaultHttpClient(ccm,params);
  }
 catch (  Exception e) {
    Logger.w("Unable to create SSL HTTP client",e);
    client=new DefaultHttpClient();
  }
  CookieStore store=new BasicCookieStore();
  store.addCookie(authCookie);
  client.setCookieStore(store);
  return client;
}
 

Example 76

From project moho, under directory /moho-impl/src/main/java/com/voxeo/moho/imified/.

Source file: IMifiedDriver.java

  16 
vote

@Override public void init(SpiFramework framework){
  _appEventSource=framework;
  HttpServlet servlet=framework.getHTTPController();
  if (servlet.getServletConfig().getInitParameter("imifiedApiURL") != null) {
    _imifiedApiURL=servlet.getServletConfig().getInitParameter("imifiedApiURL");
  }
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,20);
  ConnPerRouteBean connPerRoute=new ConnPerRouteBean(20);
  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);
  _httpClient.setReuseStrategy(new DefaultConnectionReuseStrategy());
  _httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy(){
    public long getKeepAliveDuration(    HttpResponse response,    HttpContext context){
      HeaderElementIterator it=new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
      while (it.hasNext()) {
        HeaderElement he=it.nextElement();
        String param=he.getName();
        String value=he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
          try {
            return Long.parseLong(value) * 1000;
          }
 catch (          NumberFormatException ex) {
          }
        }
      }
      return -1;
    }
  }
);
}
 

Example 77

From project OpenMEAP, under directory /java-shared/openmeap-shared-jdk5/src/com/openmeap/util/.

Source file: SSLUtils.java

  16 
vote

static public HttpClient getRelaxedSSLVerificationHttpClient(){
  try {
    KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    SSLSocketFactory sf=new MySSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,FormConstants.CHAR_ENC_DEFAULT);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",sf,443));
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    return new DefaultHttpClient(ccm,params);
  }
 catch (  Exception e) {
    return new DefaultHttpClient();
  }
}
 

Example 78

From project QuotaForAndroid, under directory /Quota/src/com/southfreo/quota/utils/.

Source file: HttpHelper.java

  16 
vote

public static DefaultHttpClient QuotaClient(){
  HttpParams myParams=new BasicHttpParams();
  int defaultTimeOut=60 * 1000;
  HttpConnectionParams.setConnectionTimeout(myParams,defaultTimeOut);
  HttpConnectionParams.setSoTimeout(myParams,defaultTimeOut);
  HttpProtocolParams.setVersion(myParams,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(myParams,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUserAgent(myParams,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6");
  SchemeRegistry schReg=new SchemeRegistry();
  schReg.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schReg.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager conMgr=new ThreadSafeClientConnManager(myParams,schReg);
  HttpProtocolParams.setUseExpectContinue(myParams,false);
  return new DefaultHttpClient(conMgr,myParams);
}
 

Example 79

From project rain-workload-toolkit, under directory /thirdparty/httpcomponents-client-4.0.1/examples/org/apache/http/examples/client/.

Source file: ClientEvictExpiredConnections.java

  16 
vote

public static void main(String[] args) throws Exception {
  HttpParams params=new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params,100);
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  HttpClient httpclient=new DefaultHttpClient(cm,params);
  String[] urisToGet={"http://jakarta.apache.org/","http://jakarta.apache.org/commons/","http://jakarta.apache.org/commons/httpclient/","http://svn.apache.org/viewvc/jakarta/httpcomponents/"};
  IdleConnectionEvictor connEvictor=new IdleConnectionEvictor(cm);
  connEvictor.start();
  for (int i=0; i < urisToGet.length; i++) {
    String requestURI=urisToGet[i];
    HttpGet req=new HttpGet(requestURI);
    System.out.println("executing request " + requestURI);
    HttpResponse rsp=httpclient.execute(req);
    HttpEntity entity=rsp.getEntity();
    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    if (entity != null) {
      System.out.println("Response content length: " + entity.getContentLength());
    }
    System.out.println("----------------------------------------");
    if (entity != null) {
      entity.consumeContent();
    }
  }
  Thread.sleep(20000);
  connEvictor.shutdown();
  connEvictor.join();
  httpclient.getConnectionManager().shutdown();
}
 

Example 80

From project skalli, under directory /org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/internal/destination/.

Source file: DestinationServiceImpl.java

  16 
vote

private void initializeConnectionManager(){
  connectionManager=new ThreadSafeClientConnManager();
  connectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
  connectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
  SSLContext sslContext=getSSLContext();
  try {
    sslContext.init(null,new TrustManager[]{new AlwaysTrustX509Manager()},null);
  }
 catch (  KeyManagementException e) {
    throw new IllegalStateException("Failed to initialize SSL context",e);
  }
  SSLSocketFactory socketFactory=new SSLSocketFactory(sslContext,new AllowAllHostnamesVerifier());
  SchemeRegistry schemeRegistry=connectionManager.getSchemeRegistry();
  schemeRegistry.register(new Scheme(HTTPS,443,socketFactory));
}
 

Example 81

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/.

Source file: Checkin.java

  16 
vote

/** 
 * Return an appropriately-configured HTTP client.
 */
private HttpClient getNewHttpClient(){
  DefaultHttpClient client;
  try {
    KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    SSLSocketFactory sf=new MySSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    HttpConnectionParams.setConnectionTimeout(params,POST_TIMEOUT_MILLISEC);
    HttpConnectionParams.setSoTimeout(params,POST_TIMEOUT_MILLISEC);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",sf,443));
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    client=new DefaultHttpClient(ccm,params);
  }
 catch (  Exception e) {
    Logger.w("Unable to create SSL HTTP client",e);
    client=new DefaultHttpClient();
  }
  CookieStore store=new BasicCookieStore();
  store.addCookie(authCookie);
  client.setCookieStore(store);
  return client;
}
 

Example 82

From project SqueezeControl, under directory /src/com/squeezecontrol/image/.

Source file: HttpFetchingImageStore.java

  16 
vote

public HttpFetchingImageStore(String baseUrl,String username,String password){
  this.baseUrl=baseUrl;
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager mgr=new ThreadSafeClientConnManager(params,schemeRegistry);
  mClient=new DefaultHttpClient(mgr,params);
  if (username != null && !"".equals(username)) {
    Credentials defaultcreds=new UsernamePasswordCredentials("dag","test");
    mClient.getCredentialsProvider().setCredentials(AuthScope.ANY,defaultcreds);
  }
}
 

Example 83

From project TextSecure, under directory /src/org/thoughtcrime/securesms/mms/.

Source file: MmsCommunication.java

  16 
vote

protected static HttpClient constructHttpClient(MmsConnectionParameters mmsConfig){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  HttpProtocolParams.setUserAgent(params,"TextSecure/0.1");
  HttpProtocolParams.setContentCharset(params,"UTF-8");
  if (mmsConfig.hasProxy()) {
    ConnRouteParams.setDefaultProxy(params,new HttpHost(mmsConfig.getProxy(),mmsConfig.getPort()));
  }
  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);
  return new DefaultHttpClient(manager,params);
}
 

Example 84

From project YandexAPI, under directory /src/ru/elifantiev/yandex/.

Source file: SSLHttpClientFactory.java

  16 
vote

public static HttpClient getNewHttpClient(){
  try {
    KeyStore trustStore=KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null,null);
    SSLSocketFactory sf=new YandexSSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
    registry.register(new Scheme("https",sf,443));
    ClientConnectionManager ccm=new ThreadSafeClientConnManager(params,registry);
    return new DefaultHttpClient(ccm,params);
  }
 catch (  Exception e) {
    return new DefaultHttpClient();
  }
}
 

Example 85

From project zxing-android, under directory /src/com/laundrylocker/barcodescanner/.

Source file: AndroidHttpClient.java

  16 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  if (userAgent != null) {
    HttpProtocolParams.setUserAgent(params,userAgent);
  }
  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);
  return new AndroidHttpClient(manager,params);
}
 

Example 86

From project android_external_oauth, under directory /core/src/main/java/net/oauth/client/httpclient4/.

Source file: HttpClient4.java

  15 
vote

SingleClient(){
  HttpClient client=new DefaultHttpClient();
  ClientConnectionManager mgr=client.getConnectionManager();
  if (!(mgr instanceof ThreadSafeClientConnManager)) {
    HttpParams params=client.getParams();
    client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
  }
  this.client=client;
}
 

Example 87

From project bbb-java, under directory /src/main/java/org/mconf/web/.

Source file: Authentication.java

  15 
vote

@SuppressWarnings("deprecation") public Authentication(String server,String username,String password) throws HttpException, IOException {
  this.server=server;
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",new PlainSocketFactory(),80));
  registry.register(new Scheme("https",new FakeSocketFactory(),443));
  HttpParams params=new BasicHttpParams();
  params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false);
  client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,registry),params);
  authenticated=authenticate(username,password);
}
 

Example 88

From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/http/.

Source file: RequestHandler.java

  15 
vote

public static DefaultHttpClient getThreadSafeClient(){
  DefaultHttpClient client=new DefaultHttpClient();
  ClientConnectionManager mgr=client.getConnectionManager();
  HttpParams params=client.getParams();
  client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
  return client;
}
 

Example 89

From project couchdb-lucene, under directory /src/main/java/com/github/rnewson/couchdb/lucene/.

Source file: HttpClientFactory.java

  15 
vote

public static synchronized HttpClient getInstance() throws MalformedURLException {
  if (instance == null) {
    final HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(params,false);
    HttpConnectionParams.setTcpNoDelay(params,true);
    HttpConnectionParams.setStaleCheckingEnabled(params,false);
    ConnManagerParams.setMaxTotalConnections(params,1000);
    ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(1000));
    final SchemeRegistry schemeRegistry=new SchemeRegistry();
    schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),5984));
    schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
    final ClientConnectionManager cm=new ShieldedClientConnManager(new ThreadSafeClientConnManager(params,schemeRegistry));
    instance=new DefaultHttpClient(cm,params);
    if (INI != null) {
      final CredentialsProvider credsProvider=new BasicCredentialsProvider();
      final Iterator<?> it=INI.getKeys();
      while (it.hasNext()) {
        final String key=(String)it.next();
        if (!key.startsWith("lucene.") && key.endsWith(".url")) {
          final URL url=new URL(INI.getString(key));
          if (url.getUserInfo() != null) {
            credsProvider.setCredentials(new AuthScope(url.getHost(),url.getPort()),new UsernamePasswordCredentials(url.getUserInfo()));
          }
        }
      }
      instance.setCredentialsProvider(credsProvider);
      instance.addRequestInterceptor(new PreemptiveAuthenticationRequestInterceptor(),0);
    }
  }
  return instance;
}
 

Example 90

From project hsDroid, under directory /src/de/nware/app/hsDroid/provider/.

Source file: HttpClientFactory.java

  15 
vote

public synchronized static DefaultHttpClient getHttpClient(int connectionTimeoutMillis){
  if (httpClient == null) {
    httpClient=new DefaultHttpClient();
    ClientConnectionManager connectionManager=httpClient.getConnectionManager();
    HttpParams httpParams=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,connectionTimeoutMillis);
    httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams,connectionManager.getSchemeRegistry()),httpParams);
  }
  return httpClient;
}
 

Example 91

From project isohealth, under directory /Oauth/java/core/httpclient4/src/main/java/net/oauth/client/httpclient4/.

Source file: HttpClient4.java

  15 
vote

SingleClient(){
  HttpClient client=new DefaultHttpClient();
  ClientConnectionManager mgr=client.getConnectionManager();
  if (!(mgr instanceof ThreadSafeClientConnManager)) {
    HttpParams params=client.getParams();
    client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
  }
  this.client=client;
}
 

Example 92

From project lightbox-android-webservices, under directory /LightboxAndroidWebServices/src/com/lightbox/android/network/.

Source file: HttpHelper.java

  15 
vote

/** 
 * Create an HttpClient.
 * @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;
}
 

Example 93

From project memcached-session-manager, under directory /core/src/test/java/de/javakaffee/web/msm/integration/.

Source file: NonStickySessionsIntegrationTest.java

  15 
vote

@BeforeMethod public void setUp() throws Throwable {
  final InetSocketAddress address1=new InetSocketAddress("localhost",MEMCACHED_PORT_1);
  _daemon1=createDaemon(address1);
  _daemon1.start();
  final InetSocketAddress address2=new InetSocketAddress("localhost",MEMCACHED_PORT_2);
  _daemon2=createDaemon(address2);
  _daemon2.start();
  try {
    _tomcat1=startTomcat(TC_PORT_1);
    _tomcat2=startTomcat(TC_PORT_2);
  }
 catch (  final Throwable e) {
    LOG.error("could not start tomcat.",e);
    throw e;
  }
  final MemcachedNodesManager nodesManager=MemcachedNodesManager.createFor(MEMCACHED_NODES,null,_memcachedClientCallback);
  _client=new MemcachedClient(new SuffixLocatorConnectionFactory(nodesManager,nodesManager.getSessionIdFormat(),Statistics.create(),1000),Arrays.asList(address1,address2));
  final SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  _httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry));
  _executor=Executors.newCachedThreadPool();
}
 

Example 94

From project platform_external_oauth, under directory /core/src/main/java/net/oauth/client/httpclient4/.

Source file: HttpClient4.java

  15 
vote

SingleClient(){
  HttpClient client=new DefaultHttpClient();
  ClientConnectionManager mgr=client.getConnectionManager();
  if (!(mgr instanceof ThreadSafeClientConnManager)) {
    HttpParams params=client.getParams();
    client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,mgr.getSchemeRegistry()),params);
  }
  this.client=client;
}
 

Example 95

From project ratebeer-for-Android, under directory /RateBeerForAndroid/src/com/ratebeer/android/api/.

Source file: HttpHelper.java

  15 
vote

private static void ensureClient(){
  if (httpClient == null) {
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",new PlainSocketFactory(),80));
    HttpParams httpparams=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpparams,TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpparams,TIMEOUT);
    HttpProtocolParams.setUserAgent(httpparams,USER_AGENT);
    httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams,registry),httpparams);
  }
}
 

Example 96

From project ratebeerforandroid, under directory /RateBeerForAndroid/src/com/ratebeer/android/api/.

Source file: HttpHelper.java

  15 
vote

private static void ensureClient(){
  if (httpClient == null) {
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(new Scheme("http",new PlainSocketFactory(),80));
    HttpParams httpparams=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpparams,TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpparams,TIMEOUT);
    HttpProtocolParams.setUserAgent(httpparams,USER_AGENT);
    httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams,registry),httpparams);
  }
}
 

Example 97

From project SVQCOM, under directory /Core/src/com/ushahidi/android/app/net/.

Source file: MainHttpClient.java

  15 
vote

public MainHttpClient(Context context){
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters);
}
 

Example 98

From project teamcity-nuget-support, under directory /nuget-server/src/jetbrains/buildServer/nuget/server/feed/impl/.

Source file: FeedHttpClientHolder.java

  15 
vote

public FeedHttpClientHolder(){
  final String serverVersion=ServerVersionHolder.getVersion().getDisplayVersion();
  final HttpParams ps=new BasicHttpParams();
  DefaultHttpClient.setDefaultHttpParams(ps);
  HttpConnectionParams.setConnectionTimeout(ps,300 * 1000);
  HttpConnectionParams.setSoTimeout(ps,300 * 1000);
  HttpProtocolParams.setUserAgent(ps,"JetBrains TeamCity " + serverVersion);
  DefaultHttpClient httpclient=new DefaultHttpClient(new ThreadSafeClientConnManager(),ps);
  httpclient.setRoutePlanner(new ProxySelectorRoutePlanner(httpclient.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()));
  httpclient.addRequestInterceptor(new RequestAcceptEncoding());
  httpclient.addResponseInterceptor(new ResponseContentEncoding());
  httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,true));
  myClient=httpclient;
}
 

Example 99

From project tshirtslayer_android, under directory /src/org/xmlrpc/android/.

Source file: XMLRPCClient.java

  15 
vote

/** 
 * XMLRPCClient constructor. Creates new instance based on server URI (Code contributed by sgayda2 from issue #17, and by erickok from ticket #10)
 * @param XMLRPC server URI
 */
public XMLRPCClient(URI uri){
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",new PlainSocketFactory(),80));
  registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  postMethod=new HttpPost(uri);
  postMethod.addHeader("Content-Type","text/xml");
  httpParams=postMethod.getParams();
  HttpProtocolParams.setUseExpectContinue(httpParams,false);
  this.client=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams,registry),httpParams);
}
 

Example 100

From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/net/.

Source file: MainHttpClient.java

  15 
vote

public MainHttpClient(Context context){
  this.context=context;
  httpParameters=new BasicHttpParams();
  httpParameters.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS,1);
  httpParameters.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,new ConnPerRouteBean(1));
  httpParameters.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParameters,"utf8");
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  try {
    schemeRegistry.register(new Scheme("https",new TrustedSocketFactory(Preferences.domain,false),443));
  }
 catch (  KeyManagementException e) {
    e.printStackTrace();
  }
catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
  httpClient=new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters,schemeRegistry),httpParameters);
  httpClient.setParams(httpParameters);
}