Java Code Examples for org.apache.http.conn.ClientConnectionManager

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 Airports, under directory /src/com/nadmm/airports/utils/.

Source file: NetworkUtils.java

  22 
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 2

From project amber, under directory /oauth-2.0/httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/.

Source file: HttpClient4.java

  22 
vote

public void shutdown(){
  if (client != null) {
    ClientConnectionManager connectionManager=client.getConnectionManager();
    if (connectionManager != null) {
      connectionManager.shutdown();
    }
  }
}
 

Example 3

From project android-rackspacecloud, under directory /src/com/rackspace/cloud/files/api/client/.

Source file: CustomHttpClient.java

  22 
vote

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

Example 4

From project androidannotations, under directory /AndroidAnnotations/functional-test-1-5-tests/src/test/java/com/googlecode/androidannotations/test15/.

Source file: SSLConnectionTest.java

  22 
vote

@Test public void truststoreProvided(){
  assertNotNull(activity.mHttpsClientTest1);
  ClientConnectionManager ccm=activity.mHttpsClientTest1.getConnectionManager();
  assertNotNull(ccm);
  Scheme httpsScheme=ccm.getSchemeRegistry().getScheme("https");
  assertNotNull(httpsScheme);
  assertEquals(443,httpsScheme.getDefaultPort());
  SocketFactory socketFactHttps=httpsScheme.getSocketFactory();
  if (!(socketFactHttps instanceof SSLSocketFactory)) {
    Assert.fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps);
  }
  assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,((SSLSocketFactory)socketFactHttps).getHostnameVerifier());
}
 

Example 5

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

Source file: HttpClient4.java

  22 
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 6

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

Source file: RequestHandler.java

  22 
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 7

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

Source file: JBossURLFetchService.java

  22 
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 8

From project capedwarf-green, under directory /connect/src/main/java/org/jboss/capedwarf/connect/server/.

Source file: ServerProxyHandler.java

  22 
vote

public synchronized void shutdown(){
  if (client != null) {
    HttpClient tmp=client;
    client=null;
    ClientConnectionManager manager=tmp.getConnectionManager();
    if (manager != null)     manager.shutdown();
  }
}
 

Example 9

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

Source file: HttpClientHttpChannelFactoryTest.java

  22 
vote

@Test public void disposeShouldShutdownConnectionManager(){
  ClientConnectionManager clientConnectionManager=mock(ClientConnectionManager.class);
  when(client.getConnectionManager()).thenReturn(clientConnectionManager);
  toTest.dispose();
  verify(clientConnectionManager).shutdown();
}
 

Example 10

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

Source file: HttpClientFactory.java

  22 
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 11

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

Source file: PooledHttpApiConnection.java

  22 
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 12

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

Source file: SocialHttpClientImpl.java

  22 
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 13

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

Source file: HttpClientFactory.java

  22 
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 14

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

Source file: AndroidHttpClient.java

  22 
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 15

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

Source file: HttpClientFactory.java

  22 
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 16

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

Source file: AsyncHTTPBuilder.java

  22 
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 17

From project httpClient, under directory /httpclient-cache/src/test/java/org/apache/http/impl/client/cache/.

Source file: TestCachingHttpClient.java

  22 
vote

@Test public void testUsesBackendsConnectionManager(){
  expect(mockBackend.getConnectionManager()).andReturn(mockConnectionManager);
  replayMocks();
  ClientConnectionManager result=impl.getConnectionManager();
  verifyMocks();
  Assert.assertSame(result,mockConnectionManager);
}
 

Example 18

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

Source file: AndroidHttpClient.java

  22 
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 19

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

Source file: HttpClient4.java

  22 
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 20

From project jolokia, under directory /client/java/src/main/java/org/jolokia/client/.

Source file: J4pClientBuilder.java

  22 
vote

/** 
 * Build the agent with the information given before
 * @return a new J4pClient
 */
public J4pClient build(){
  ClientConnectionManager cm=createClientConnectionManager();
  DefaultHttpClient httpClient=new DefaultHttpClient(cm,getHttpParams());
  if (user != null) {
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(user,password));
  }
  return new J4pClient(url,httpClient,targetUrl != null ? new J4pTargetConfig(targetUrl,targetUser,targetPassword) : null);
}
 

