Java Code Examples for org.apache.http.params.HttpProtocolParams

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 4308Cirrus, under directory /tendril-android-lib/src/main/java/edu/colorado/cs/cirrus/android/.

Source file: HttpUtils.java

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

From project accesointeligente, under directory /src/org/accesointeligente/server/robots/.

Source file: SGS.java

  19 
vote

public SGS(){
  client=new DefaultHttpClient();
  HttpProtocolParams.setUserAgent(client.getParams(),"Mozilla/5.0 (X11; U; Linux x86_64; es-CL; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.10 (maverick) Firefox/3.6.12");
  HttpProtocolParams.setVersion(client.getParams(),HttpVersion.HTTP_1_0);
  cleaner=new HtmlCleaner();
}
 

Example 3

From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.

Source file: CatchAPI.java

  19 
vote

private HttpClient getHttpClientNoToken(){
  if (httpClientNoToken == null) {
    HttpParams params=new BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(params,userAgent);
    HttpProtocolParams.setContentCharset(params,"UTF-8");
    httpClientNoToken=new DefaultHttpClient(params);
  }
  return httpClientNoToken;
}
 

Example 4

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

Source file: Urllib.java

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

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

Source file: ApacheHCHttpCommandExecutorServiceModule.java

  19 
vote

@Singleton @Provides HttpParams newBasicHttpParams(HttpUtils utils){
  BasicHttpParams params=new BasicHttpParams();
  params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,true).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true).setParameter(CoreProtocolPNames.ORIGIN_SERVER,"jclouds/1.0");
  if (utils.getConnectionTimeout() > 0) {
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,utils.getConnectionTimeout());
  }
  if (utils.getSocketOpenTimeout() > 0) {
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,utils.getSocketOpenTimeout());
  }
  if (utils.getMaxConnections() > 0)   ConnManagerParams.setMaxTotalConnections(params,utils.getMaxConnections());
  if (utils.getMaxConnectionsPerHost() > 0) {
    ConnPerRoute connectionsPerRoute=new ConnPerRouteBean(utils.getMaxConnectionsPerHost());
    ConnManagerParams.setMaxConnectionsPerRoute(params,connectionsPerRoute);
  }
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  return params;
}
 

Example 6

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/google/.

Source file: GoogleSuggestClient.java

  19 
vote

public GoogleSuggestClient(Context context){
  super(context);
  mHttpClient=new DefaultHttpClient();
  HttpParams params=mHttpClient.getParams();
  HttpProtocolParams.setUserAgent(params,USER_AGENT);
  params.setLongParameter(HTTP_TIMEOUT,HTTP_TIMEOUT_MS);
  mSuggestUri=null;
}
 

Example 7

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

Source file: ConnectionOAuth.java

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

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

Source file: ConnectionOAuth.java

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

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

Source file: Flickr.java

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

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 11

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 12

From project build-info, under directory /build-info-client/src/main/java/org/jfrog/build/client/.

Source file: PreemptiveHttpClient.java

  19 
vote

private DefaultHttpClient createHttpClient(String userName,String password,int timeout){
  BasicHttpParams params=new BasicHttpParams();
  int timeoutMilliSeconds=timeout * 1000;
  HttpConnectionParams.setConnectionTimeout(params,timeoutMilliSeconds);
  HttpConnectionParams.setSoTimeout(params,timeoutMilliSeconds);
  DefaultHttpClient client=new DefaultHttpClient(params);
  if (userName != null && !"".equals(userName)) {
    client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST,AuthScope.ANY_PORT),new UsernamePasswordCredentials(userName,password));
    localContext=new BasicHttpContext();
    BasicScheme basicAuth=new BasicScheme();
    localContext.setAttribute("preemptive-auth",basicAuth);
    client.addRequestInterceptor(new PreemptiveAuth(),0);
  }
  String userAgent="ArtifactoryBuildClient/" + CLIENT_VERSION;
  HttpProtocolParams.setUserAgent(client.getParams(),userAgent);
  return client;
}
 

Example 13

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

Source file: JBossURLFetchService.java

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

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

Source file: ServerProxyHandler.java

  19 
vote

/** 
 * Get client.
 * @return the client
 */
