Java Code Examples for org.apache.http.conn.scheme.SchemeRegistry

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

  34 
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 capedwarf-blue, under directory /urlfetch/src/main/java/org/jboss/capedwarf/urlfetch/.

Source file: JBossURLFetchService.java

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

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

Source file: CustomHttpClient.java

  32 
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 anode, under directory /src/net/haltcondition/anode/.

Source file: WebtoolsHttpClient.java

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

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

Source file: Flickr.java

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

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

Source file: Authentication.java

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

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

Source file: ServerProxyHandler.java

  32 
vote

/** 
 * Create and initialize scheme registry.
 * @return the scheme registry
 */
protected SchemeRegistry createSchemeRegistry(){
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",config.getPlainFactory(),config.getPort()));
  schemeRegistry.register(new Scheme("https",config.getSslFactory(),config.getSslPort()));
  return schemeRegistry;
}
 

Example 8

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

Source file: HttpClientFactory.java

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

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

Source file: SimpleHttpClient.java

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

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

Source file: PooledHttpApiConnection.java

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

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

Source file: SocialHttpClientImpl.java

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

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

Source file: HttpClient.java

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

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

Source file: HttpClientFactory.java

  32 
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

  32 
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 httpbuilder, under directory /src/main/java/groovyx/net/http/.

Source file: AsyncHTTPBuilder.java

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

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

Source file: HTTPClientResponseResolver.java

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

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

Source file: HttpConnector.java

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

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

Source file: AndroidHttpClient.java

  32 
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 jetty-project, under directory /jetty-reverse-http/reverse-http-client/src/test/java/org/mortbay/jetty/rhttp/client/.

Source file: ApacheClientTest.java

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

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

Source file: BulkURIFetchers.java

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

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

Source file: NetworkClient.java

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

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

Source file: AndroidHttpClient.java

  32 
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

  32 
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

  32 
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 PageTurner, under directory /src/main/java/net/nightwhistler/pageturner/sync/.

Source file: PageTurnerWebProgressService.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: HttpClientFactory.java

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

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

Source file: AndroidHttpClient.java

  32 
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

  32 
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 ptest-server, under directory /src/main/java/com/mnxfst/testing/client/.

Source file: TSClientPlanResultCollectCallable.java

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

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

Source file: GeoStore.java

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

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

Source file: HttpHelper.java

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

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

Source file: HttpHelper.java

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

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

Source file: G2Client.java

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

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

Source file: ZenossAPIv2.java

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

From project sched-assist, under directory /sched-assist-spi-caldav/src/main/java/org/jasig/schedassist/impl/caldav/.

Source file: SchemeRegistryProvider.java

  32 
vote

/** 
 * @see SchemeRegistryFactory#createDefault()
 * @param schemeName
 * @param port
 * @param useSsl
 * @return
 */
public static SchemeRegistry createSchemeRegistry(String schemeName,int port,boolean useSsl){
  SchemeRegistry registry=SchemeRegistryFactory.createDefault();
  if (useSsl) {
    registry.register(new Scheme(schemeName,port,SSLSocketFactory.getSocketFactory()));
  }
 else {
    registry.register(new Scheme(schemeName,port,PlainSocketFactory.getSocketFactory()));
  }
  return registry;
}
 

Example 37

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

Source file: Network.java

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

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

Source file: AndroidHttpClient.java

  32 
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 spark, under directory /spark-http-client/src/main/java/spark/protocol/.

Source file: ProtocolDataSource.java

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

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

Source file: HttpComponentsClientHttpRequestFactory.java

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

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

Source file: RESTMusicService.java

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

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

Source file: RESTMusicService.java

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

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

Source file: RESTMusicService.java

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

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

Source file: RESTMusicService.java

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

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

Source file: RESTMusicService.java

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

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

Source file: XMLRPCClient.java

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

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

Source file: ServerConnection.java

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

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

Source file: WeaveTransport.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: HttpUtils.java

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

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

Source file: Urllib.java

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

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

Source file: AbstractAjaxCallback.java

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

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

Source file: ConnectionOAuth.java

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

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

Source file: ConnectionOAuth.java

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

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

Source file: NetTest.java

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

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

Source file: GSRestClient.java

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

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

Source file: HttpClientFactory.java

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

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

Source file: Session.java

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

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

Source file: HttpClientFactory.java

  31 
vote