Example 21

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

Source file: BulkURIFetchers.java

  22 
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 22

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

Source file: AndroidHttpClient.java

  22 
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 23

From project onebusaway-java-api, under directory /src/test/java/fr/dudie/onebusaway/client/.

Source file: JsonOneBusAwayClientTest.java

  22 
vote

/** 
 * Instantiates the test.
 * @param name the test name
 * @throws IOException an error occurred during initialization
 */
public JsonOneBusAwayClientTest(final String name) throws IOException {
  super(name);
  LOGGER.info("Loading configuration file {}",PROPS_PATH);
  final InputStream in=JsonOneBusAwayClientTest.class.getResourceAsStream(PROPS_PATH);
  PROPS.load(in);
  LOGGER.info("Preparing http client");
  final SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",new PlainSocketFactory(),80));
  final ClientConnectionManager connexionManager=new SingleClientConnManager(null,registry);
  final HttpClient httpClient=new DefaultHttpClient(connexionManager,null);
  final String url=PROPS.getProperty("onebusaway.api.url");
  final String key=PROPS.getProperty("onebusaway.api.key");
  obaClient=new JsonOneBusAwayClient(httpClient,url,key);
}
 

Example 24

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

Source file: AnonProxy.java

  22 
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 25

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

Source file: AndroidHttpClient.java

  22 
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 26

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

Source file: HttpClientFactory.java

  22 
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 27

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

Source file: HttpClient4.java

  22 
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 28

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

Source file: AndroidHttpClient.java

  22 
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 playn, under directory /android/src/playn/android/.

Source file: AndroidHttpClient.java

  22 
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 30

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

Source file: G2Client.java

  22 
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 31

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

Source file: Network.java

  22 
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 32

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

Source file: AndroidHttpClient.java

  22 
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 33

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

Source file: ProtocolDataSource.java

  22 
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 34

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

Source file: BasicHttpClientFactory.java

  22 
vote

static HttpClient createHttpClient(){
  final HttpParams params=createHttpParams();
  final ClientConnectionManager ccm=createConnectionManager(params);
  final DefaultHttpClient client=new DefaultHttpClient(ccm,params);
  client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false);
  client.clearRequestInterceptors();
  client.clearResponseInterceptors();
  client.addRequestInterceptor(new RequestCopyHeadersInterceptor());
  return client;
}
 

Example 35

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

Source file: HttpManagerImpl.java

  22 
vote

/** 
 * Create a new THREAD SAFE HttpClient instance using the available portlet preferences. This method may be used by subclasses to provide an alternate instance of DefaultHttpClient.  The returned client should be sure to  use a  thread-safe client connection manager.
 * @param prefs
 * @return new DefaultHttpClient instance
 */
protected DefaultHttpClient createHttpClient(PortletRequest request){
  if (logger.isDebugEnabled()) {
    logger.debug("Creating new DefaultHttpClient for " + request.getRemoteUser());
  }
  final HttpParams params=new BasicHttpParams();
  final ClientConnectionManager clientConnectionManager=this.createClientConnectionManager(request,params);
  client=new DefaultHttpClient(clientConnectionManager,params);
  return client;
}
 

Example 36

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

Source file: WeaveTransport.java

  22 
vote

private DefaultHttpClient createDefaultHttpClient(){
  ClientConnectionManager connectionManager;
  if (m_clientConMgr != null) {
    connectionManager=m_clientConMgr;
  }
 else {
    connectionManager=createClientConnectionManager(false);
  }
  return new DefaultHttpClient(connectionManager,sm_httpParams);
}
 

Example 37

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

Source file: AndroidHttpClient.java

  22 
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 38

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

Source file: HttpUtils.java

  21 
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 39

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

Source file: Urllib.java

  21 
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 40

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

Source file: ConnectionOAuth.java

  21 
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 41

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

Source file: ConnectionOAuth.java

  21 
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 42