private synchronized HttpClient getClient(){
  if (client == null) {
    HttpParams params=createHttpParams();
    HttpProtocolParams.setVersion(params,config.getHttpVersion());
    HttpProtocolParams.setContentCharset(params,config.getContentCharset());
    HttpProtocolParams.setUseExpectContinue(params,config.isExpectContinue());
    HttpConnectionParams.setStaleCheckingEnabled(params,config.isStaleCheckingEnabled());
    HttpConnectionParams.setConnectionTimeout(params,config.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(params,config.getSoTimeout());
    HttpConnectionParams.setSocketBufferSize(params,config.getSocketBufferSize());
    SchemeRegistry schemeRegistry=createSchemeRegistry();
    ClientConnectionManager ccm=createClientConnectionManager(params,schemeRegistry);
    HttpClient tmp=createClient(ccm,params);
    String username=config.getUsername();
    String password=config.getPassword();
    if (username != null && password != null) {
      if (tmp instanceof AbstractHttpClient) {
        CredentialsProvider credsProvider=AbstractHttpClient.class.cast(tmp).getCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(config.getHostName(),config.getSslPort()),new UsernamePasswordCredentials(username,password));
      }
 else {
        Logger.getLogger(getClass().getName()).warning("Cannot set CredentialsProvider on HttpClient: " + tmp);
      }
    }
    client=tmp;
  }
  return client;
}
 

Example 15

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

Source file: GSRestClient.java

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

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

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 17

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

Source file: HttpClientFactory.java

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

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

Source file: HttpClientFactory.java

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

From project dccsched, under directory /src/com/underhilllabs/dccsched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 20

From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 21

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

Source file: HttpClientFactory.java

  19 
vote

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

Example 22

From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/service/.

Source file: RestService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 23

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

Source file: NetworkHelper.java

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

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

Source file: BetterHttp.java

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

From project droidparts, under directory /extra/src/org/droidparts/http/wrapper/.

Source file: DefaultHttpClientWrapper.java

  19 
vote

public DefaultHttpClientWrapper(String userAgent){
  super(userAgent);
  httpClient=new DefaultHttpClient();
  HttpParams params=httpClient.getParams();
  HttpConnectionParams.setConnectionTimeout(params,SOCKET_OPERATION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_OPERATION_TIMEOUT);
  HttpConnectionParams.setSocketBufferSize(params,BUFFER_SIZE);
  if (userAgent != null) {
    HttpProtocolParams.setUserAgent(params,userAgent);
  }
}
 

Example 26

From project evodroid, under directory /src/com/sonorth/evodroid/.

Source file: Read.java

  19 
vote

public boolean onOptionsItemSelected(final MenuItem item){
switch (item.getItemId()) {
case 0:
    finish();
  break;
case 1:
if (!wv.getUrl().contains("b2evo-login.php")) {
  Intent i=new Intent(Intent.ACTION_VIEW);
  i.setData(Uri.parse(wv.getUrl()));
  startActivity(i);
}
break;
case 2:
wv.reload();
new Thread(new Runnable(){
public void run(){
try {
HttpClient httpclient=new DefaultHttpClient();
HttpProtocolParams.setUserAgent(httpclient.getParams(),"evodroid");
String readerURL=Constants.readerURL + "/?template=stats&stats_name=home_page_refresh";
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4) {
  readerURL+="&per_page=20";
}
httpclient.execute(new HttpGet(readerURL));
}
 catch (Exception e) {
}
}
}
).start();
break;
}
return false;
}
 

Example 27

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

Source file: HttpClient.java

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

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

Source file: HttpDispatcherImpl_Jakarta.java

  19 
vote

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

Example 29

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

Source file: OperatorConnectDirect.java

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

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

Source file: TwAjax.java

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

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

Source file: AndroidHttpClient.java

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

From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 33

From project generic-store-for-android, under directory /src/com/wareninja/opensource/common/.

Source file: CustomBugSenseReportSender.java

  19 
vote