public static HttpClient create(CRestConfig crestConfig,Class<?> source){
  HttpClient httpClient=crestConfig.get(source.getName() + HTTP_CLIENT);
  if (httpClient != null) {
    return httpClient;
  }
  int concurrencyLevel=crestConfig.getConcurrencyLevel();
  if (concurrencyLevel > 1) {
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    ConnManagerParams.setMaxConnectionsPerRoute(params,new ConnPerRouteBean(concurrencyLevel));
    ConnManagerParams.setMaxTotalConnections(params,concurrencyLevel);
    SchemeRegistry schemeRegistry=new SchemeRegistry();
    schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),HTTP_PORT));
    schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),HTTPS_PORT));
    ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
    httpClient=new DefaultHttpClient(cm,params);
  }
 else {
    httpClient=new DefaultHttpClient();
  }
  ((DefaultHttpClient)httpClient).setRoutePlanner(new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()));
  return httpClient;
}
 

Example 60

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

Source file: NetworkHelper.java

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

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

Source file: BetterHttp.java

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

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

Source file: OperatorConnectDirect.java

  31 
vote

public static void main(String[] args) throws Exception {
  HttpHost target=new HttpHost("jakarta.apache.org",80,"http");
  SchemeRegistry supportedSchemes=new SchemeRegistry();
  supportedSchemes.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  HttpParams params=new SyncBasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUseExpectContinue(params,false);
  ClientConnectionOperator scop=new DefaultClientConnectionOperator(supportedSchemes);
  HttpRequest req=new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1);
  req.addHeader("Host",target.getHostName());
  HttpContext ctx=new BasicHttpContext();
  OperatedClientConnection conn=scop.createConnection();
  try {
    System.out.println("opening connection to " + target);
    scop.openConnection(conn,target,null,ctx,params);
    System.out.println("sending request");
    conn.sendRequestHeader(req);
    conn.flush();
    System.out.println("receiving response header");
    HttpResponse rsp=conn.receiveResponseHeader();
    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    Header[] headers=rsp.getAllHeaders();
    for (int i=0; i < headers.length; i++) {
      System.out.println(headers[i]);
    }
    System.out.println("----------------------------------------");
  }
  finally {
    System.out.println("closing connection");
    conn.close();
  }
}
 

Example 63

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

Source file: TwAjax.java

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

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

Source file: IgnitedHttp.java

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

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

Source file: OperatorConnectDirect.java

  31 
vote

public static void main(String[] args) throws Exception {
  HttpHost target=new HttpHost("jakarta.apache.org",80,"http");
  SchemeRegistry supportedSchemes=new SchemeRegistry();
  supportedSchemes.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  HttpParams params=new SyncBasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUseExpectContinue(params,false);
  ClientConnectionOperator scop=new DefaultClientConnectionOperator(supportedSchemes);
  HttpRequest req=new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1);
  req.addHeader("Host",target.getHostName());
  HttpContext ctx=new BasicHttpContext();
  OperatedClientConnection conn=scop.createConnection();
  try {
    System.out.println("opening connection to " + target);
    scop.openConnection(conn,target,null,ctx,params);
    System.out.println("sending request");
    conn.sendRequestHeader(req);
    conn.flush();
    System.out.println("receiving response header");
    HttpResponse rsp=conn.receiveResponseHeader();
    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    Header[] headers=rsp.getAllHeaders();
    for (int i=0; i < headers.length; i++) {
      System.out.println(headers[i]);
    }
    System.out.println("----------------------------------------");
  }
  finally {
    System.out.println("closing connection");
    conn.close();
  }
}
 

Example 66

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

Source file: HttpClientConfigurer.java

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

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

Source file: AndroidCompatibleRestClient.java

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

From project k-9, under directory /src/com/fsck/k9/mail/store/.

Source file: WebDavStore.java

  31 
vote

public WebDavHttpClient getHttpClient() throws MessagingException {
  if (mHttpClient == null) {
    mHttpClient=new WebDavHttpClient();
    mHttpClient.getParams().setBooleanParameter("http.protocol.handle-redirects",false);
    mContext=new BasicHttpContext();
    mAuthCookies=new BasicCookieStore();
    mContext.setAttribute(ClientContext.COOKIE_STORE,mAuthCookies);
    SchemeRegistry reg=mHttpClient.getConnectionManager().getSchemeRegistry();
    try {
      Scheme s=new Scheme("https",new TrustedSocketFactory(mHost,mSecure),443);
      reg.register(s);
    }
 catch (    NoSuchAlgorithmException nsa) {
      Log.e(K9.LOG_TAG,"NoSuchAlgorithmException in getHttpClient: " + nsa);
      throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
    }
catch (    KeyManagementException kme) {
      Log.e(K9.LOG_TAG,"KeyManagementException in getHttpClient: " + kme);
      throw new MessagingException("KeyManagementException in getHttpClient: " + kme);
    }
  }
  return mHttpClient;
}
 