From project bitfluids, under directory /src/test/java/at/bitcoin_austria/bitfluids/.

Source file: NetTest.java

  21 
vote

public static HttpClient wrapClient(HttpClient base){
  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);
    ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm=base.getConnectionManager();
    SchemeRegistry sr=ccm.getSchemeRegistry();
    sr.register(new Scheme("https",ssf,443));
    return new DefaultHttpClient(ccm,base.getParams());
  }
 catch (  Exception ex) {
    throw new RuntimeException(ex);
  }
}
 

Example 43

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

Source file: GSRestClient.java

  21 
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 44

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

Source file: HttpClientFactory.java

  21 
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 45

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

Source file: HttpDispatcherImpl_Jakarta.java

  21 
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 46

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

Source file: TwAjax.java

  21 
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 47

From project iSpace, under directory /base/httpcrawler/src/main/java/com/villemos/ispace/httpcrawler/.

Source file: HttpClientConfigurer.java

  21 
vote

public static HttpClient setupClient(boolean ignoreAuthenticationFailure,String domain,Integer port,String proxyHost,Integer proxyPort,String authUser,String authPassword,CookieStore cookieStore) throws NoSuchAlgorithmException, KeyManagementException {
  DefaultHttpClient client=null;
  if (ignoreAuthenticationFailure) {
    SSLContext sslContext=SSLContext.getInstance("SSL");
    sslContext.init(null,new TrustManager[]{new EasyX509TrustManager()},new SecureRandom());
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    SSLSocketFactory sf=new SSLSocketFactory(sslContext);
    Scheme httpsScheme=new Scheme("https",sf,443);
    schemeRegistry.register(httpsScheme);
    SocketFactory sfa=new PlainSocketFactory();
    Scheme httpScheme=new Scheme("http",sfa,80);
    schemeRegistry.register(httpScheme);
    HttpParams params=new BasicHttpParams();
    ClientConnectionManager cm=new SingleClientConnManager(params,schemeRegistry);
    client=new DefaultHttpClient(cm,params);
  }
 else {
    client=new DefaultHttpClient();
  }
  if (proxyHost != null && proxyPort != null) {
    HttpHost proxy=new HttpHost(proxyHost,proxyPort);
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
  }
 else {
    ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault());
    client.setRoutePlanner(routePlanner);
  }
  if (authUser != null && authPassword != null) {
    client.getCredentialsProvider().setCredentials(new AuthScope(domain,port),new UsernamePasswordCredentials(authUser,authPassword));
  }
  client.setCookieStore(cookieStore);
  client.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BEST_MATCH);
  return client;
}
 

Example 48

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

Source file: LRClient.java

  21 
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 49

From project lyo.testsuite, under directory /org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/.

Source file: OSLCUtils.java

  21 
vote

static public void setupLazySSLSupport(HttpClient httpClient){
  ClientConnectionManager connManager=httpClient.getConnectionManager();
  SchemeRegistry schemeRegistry=connManager.getSchemeRegistry();
  schemeRegistry.unregister("https");
  TrustManager[] trustAllCerts=new TrustManager[]{new X509TrustManager(){
    public void checkClientTrusted(    java.security.cert.X509Certificate[] certs,    String authType){
    }
    public void checkServerTrusted(    java.security.cert.X509Certificate[] certs,    String authType){
    }
    public java.security.cert.X509Certificate[] getAcceptedIssuers(){
      return null;
    }
  }
};
  SSLContext sc=null;
  try {
    sc=SSLContext.getInstance("SSL");
    sc.init(null,trustAllCerts,new java.security.SecureRandom());
  }
 catch (  NoSuchAlgorithmException e) {
  }
catch (  KeyManagementException e) {
  }
  SSLSocketFactory sf=new SSLSocketFactory(sc);
  sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  Scheme https=new Scheme("https",sf,443);
  schemeRegistry.register(https);
}
 

Example 50

From project miso-lims, under directory /core/src/main/java/uk/ac/bbsrc/tgac/miso/core/manager/.

Source file: ERASubmissionManager.java

  21 
vote