private void submitError(String hash,String data){
  DefaultHttpClient httpClient=new DefaultHttpClient();
  HttpParams params=httpClient.getParams();
  HttpProtocolParams.setUseExpectContinue(params,false);
  HttpConnectionParams.setConnectionTimeout(params,TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,TIMEOUT);
  HttpPost httpPost=new HttpPost(bugSenseEndPoint);
  httpPost.addHeader("X-BugSense-Api-Key",bugSenseApiKey);
  List<NameValuePair> nvps=new ArrayList<NameValuePair>();
  nvps.add(new BasicNameValuePair("data",data));
  nvps.add(new BasicNameValuePair("hash",hash));
  try {
    httpPost.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8));
    HttpResponse response=httpClient.execute(httpPost);
    HttpEntity entity=response.getEntity();
    Log.d(TAG,"entity : " + entity);
  }
 catch (  Exception ex) {
    Log.e(TAG,"Error sending exception stacktrace",ex);
  }
}
 

Example 34

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

Source file: AsyncHTTPBuilder.java

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

From project httpClient, under directory /httpclient/src/examples/org/apache/http/examples/conn/.

Source file: OperatorConnectDirect.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: IgnitedHttp.java

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

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

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

From project iosched, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 40

From project iosched2011, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 41

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

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 42

From project iosched_2, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 43

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

Source file: AndroidCompatibleRestClient.java

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

From project javaee-tutorial, under directory /jaxrs/android/src/org/jboss/ee/tutorial/jaxrs/android/data/.

Source file: LibraryHttpClient.java

  19 
vote

public LibraryHttpClient(Context context){
  this.context=context;
  BasicHttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(params,false);
  httpClient=new DefaultHttpClient(params);
}
 

Example 45

From project jena-fuseki, under directory /src/main/java/org/apache/jena/fuseki/http/.

Source file: DatasetGraphAccessorHTTP.java

  19 
vote

static private HttpParams createHttpParams(){
  HttpParams httpParams$=new BasicHttpParams();
  HttpProtocolParams.setVersion(httpParams$,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(httpParams$,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(httpParams$,true);
  HttpConnectionParams.setTcpNoDelay(httpParams$,true);
  HttpConnectionParams.setSocketBufferSize(httpParams$,32 * 1024);
  HttpProtocolParams.setUserAgent(httpParams$,Fuseki.NAME + "/" + Fuseki.VERSION);
  return httpParams$;
}
 

Example 46

From project Jenkins-Repository, under directory /jenkins-maven-plugin/src/main/java/com/nirima/jenkins/.

Source file: SimpleArtifactCopier.java

  19 
vote

private void init() throws URISyntaxException {
  URI targetURI=host.toURI();
  targetHost=new HttpHost(targetURI.getHost(),targetURI.getPort());
  params=new BasicHttpParams();
  params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
  params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,false);
  params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,false);
  params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,8 * 1024);
  httpexecutor=new HttpRequestExecutor();
  httpproc=new BasicHttpProcessor();
  httpproc.addInterceptor(new RequestContent());
  httpproc.addInterceptor(new RequestTargetHost());
  httpproc.addInterceptor(new RequestConnControl());
  httpproc.addInterceptor(new RequestUserAgent());
  httpproc.addInterceptor(new RequestExpectContinue());
  context=new BasicHttpContext();
  conn=new DefaultHttpClientConnection();
  connStrategy=new DefaultConnectionReuseStrategy();
}
 

Example 47

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

Source file: HttpHelper.java

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

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

Source file: NetworkClient.java

  19 
vote

@Override protected HttpParams createHttpParams(){
  final HttpParams params=super.createHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUseExpectContinue(params,true);
  String appVersion="unknown";
  try {
    appVersion=mContext.getPackageManager().getPackageInfo(mContext.getPackageName(),0).versionName;
  }
 catch (  final NameNotFoundException e) {
    Log.e(TAG,e.getLocalizedMessage(),e);
  }
  final String userAgent=mContext.getString(R.string.app_name) + "/" + appVersion;
  HttpProtocolParams.setUserAgent(params,userAgent);
  return params;
}
 

Example 49

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

Source file: LRClient.java

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

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

Source file: ClienteSeneca.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: DecodeServlet.java

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

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

Source file: Checkin.java

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

From project netifera, under directory /platform/com.netifera.platform.net.http/com.netifera.platform.net.http.service/src/com/netifera/platform/net/http/service/.

Source file: HTTPClient.java

  19 
vote