Example 69

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

Source file: HttpHelper.java

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

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

Source file: LRClient.java

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

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

Source file: OSLCUtils.java

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

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

Source file: ClienteSeneca.java

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

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

Source file: NonStickySessionsIntegrationTest.java

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

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

Source file: ERASubmissionManager.java

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

From project Mobile-Tour-Guide, under directory /zxing-2.0/zxingorg/src/com/google/zxing/web/.

Source file: DecodeServlet.java

  31 
vote

@Override public void init(ServletConfig servletConfig){
  Logger logger=Logger.getLogger("com.google.zxing");
  logger.addHandler(new ServletContextLogHandler(servletConfig.getServletContext()));
  params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  registry=new SchemeRegistry();
  registry.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  registry.register(new Scheme("https",443,SSLSocketFactory.getSocketFactory()));
  diskFileItemFactory=new DiskFileItemFactory();
  log.info("DecodeServlet configured");
}
 

Example 76

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

Source file: Checkin.java

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

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

Source file: IMifiedDriver.java

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

From project npr-android-app, under directory /src/org/npr/android/news/.

Source file: StreamProxy.java

  31 
vote

private HttpResponse download(String url){
  DefaultHttpClient seed=new DefaultHttpClient();
  SchemeRegistry registry=new SchemeRegistry();
  registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  SingleClientConnManager mgr=new MyClientConnManager(seed.getParams(),registry);
  DefaultHttpClient http=new DefaultHttpClient(mgr,seed.getParams());
  HttpGet method=new HttpGet(url);
  HttpResponse response=null;
  try {
    Log.d(LOG_TAG,"starting download");
    response=http.execute(method);
    Log.d(LOG_TAG,"downloaded");
  }
 catch (  ClientProtocolException e) {
    Log.e(LOG_TAG,"Error downloading",e);
  }
catch (  IOException e) {
    Log.e(LOG_TAG,"Error downloading",e);
  }
  return response;
}
 

Example 79

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

Source file: PackageDownloader.java

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

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

Source file: BetterHttp.java

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

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

Source file: SSLUtils.java

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

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

Source file: GlassfishDerbyTest.java

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

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

Source file: SslEchoTest.java

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

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

Source file: DefaultHttpClient.java

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

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

Source file: ShifterProvisioner.java

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

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

Source file: ProxyServlet.java

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

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

Source file: BetterHttp.java

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

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

Source file: HttpTransport.java

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

From project repose, under directory /project-set/core/core-lib/src/main/java/com/rackspace/papi/service/proxy/httpcomponent/.

Source file: RequestProxyServiceImpl.java

  31 
vote

private HttpClient getClient(){
synchronized (clientLock) {
    if (client == null) {
      LOG.info("Building Apache Components Http v4 Client");
      manager=new PoolingClientConnectionManager();
      manager.setMaxTotal(proxyThreadPool);
      manager.setDefaultMaxPerRoute(proxyThreadPool);
      SSLContext sslContext=ProxyUtilities.getTrustingSslContext();
      SSLSocketFactory ssf=new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      SchemeRegistry registry=manager.getSchemeRegistry();
      Scheme scheme=new Scheme("https",DEFAULT_HTTPS_PORT,ssf);
      registry.register(scheme);
      client=new DefaultHttpClient(manager);
      client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,false);
      client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT,readTimeout);
      client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeout);
    }
    return client;
  }
}
 

Example 90

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

Source file: HttpsClientDecorator.java

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

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

Source file: DestinationServiceImpl.java

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

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

Source file: MainHttpClient.java

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

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

Source file: Checkin.java

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

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

Source file: HttpFetchingImageStore.java

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

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

Source file: MainHttpClient.java

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

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

Source file: MmsCommunication.java

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

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

Source file: HttpClientImpl.java

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

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

Source file: MainHttpClient.java

  31 
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);
}
 

Example 99

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

Source file: AbstractHttpClientFactory.java

  31 
vote