/** 
 * Builds a "trusting" trust manager. This is totally horrible and basically ignores everything that SSL stands for. This allows connection to self-signed certificate hosts, bypassing the normal validation exceptions that occur. <p/> Use at your own risk - again, this is horrible!
 */
public DefaultHttpClient getEvilTrustingTrustManager(DefaultHttpClient httpClient){
  try {
    X509TrustManager trustManager=new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
        log.warn("BYPASSING CLIENT TRUSTED CHECK!");
      }
      public void checkServerTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
        log.warn("BYPASSING SERVER TRUSTED CHECK!");
      }
      public X509Certificate[] getAcceptedIssuers(){
        log.warn("BYPASSING CERTIFICATE ISSUER CHECKS!");
        return null;
      }
    }
;
    SSLContext sslcontext=SSLContext.getInstance("TLS");
    sslcontext.init(null,new TrustManager[]{trustManager},null);
    SSLSocketFactory sf=new SSLSocketFactory(sslcontext);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm=httpClient.getConnectionManager();
    SchemeRegistry schemeRegistry=ccm.getSchemeRegistry();
    schemeRegistry.register(new Scheme("https",sf,443));
    return new DefaultHttpClient(ccm,httpClient.getParams());
  }
 catch (  Throwable t) {
    log.warn("Something nasty happened with the EvilTrustingTrustManager. Warranty is null and void!");
    t.printStackTrace();
    return null;
  }
}
 

Example 51

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

Source file: Checkin.java

  21 
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 52

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

Source file: IMifiedDriver.java

  21 
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 53

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

Source file: SSLUtils.java

  21 
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 54

From project Pitbull, under directory /pitbull-core/src/test/java/org/jboss/pitbull/test/.

Source file: SslEchoTest.java

  21 
vote

private static DefaultHttpClient createHttpClient(int port){
  try {
    java.lang.System.setProperty("sun.security.ssl.allowUnsafeRenegotiation","true");
    X509TrustManager trustManager=new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
      }
      public void checkServerTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
      }
      public X509Certificate[] getAcceptedIssuers(){
        return null;
      }
    }
;
    SSLContext sslContext=SSLContext.getInstance("SSL");
    sslContext.init(null,new TrustManager[]{trustManager},new SecureRandom());
    SSLSocketFactory sf=new SSLSocketFactory(sslContext);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme httpsScheme=new Scheme("https",sf,port);
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    HttpParams params=new BasicHttpParams();
    ClientConnectionManager cm=new SingleClientConnManager(params,schemeRegistry);
    return new DefaultHttpClient(cm,params);
  }
 catch (  Exception ex) {
    return null;
  }
}
 

Example 55

From project platform_external_apache-http, under directory /src/org/apache/http/impl/client/.

Source file: DefaultHttpClient.java

  21 
vote

@Override protected ClientConnectionManager createClientConnectionManager(){
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  registry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager connManager=null;
  HttpParams params=getParams();
  ClientConnectionManagerFactory factory=null;
  factory=(ClientConnectionManagerFactory)params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
  if (factory == null) {
    String className=(String)params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
      try {
        Class<?> clazz=Class.forName(className);
        factory=(ClientConnectionManagerFactory)clazz.newInstance();
      }
 catch (      ClassNotFoundException ex) {
        throw new IllegalStateException("Invalid class name: " + className);
      }
catch (      IllegalAccessException ex) {
        throw new IllegalAccessError(ex.getMessage());
      }
catch (      InstantiationException ex) {
        throw new InstantiationError(ex.getMessage());
      }
    }
  }
  if (factory != null) {
    connManager=factory.newInstance(params,registry);
  }
 else {
    connManager=new SingleClientConnManager(getParams(),registry);
  }
  return connManager;
}
 

Example 56

From project processFlowProvision, under directory /osProvision/src/main/java/org/jboss/processFlow/openshift/.

Source file: ShifterProvisioner.java

  21 
vote