public HttpResponse execute(HttpRequest request) throws IOException, HttpException {
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,"UTF-8");
  HttpProtocolParams.setUserAgent(params,DEFAULT_USER_AGENT);
  HttpProtocolParams.setUseExpectContinue(params,true);
  BasicHttpProcessor processor=new BasicHttpProcessor();
  processor.addInterceptor(new RequestContent());
  processor.addInterceptor(new RequestConnControl());
  processor.addInterceptor(new RequestUserAgent());
  processor.addInterceptor(new RequestExpectContinue());
  HttpRequestExecutor executor=new HttpRequestExecutor();
  HttpContext context=new BasicHttpContext(null);
  context.setAttribute(ExecutionContext.HTTP_CONNECTION,connection);
  if (!connection.isOpen()) {
    Socket socket=new Socket(locator.getAddress().toInetAddress(),locator.getPort());
    connection.bind(socket,params);
  }
  context.setAttribute(ExecutionContext.HTTP_REQUEST,request);
  request.setParams(params);
  executor.preProcess(request,processor,context);
  HttpResponse response=executor.execute(request,connection,context);
  executor.postProcess(response,processor,context);
  return response;
}
 

Example 55

From project nuxeo-android, under directory /nuxeo-android-connector/src/main/java/org/nuxeo/ecm/automation/client/android/.

Source file: AndroidAutomationClient.java

  19 
vote

public AndroidAutomationClient(String url,Context androidContext,SQLStateManager sqlStateManager,BlobStoreManager blobStoreManager,NuxeoNetworkStatus offlineSettings,NuxeoServerConfig serverConfig){
  super(url);
  this.http=AndroidHttpClient.newInstance("Nuxeo Android Client",null);
  HttpProtocolParams.setUseExpectContinue(http.getParams(),false);
  this.sqlStateManager=sqlStateManager;
  this.blobStoreManager=blobStoreManager;
  this.responseCacheManager=new AndroidResponseCacheManager(sqlStateManager,blobStoreManager);
  this.deferredUpdatetManager=new AndroidDeferredUpdateManager(sqlStateManager);
  this.networkStatus=offlineSettings;
  this.androidContext=androidContext;
  this.messageHelper=new AndroidMessageHelper(androidContext);
  this.transientStateManager=new AndroidTransientStateManager(androidContext,sqlStateManager);
  this.documentProvider=new AndroidDocumentProvider(sqlStateManager);
  this.fileDownloader=new FileDownloader(this);
  this.serverConfig=serverConfig;
  this.fileUploader=new FileUploader(this);
  this.layoutService=new AndroidLayoutService(fileDownloader);
}
 

Example 56

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

Source file: PackageDownloader.java

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

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

Source file: BetterHttp.java

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

From project OpenBike, under directory /src/fr/openbike/android/service/.

Source file: SyncService.java

  19 
vote

/** 
 * Generate and return a  {@link HttpClient} configured for general use,including setting an application-specific user-agent string.
 */
public static HttpClient getHttpClient(Context context){
  final HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSoTimeout(params,20 * SECOND_IN_MILLIS);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpProtocolParams.setUserAgent(params,buildUserAgent(context));
  final DefaultHttpClient client=new DefaultHttpClient(params);
  client.addRequestInterceptor(new HttpRequestInterceptor(){
    public void process(    HttpRequest request,    HttpContext context){
      if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
        request.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);
      }
    }
  }
);
  client.addResponseInterceptor(new HttpResponseInterceptor(){
    public void process(    HttpResponse response,    HttpContext context){
      final HttpEntity entity=response.getEntity();
      final Header encoding=entity.getContentEncoding();
      if (encoding != null) {
        for (        HeaderElement element : encoding.getElements()) {
          if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
            response.setEntity(new InflatingEntity(response.getEntity()));
            break;
          }
        }
      }
    }
  }
);
  return client;
}
 

Example 59

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

Source file: SSLUtils.java

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

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

Source file: XMLRPCClient.java

  19 
vote

/** 
 * XMLRPCClient constructor. Creates new instance based on server URI
 * @param XMLRPC server URI
 */