protected static SchemeRegistry createSchemeRegistry(){
  final SchemeRegistry sr=new SchemeRegistry();
  sr.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  SSLContext ctx;
  try {
    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 X509TrustManager[]{tm},null);
    SSLSocketFactory ssf=new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    sr.register(new Scheme("https",443,ssf));
  }
 catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
catch (  KeyManagementException e) {
    e.printStackTrace();
  }
  return sr;
}
 

Example 100

From project wip, under directory /src/main/java/fr/ippon/wip/http/hc/.

Source file: HttpClientResourceManager.java

  31 
vote

private HttpClientResourceManager(){
  perUserClientMap=Collections.synchronizedMap(new HashMap<String,HttpClient>());
  perUserCookieStoreMap=Collections.synchronizedMap(new HashMap<String,CookieStore>());
  perUserWindowCredentialProviderMap=Collections.synchronizedMap(new HashMap<String,CredentialsProvider>());
  currentPortletRequest=new ThreadLocal<PortletRequest>();
  currentPortletResponse=new ThreadLocal<PortletResponse>();
  currentRequest=new ThreadLocal<RequestBuilder>();
  try {
    SSLSocketFactory ssf=new SSLSocketFactory(new TrustSelfSignedStrategy(),new AllowAllHostnameVerifier());
    Scheme httpsScheme=new Scheme("https",443,ssf);
    PlainSocketFactory psf=new PlainSocketFactory();
    Scheme httpScheme=new Scheme("http",80,psf);
    SchemeRegistry registry=new SchemeRegistry();
    registry.register(httpsScheme);
    registry.register(httpScheme);
    connectionManager=new PoolingClientConnectionManager(registry);
    connectionManager.setDefaultMaxPerRoute(10);
    connectionManager.setMaxTotal(100);
    DefaultHttpClient defaultHttpClient=new DefaultHttpClient(connectionManager);
    defaultHttpClient.setRedirectStrategy(new LaxRedirectStrategy());
    CacheConfig cacheConfig=createAndConfigureCache();
    URL ehCacheConfig=getClass().getResource("/ehcache.xml");
    cacheManager=CacheManager.create(ehCacheConfig);
    Ehcache ehcache=cacheManager.getEhcache("public");
    EhcacheHttpCacheStorage httpCacheStorage=new EhcacheHttpCacheStorage(ehcache);
    CachingHttpClient sharedCacheClient=new CachingHttpClient(defaultHttpClient,httpCacheStorage,cacheConfig);
    HttpClientDecorator decoratedClient=new HttpClientDecorator(sharedCacheClient);
    decoratedClient.addPreProcessor(new LtpaRequestInterceptor());
    decoratedClient.addPreProcessor(new StaleIfErrorRequestInterceptor(staleIfErrorTime));
    decoratedClient.addFilter(new IgnoreHttpRequestFilter());
    decoratedClient.addPostProcessor(new TransformerResponseInterceptor());
    rootClient=decoratedClient;
  }
 catch (  Exception e) {
    throw new RuntimeException("Could not initialize connection manager",e);
  }
}
 

Example 101

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

Source file: SSLHttpClientFactory.java

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

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

Source file: OperatorConnectDirect.java

  31 
vote

public static void main(String[] args) throws Exception {
  HttpHost target=new HttpHost("jakarta.apache.org",80,"http");
  SchemeRegistry supportedSchemes=new SchemeRegistry();
  supportedSchemes.register(new Scheme("http",80,PlainSocketFactory.getSocketFactory()));
  HttpParams params=new SyncBasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUseExpectContinue(params,false);
  ClientConnectionOperator scop=new DefaultClientConnectionOperator(supportedSchemes);
  HttpRequest req=new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1);
  req.addHeader("Host",target.getHostName());
  HttpContext ctx=new BasicHttpContext();
  OperatedClientConnection conn=scop.createConnection();
  try {
    System.out.println("opening connection to " + target);
    scop.openConnection(conn,target,null,ctx,params);
    System.out.println("sending request");
    conn.sendRequestHeader(req);
    conn.flush();
    System.out.println("receiving response header");
    HttpResponse rsp=conn.receiveResponseHeader();
    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    Header[] headers=rsp.getAllHeaders();
    for (int i=0; i < headers.length; i++) {
      System.out.println(headers[i]);
    }
    System.out.println("----------------------------------------");
  }
  finally {
    System.out.println("closing connection");
    conn.close();
  }
}
 

Example 103

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

Source file: AndroidHttpClient.java

  31 
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);
}