private void prepConnection() throws Exception {
  httpClient=new DefaultHttpClient();
  SSLContext sslContext=SSLContext.getInstance("SSL");
  sslContext.init(null,new TrustManager[]{new X509TrustManager(){
    public X509Certificate[] getAcceptedIssuers(){
      System.out.println("getAcceptedIssuers =============");
      return null;
    }
    public void checkClientTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkClientTrusted =============");
    }
    public void checkServerTrusted(    X509Certificate[] certs,    String authType){
      System.out.println("checkServerTrusted =============");
    }
  }
},new SecureRandom());
  SSLSocketFactory ssf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  ClientConnectionManager ccm=httpClient.getConnectionManager();
  SchemeRegistry sr=ccm.getSchemeRegistry();
  sr.register(new Scheme("https",443,ssf));
  UsernamePasswordCredentials credentials=new UsernamePasswordCredentials(accountId,password);
  URL urlObj=new URL(openshiftRestURI);
  AuthScope aScope=new AuthScope(urlObj.getHost(),urlObj.getPort());
  httpClient.getCredentialsProvider().setCredentials(aScope,credentials);
  httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(),0);
}
 

Example 57

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

Source file: HttpHelper.java

  21 
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 58

From project rain-workload-toolkit, under directory /src/radlab/rain/util/.

Source file: HttpTransport.java

  21 
vote

public static HttpClient wrapClient(HttpClient base){
  try {
    SSLContext ctx=SSLContext.getInstance("TLS");
    X509TrustManager tm=new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public void checkServerTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public X509Certificate[] getAcceptedIssuers(){
        return null;
      }
    }
;
    ctx.init(null,new TrustManager[]{tm},null);
    SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm=base.getConnectionManager();
    SchemeRegistry sr=ccm.getSchemeRegistry();
    sr.register(new Scheme("https",443,ssf));
    return new DefaultHttpClient(ccm,base.getParams());
  }
 catch (  Exception ex) {
    return null;
  }
}
 

Example 59

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

Source file: ClientUtils.java

  21 
vote

/** 
 * Construct a new  {@link HttpClient} instance given a {@link RiakConfig}.
 * @param config {@link RiakConfig} containing HttpClient configurationspecifics.
 * @return A new {@link HttpClient}
 */
public static HttpClient newHttpClient(RiakConfig config){
  HttpClient http=config.getHttpClient();
  ClientConnectionManager m;
  if (http == null) {
    m=new ThreadSafeClientConnManager();
    if (config.getMaxConnections() != null) {
      ((ThreadSafeClientConnManager)m).setMaxTotal(config.getMaxConnections());
      ((ThreadSafeClientConnManager)m).setDefaultMaxPerRoute(config.getMaxConnections());
    }
    http=new DefaultHttpClient(m);
    if (config.getRetryHandler() != null) {
      ((DefaultHttpClient)http).setHttpRequestRetryHandler(config.getRetryHandler());
    }
  }
  HttpParams cp=http.getParams();
  if (config.getTimeout() != null) {
    cp.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT,config.getTimeout());
    cp.setIntParameter(AllClientPNames.SO_TIMEOUT,config.getTimeout());
  }
  return http;
}
 

Example 60

From project sensei, under directory /sensei-core/src/main/java/com/senseidb/dataprovider/http/.

Source file: HttpsClientDecorator.java

  21 
vote

public static DefaultHttpClient decorate(DefaultHttpClient base){
  try {
    SSLContext ctx=SSLContext.getInstance("TLS");
    X509TrustManager tm=new X509TrustManager(){
      public void checkClientTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public void checkServerTrusted(      X509Certificate[] xcs,      String string) throws CertificateException {
      }
      public X509Certificate[] getAcceptedIssuers(){
        return null;
      }
    }
;
    ctx.init(null,new TrustManager[]{tm},null);
    SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm=base.getConnectionManager();
    SchemeRegistry sr=ccm.getSchemeRegistry();
    sr.register(new Scheme("https",443,ssf));
    return new DefaultHttpClient(ccm,base.getParams());
  }
 catch (  Exception ex) {
    logger.error(ex.getMessage(),ex);
    return null;
  }
}
 

Example 61

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

Source file: Checkin.java

  21 
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 62

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

Source file: HttpFetchingImageStore.java

  21 
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 63

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