public XMLRPCClient(URI uri){
  postMethod=new HttpPost(uri);
  postMethod.addHeader("Content-Type","text/xml");
  httpParams=postMethod.getParams();
  HttpProtocolParams.setUseExpectContinue(httpParams,false);
  client=new DefaultHttpClient();
  serializer=Xml.newSerializer();
}
 

Example 61

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

Source file: AnonProxy.java

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

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

Source file: XMLRPCClient.java

  19 
vote

/** 
 * XMLRPCClient constructor. Creates new instance based on server URI
 * @param XMLRPC server URI
 */
public XMLRPCClient(URI uri){
  postMethod=new HttpPost(uri);
  postMethod.addHeader("Content-Type","text/xml");
  httpParams=postMethod.getParams();
  HttpProtocolParams.setUseExpectContinue(httpParams,false);
  client=new DefaultHttpClient();
}
 

Example 63

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

Source file: AndroidHttpClient.java

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

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

Source file: HttpClientFactory.java

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

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

Source file: DefaultHttpClient.java

  19 
vote

@Override protected HttpParams createHttpParams(){
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setContentCharset(params,HTTP.DEFAULT_CONTENT_CHARSET);
  HttpProtocolParams.setUseExpectContinue(params,false);
  final VersionInfo vi=VersionInfo.loadVersionInfo("org.apache.http.client",getClass().getClassLoader());
  final String release=(vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
  HttpProtocolParams.setUserAgent(params,"Apache-HttpClient/" + release + " (java 1.4)");
  return params;
}
 

Example 66

From project platform_packages_apps_mms, under directory /src/com/android/mms/transaction/.

Source file: HttpUtils.java

  19 
vote

private static AndroidHttpClient createHttpClient(Context context){
  String userAgent=MmsConfig.getUserAgent();
  AndroidHttpClient client=AndroidHttpClient.newInstance(userAgent,context);
  HttpParams params=client.getParams();
  HttpProtocolParams.setContentCharset(params,"UTF-8");
  int soTimeout=MmsConfig.getHttpSocketTimeout();
  if (Log.isLoggable(LogTag.TRANSACTION,Log.DEBUG)) {
    Log.d(TAG,"[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, "+ ", UA="+ userAgent);
  }
  HttpConnectionParams.setSoTimeout(params,soTimeout);
  return client;
}
 

Example 67

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

Source file: AndroidHttpClient.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: BetterHttp.java

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

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

Source file: HttpHelper.java

  19 
vote

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

Example 71

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

Source file: ClientEvictExpiredConnections.java

  19 
vote

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

Example 72

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

Source file: HttpHelper.java

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

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

Source file: HttpHelper.java

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

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

Source file: G2Client.java

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

From project rundeck-api-java-client, under directory /src/main/java/org/rundeck/api/.

Source file: ApiCall.java

  19 
vote

/** 
 * Instantiate a new  {@link HttpClient} instance, configured to accept all SSL certificates
 * @return an {@link HttpClient} instance - won't be null
 */
private HttpClient instantiateHttpClient(){
  DefaultHttpClient httpClient=new DefaultHttpClient();
  HttpProtocolParams.setUserAgent(httpClient.getParams(),"RunDeck API Java Client " + RundeckClient.API_VERSION);
  SSLSocketFactory socketFactory=null;
  try {
    socketFactory=new SSLSocketFactory(new TrustStrategy(){
      @Override public boolean isTrusted(      X509Certificate[] chain,      String authType) throws CertificateException {
        return true;
      }
    }
,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  }
 catch (  KeyManagementException e) {
    throw new RuntimeException(e);
  }
catch (  UnrecoverableKeyException e) {
    throw new RuntimeException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
catch (  KeyStoreException e) {
    throw new RuntimeException(e);
  }
  httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https",443,socketFactory));
  System.setProperty("java.net.useSystemProxies","true");
  httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault()));
  httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
    @Override public void process(    HttpRequest request,    HttpContext context) throws HttpException, IOException {
      if (client.getToken() != null) {
        request.addHeader(AUTH_TOKEN_HEADER,client.getToken());
      }
    }
  }
);
  return httpClient;
}
 

Example 76

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

Source file: SaldoHttpClient.java

  19 
vote

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

Example 77

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

Source file: Network.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: MainHttpClient.java

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

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

Source file: ProtocolDataSource.java

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

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