Source file: MmsCommunication.java

  21 
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 64

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

Source file: SSLHttpClientFactory.java

  21 
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 65

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

Source file: AndroidHttpClient.java

  21 
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 66

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: UriTexture.java

  19 
vote

private static final BufferedInputStream createInputStreamFromRemoteUrl(String uri,ClientConnectionManager connectionManager){
  InputStream contentInput=null;
  if (connectionManager == null) {
    try {
      URL url=new URI(uri).toURL();
      URLConnection conn=url.openConnection();
      conn.connect();
      contentInput=conn.getInputStream();
    }
 catch (    Exception e) {
      Log.w(TAG,"Request failed: " + uri);
      e.printStackTrace();
      return null;
    }
  }
 else {
    final DefaultHttpClient mHttpClient=new DefaultHttpClient(connectionManager,HTTP_PARAMS);
    HttpUriRequest request=new HttpGet(uri);
    HttpResponse httpResponse=null;
    try {
      httpResponse=mHttpClient.execute(request);
      HttpEntity entity=httpResponse.getEntity();
      if (entity != null) {
        contentInput=entity.getContent();
      }
    }
 catch (    Exception e) {
      Log.w(TAG,"Request failed: " + request.getURI());
      return null;
    }
  }
  if (contentInput != null) {
    return new BufferedInputStream(contentInput,4096);
  }
 else {
    return null;
  }
}
 

Example 67

From project anode, under directory /src/net/haltcondition/anode/.

Source file: WebtoolsHttpClient.java

  19 
vote

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

Example 68

From project conference-mobile-app, under directory /android-app/tests/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 69

From project dccsched, under directory /tests/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 70

From project dcnyc10-android, under directory /android/tests.old/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 71

From project gddsched2, under directory /trunk/android/tests.old/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 72

From project iosched, under directory /android/tests.old/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 73

From project iosched2011, under directory /android/tests.old/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 74

From project iosched_1, under directory /tests/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 75

From project iosched_2, under directory /android/tests.old/src/com/google/android/apps/iosched/io/.

Source file: StubHttpClient.java

  19 
vote

/** 
 * {@inheritDoc} 
 */
@Override protected RequestDirector createClientRequestDirector(final HttpRequestExecutor requestExec,final ClientConnectionManager conman,final ConnectionReuseStrategy reustrat,final ConnectionKeepAliveStrategy kastrat,final HttpRoutePlanner rouplan,final HttpProcessor httpProcessor,final HttpRequestRetryHandler retryHandler,final RedirectHandler redirectHandler,final AuthenticationHandler targetAuthHandler,final AuthenticationHandler proxyAuthHandler,final UserTokenHandler stateHandler,final HttpParams params){
  return new RequestDirector(){
    /** 
 * {@inheritDoc} 
 */
    public HttpResponse execute(    HttpHost target,    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      Log.d(TAG,"Intercepted: " + request.getRequestLine().toString());
      mLastRequest=request;
      return mResponse;
    }
  }
;
}
 

Example 76

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

Source file: NetworkClient.java

  19 
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 77

From project maven-wagon, under directory /wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/.

Source file: AbstractHttpClientWagon.java

  19 
vote

public ClientConnectionManager getConnectionManager(){
  if (!useClientManagerPooled) {
    return clientConnectionManager;
  }
  return connectionManagerPooled;
}
 

Example 78

From project PageTurner, under directory /src/main/java/net/nightwhistler/pageturner/sync/.

Source file: PageTurnerWebProgressService.java

  19 
vote

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

Example 79

From project saldo, under directory /src/com/adrup/saldo/.

Source file: SaldoHttpClient.java

  19 
vote

public SaldoHttpClient(Context context,ClientConnectionManager conman,HttpParams params){
  super(conman,params);
  mContext=context;
  if (sLockForLocaleSettings == null) {
    sLockForLocaleSettings=new Object();
    sLocale=Locale.getDefault();
  }
  mUserAgent=getCurrentUserAgent();
  getParams().setParameter(HttpProtocolParams.USER_AGENT,mUserAgent);
}