Source file: Checkin.java

  19 
vote

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

Example 82

From project spring-social, under directory /spring-social-core/src/main/java/org/springframework/social/support/.

Source file: ClientHttpRequestFactorySelector.java

  19 
vote

public static ClientHttpRequestFactory createRequestFactory(String proxyHost,int proxyPort){
  HttpComponentsClientHttpRequestFactory requestFactory=new HttpComponentsClientHttpRequestFactory(){
    @Override protected void postProcessHttpRequest(    HttpUriRequest request){
      HttpProtocolParams.setUseExpectContinue(request.getParams(),false);
    }
  }
;
  if (proxyHost != null) {
    DefaultHttpClient httpClient=new DefaultHttpClient();
    HttpHost proxy=new HttpHost(proxyHost,proxyPort);
    httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
    requestFactory.setHttpClient(httpClient);
  }
  return requestFactory;
}
 

Example 83

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

Source file: MainHttpClient.java

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

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

Source file: FeedGetMethodFactory.java

  19 
vote

@NotNull public HttpGet createGet(@NotNull final String url,NameValuePair... getParams){
  String argz=URLEncodedUtils.format(Arrays.asList(getParams),HTTP.ISO_8859_1);
  if (argz.length() > 0) {
    argz=(url.contains("?") ? "&" : "?") + argz;
  }
  final HttpGet get=new HttpGet(url + argz);
  HttpProtocolParams.setVersion(get.getParams(),HttpVersion.HTTP_1_1);
  return get;
}
 

Example 85

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

Source file: MmsCommunication.java

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

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

Source file: XMLRPCClient.java

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

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

Source file: ServerConnection.java

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

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

Source file: MainHttpClient.java

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

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

Source file: ProxyTransactionManipulator.java

  19 
vote

@Override public synchronized void process(HttpRequest request){
  if (userAgent != null) {
    if (userAgentOverride != false) {
      request.setHeader(new BasicHeader("User-Agent",userAgent));
    }
 else {
      HttpProtocolParams.setUserAgent(request.getParams(),userAgent);
    }
  }
  if (disableBrowserCache) {
    for (    String header : CONDITIONAL_REQUEST_HEADERS) {
      request.removeHeaders(header);
    }
  }
  if (disableProxyCache) {
    request.setHeader(new BasicHeader("Cache-Control","no-cache"));
    request.setHeader(new BasicHeader("Pragma","no-cache"));
  }
}
 

Example 90

From project Wordpress-Android-App, under directory /src/org/wordpress/android/.

Source file: Read.java

  19 
vote

public boolean onOptionsItemSelected(final MenuItem item){
switch (item.getItemId()) {
case 0:
    finish();
  break;
case 1:
if (!wv.getUrl().contains("wp-login.php")) {
  Intent i=new Intent(Intent.ACTION_VIEW);
  i.setData(Uri.parse(wv.getUrl()));
  startActivity(i);
}
break;
case 2:
wv.reload();
new Thread(new Runnable(){
public void run(){
try {
HttpClient httpclient=new DefaultHttpClient();
HttpProtocolParams.setUserAgent(httpclient.getParams(),"wp-android");
String readerURL=Constants.readerURL + "/?template=stats&stats_name=home_page_refresh";
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4) {
  readerURL+="&per_page=20";
}
httpclient.execute(new HttpGet(readerURL));
}
 catch (Exception e) {
}
}
}
).start();
break;
}
return false;
}
 

Example 91

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

Source file: SSLHttpClientFactory.java

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

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

Source file: OperatorConnectDirect.java

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

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

Source file: AndroidHttpClient.java

  19 
vote

/** 
 * Create a new HttpClient with reasonable defaults (which you can update).
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 */
public static AndroidHttpClient newInstance(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20 * 1000);
  HttpConnectionParams.setSoTimeout(params,20 * 1000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClientParams.setRedirecting(params,false);
  if (userAgent != null) {
    HttpProtocolParams.setUserAgent(params,userAgent);
  }
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  ClientConnectionManager manager=new ThreadSafeClientConnManager(params,schemeRegistry);
  return new AndroidHttpClient(manager,params);
}
 

Example 94

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

Source file: AndroidHttpClient.java

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