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

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 and-bible, under directory /jsword-tweaks/src/main/java/jsword/org/crosswire/common/util/.

Source file: WebResource.java

  16 
vote

/** 
 * Construct a WebResource for the given URL, going through the optional proxy and port, while timing out if too much time has passed.
 * @param theURI the Resource to get via HTTP
 * @param theProxyHost the proxy host or null
 * @param theProxyPort the proxy port or null, where null means use the standard port
 * @param theTimeout the length of time in milliseconds to allow a connection to respond before timing out
 */
public WebResource(URI theURI,String theProxyHost,Integer theProxyPort,int theTimeout){
  uri=theURI;
  client=new DefaultHttpClient();
  HttpParams params=client.getParams();
  HttpConnectionParams.setSoTimeout(params,theTimeout);
  HttpConnectionParams.setConnectionTimeout(params,theTimeout);
  if (theProxyHost != null && theProxyHost.length() > 0) {
    HttpHost proxy=new HttpHost(theProxyHost,theProxyPort == null ? -1 : theProxyPort.intValue());
    ConnRouteParams.setDefaultProxy(params,proxy);
    ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault());
    ((AbstractHttpClient)client).setRoutePlanner(routePlanner);
  }
}
 

Example 2

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: HttpClientSingleton.java

  15 
vote

public static HttpClient getInstance(){
  if (instance == null) {
    instance=new DefaultHttpClient();
    HttpParams httpParams=instance.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,Values.TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams,Values.TIMEOUT);
  }
  return instance;
}
 

Example 3

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

Source file: VersionedCatchHttpClient.java

  15 
vote

public PreFroyoCatchHttpClient(String userAgent){
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(params,userAgent);
  HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
  HttpConnectionParams.setStaleCheckingEnabled(params,false);
  HttpConnectionParams.setConnectionTimeout(params,20000);
  HttpConnectionParams.setSoTimeout(params,20000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  mHttpClient=new DefaultHttpClient(params);
}
 

Example 4

From project android-async-http, under directory /src/com/loopj/android/http/.

Source file: AsyncHttpClient.java

  15 
vote

/** 
 * Sets the connection time oout. By default, 10 seconds
 * @param timeout the connect/socket timeout in milliseconds
 */
public void setTimeout(int timeout){
  final HttpParams httpParams=this.httpClient.getParams();
  ConnManagerParams.setTimeout(httpParams,timeout);
  HttpConnectionParams.setSoTimeout(httpParams,timeout);
  HttpConnectionParams.setConnectionTimeout(httpParams,timeout);
}
 

Example 5

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

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 6

From project android-client, under directory /xwiki-android-rest/src/org/xwiki/android/rest/.

Source file: HttpConnector.java

  15 
vote

/** 
 * initialize the general property fields
 */
private void initialize(){
  client=new DefaultHttpClient();
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,10000);
  HttpConnectionParams.setSoTimeout(params,20000);
  client.setParams(params);
}
 

Example 7

From project Android-SyncAdapter-JSON-Server-Example, under directory /src/com/puny/android/network/util/.

Source file: DrupalJSONServerNetworkUtilityBase.java

  15 
vote

/** 
 * Configures the httpClient to connect to the URL provided.
 */
public static void maybeCreateHttpClient(){
  if (mHttpClient == null) {
    mHttpClient=new DefaultHttpClient();
    final HttpParams params=mHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT);
    ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT);
  }
}
 

Example 8

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

Source file: AbstractAjaxCallback.java

  15 
vote

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

Example 9

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.

Source file: EasSyncService.java

  15 
vote

private HttpClient getHttpClient(int timeout){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,timeout);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpClient client=new DefaultHttpClient(getClientConnectionManager(),params);
  return client;
}
 

Example 10

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

Source file: ConnectionBasicAuth.java

  15 
vote

/** 
 * Execute a GET request against the Twitter REST API.
 * @param url
 * @param client
 * @return String
 * @throws ConnectionException
 */
private String getRequest(String url,HttpClient client) throws ConnectionException {
  String result=null;
  int statusCode=0;
  HttpGet getMethod=new HttpGet(url);
  try {
    getMethod.setHeader("User-Agent",USER_AGENT);
    getMethod.addHeader("Authorization","Basic " + getCredentials());
    client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,DEFAULT_GET_REQUEST_TIMEOUT);
    client.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,DEFAULT_GET_REQUEST_TIMEOUT);
    HttpResponse httpResponse=client.execute(getMethod);
    statusCode=httpResponse.getStatusLine().getStatusCode();
    result=retrieveInputStream(httpResponse.getEntity());
  }
 catch (  Exception e) {
    Log.e(TAG,"getRequest: " + e.toString());
    throw new ConnectionException(e);
  }
 finally {
    getMethod.abort();
  }
  parseStatusCode(statusCode,url);
  return result;
}
 

Example 11

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

Source file: ConnectionBasicAuth.java

  15 
vote

/** 
 * Execute a GET request against the Twitter REST API.
 * @param url
 * @param client
 * @return String
 * @throws ConnectionException
 */
private String getRequest(String url,HttpClient client) throws ConnectionException {
  String result=null;
  int statusCode=0;
  HttpGet getMethod=new HttpGet(url);
  try {
    getMethod.setHeader("User-Agent",USER_AGENT);
    getMethod.addHeader("Authorization","Basic " + getCredentials());
    client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,DEFAULT_GET_REQUEST_TIMEOUT);
    client.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,DEFAULT_GET_REQUEST_TIMEOUT);
    HttpResponse httpResponse=client.execute(getMethod);
    statusCode=httpResponse.getStatusLine().getStatusCode();
    result=retrieveInputStream(httpResponse.getEntity());
  }
 catch (  Exception e) {
    Log.e(TAG,"getRequest: " + e.toString());
    throw new ConnectionException(e);
  }
 finally {
    getMethod.abort();
  }
  parseStatusCode(statusCode,url);
  return result;
}
 

Example 12

From project Anki-Android, under directory /src/com/tomgibara/android/veecheck/.

Source file: VeecheckThread.java

  15 
vote

private VeecheckResult performRequest(VeecheckVersion version,String uri) throws ClientProtocolException, IOException, IllegalStateException, SAXException {
  HttpClient client=new DefaultHttpClient();
  HttpParams params=client.getParams();
  HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SO_TIMEOUT);
  HttpGet request=new HttpGet(version.substitute(uri));
  HttpResponse response=client.execute(request);
  HttpEntity entity=response.getEntity();
  try {
    StatusLine line=response.getStatusLine();
    if (line.getStatusCode() != 200) {
      throw new IOException("Request failed: " + line.getReasonPhrase());
    }
    Header header=response.getFirstHeader(HTTP.CONTENT_TYPE);
    Encoding encoding=identityEncoding(header);
    VeecheckResult handler=new VeecheckResult(version);
    Xml.parse(entity.getContent(),encoding,handler);
    return handler;
  }
  finally {
    entity.consumeContent();
  }
}
 

Example 13

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

Source file: SyncService.java

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

From project bbb-java, under directory /src/main/java/org/transdroid/util/.

Source file: FakeSocketFactory.java

  15 
vote

@Override public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 15

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

Source file: SyncService.java

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

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/goodreads/.

Source file: GoodreadsManager.java

  15 
vote

/** 
 * Create an HttpClient with specifically set buffer sizes to deal with potentially exorbitant settings on some HTC handsets.
 * @return
 */
private HttpClient newHttpClient(){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,30000);
  HttpConnectionParams.setSocketBufferSize(params,8192);
  HttpConnectionParams.setLinger(params,0);
  HttpConnectionParams.setTcpNoDelay(params,false);
  HttpClient httpClient=new DefaultHttpClient(params);
  return httpClient;
}
 

Example 17

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

Source file: PreemptiveHttpClient.java

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

From project BusFollower, under directory /src/net/argilo/busfollower/ocdata/.

Source file: OCTranspoDataFetcher.java

  15 
vote

private HttpParams getHttpParams(){
  HttpParams httpParams=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpParams,TIMEOUT_CONNECTION);
  HttpConnectionParams.setSoTimeout(httpParams,TIMEOUT_SOCKET);
  return httpParams;
}
 

Example 19

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

Source file: JBossURLFetchService.java

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

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

Source file: ServerProxyHandler.java

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

From project cmsandroid, under directory /src/com/zia/freshdocs/net/.

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 22

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

Source file: SyncService.java

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

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

Source file: HttpClientFactory.java

  15 
vote

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

Example 24

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

Source file: SyncService.java

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

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

Source file: SyncService.java

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

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

Source file: HttpClientFactory.java

  15 
vote

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

Example 27

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

Source file: RestService.java

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

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

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 29

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

Source file: BetterHttp.java

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

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

Source file: DefaultHttpClientWrapper.java

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

From project E12Planner, under directory /src/com/neoware/europlanner/.

Source file: ReadDataAsyncTask.java

  15 
vote

@Override protected Boolean doInBackground(String... params){
  try {
    HttpClient httpClient=new DefaultHttpClient();
    HttpParams httpParams=httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,30000);
    HttpConnectionParams.setSoTimeout(httpParams,30000);
    HttpGet get=new HttpGet(params[0]);
    mData=httpClient.execute(get,new BasicResponseHandler());
    return true;
  }
 catch (  ClientProtocolException ex) {
    mErrorMessage=ex.getMessage();
  }
catch (  IOException ex) {
    mErrorMessage=ex.getMessage();
  }
  return false;
}
 

Example 32

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

Source file: SocialHttpClientImpl.java

  15 
vote

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

Example 33

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

Source file: HttpClient.java

  15 
vote

/** 
 * Setup HTTPConncetionParams
 * @param method
 */
private void SetupHTTPConnectionParams(HttpUriRequest method){
  HttpConnectionParams.setConnectionTimeout(method.getParams(),CONNECTION_TIMEOUT_MS);
  HttpConnectionParams.setSoTimeout(method.getParams(),SOCKET_TIMEOUT_MS);
  mClient.setHttpRequestRetryHandler(requestRetryHandler);
  method.addHeader("Accept-Encoding","gzip, deflate");
  method.addHeader("Accept-Charset","UTF-8,*;q=0.5");
}
 

Example 34

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

Source file: HttpDispatcherImpl_Jakarta.java

  15 
vote

public void run(HttpComponent component){
  this.commponent=component;
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,component.connectTimeout);
  HttpConnectionParams.setSoTimeout(params,component.readTimeout);
  try {
    this.init(component);
    HttpClient httpclient=new MyHttpClient(getConnectionManager(params,component.enablePersistentConnection),params);
    if (component.enableProxy && "http".equals(component.proxyType)) {
      HttpHost proxy=new HttpHost(component.proxyHost,component.proxyPort,component.proxyType);
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
    }
    HttpUriRequest request=new HttpRequest(component.method,component.uri);
    MyHttpResponseHandler responseHandler=new MyHttpResponseHandler(component.responseCharset);
    String body=httpclient.execute(request,responseHandler);
    this.onResponse(component,responseHandler.code,body);
  }
 catch (  SocketTimeoutException e) {
    onException(component,-2," socket timeout error occurs: " + e.getMessage());
  }
catch (  ClientProtocolException e) {
    onException(component,-3," error resposed from server: " + e.getMessage());
  }
catch (  IOException e) {
    onException(component,-4," error occurs during dispatch: " + e.getMessage());
  }
catch (  Exception e) {
    onException(component,-5,"error occurs during parsing xml:" + e.getMessage());
  }
}
 

Example 35

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

Source file: ClientExecuteSOCKS.java

  15 
vote

public Socket connectSocket(final Socket socket,final InetSocketAddress remoteAddress,final InetSocketAddress localAddress,final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  if (remoteAddress == null) {
    throw new IllegalArgumentException("Remote address may not be null");
  }
  if (params == null) {
    throw new IllegalArgumentException("HTTP parameters may not be null");
  }
  Socket sock;
  if (socket != null) {
    sock=socket;
  }
 else {
    sock=createSocket(params);
  }
  if (localAddress != null) {
    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
    sock.bind(localAddress);
  }
  int timeout=HttpConnectionParams.getConnectionTimeout(params);
  try {
    sock.connect(remoteAddress,timeout);
  }
 catch (  SocketTimeoutException ex) {
    throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"+ remoteAddress.getAddress()+ " timed out");
  }
  return sock;
}
 

Example 36

From project Gaggle, under directory /src/com/geeksville/location/.

Source file: LeonardoUpload.java

  15 
vote

/** 
 * Upload a flight to Leonardo
 * @param username
 * @param password
 * @param postURL
 * @param shortFilename
 * @param igcFile we will take care of closing this stram
 * @return null for success, otherwise a string description of the problem
 * @throws IOException
 */
public static String upload(String username,String password,String postURL,int competitionClass,String shortFilename,String igcFile,int connectionTimeout,int operationTimeout) throws IOException {
  int i=shortFilename.lastIndexOf('.');
  if (i >= 1)   shortFilename=shortFilename.substring(0,i);
  String sCompetitionClass=String.valueOf(competitionClass);
  HttpParams httpParameters=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpParameters,connectionTimeout);
  HttpConnectionParams.setSoTimeout(httpParameters,operationTimeout);
  HttpClient httpclient=new DefaultHttpClient(httpParameters);
  httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,false);
  HttpPost httppost=new HttpPost(postURL);
  List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
  nameValuePairs.add(new BasicNameValuePair("user",username));
  nameValuePairs.add(new BasicNameValuePair("pass",password));
  nameValuePairs.add(new BasicNameValuePair("igcfn",shortFilename));
  nameValuePairs.add(new BasicNameValuePair("Klasse",sCompetitionClass));
  nameValuePairs.add(new BasicNameValuePair("IGCigcIGC",igcFile));
  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  HttpResponse response=httpclient.execute(httppost);
  HttpEntity entity=response.getEntity();
  String resp=EntityUtils.toString(entity);
  if (resp.contains("flight scored"))   resp=null;
 else {
    int bodLoc=resp.indexOf("<body>");
    if (bodLoc >= 0)     resp=resp.substring(bodLoc + 6);
    int probLoc=resp.indexOf("problem");
    if (probLoc >= 0)     resp=resp.substring(probLoc + 7);
    if (resp.startsWith("<br>"))     resp=resp.substring(4);
    int markLoc=resp.indexOf('<');
    if (markLoc >= 0)     resp=resp.substring(0,markLoc);
    resp=resp.trim();
  }
  return resp;
}
 

Example 37

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

Source file: AndroidHttpClient.java

  15 
vote

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

Example 38

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

Source file: SyncService.java

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

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

Source file: CustomBugSenseReportSender.java

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

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

Source file: HttpClientFactory.java

  15 
vote

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

Example 41

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

Source file: ClientExecuteSOCKS.java

  15 
vote

public Socket connectSocket(final Socket socket,final InetSocketAddress remoteAddress,final InetSocketAddress localAddress,final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  if (remoteAddress == null) {
    throw new IllegalArgumentException("Remote address may not be null");
  }
  if (params == null) {
    throw new IllegalArgumentException("HTTP parameters may not be null");
  }
  Socket sock;
  if (socket != null) {
    sock=socket;
  }
 else {
    sock=createSocket(params);
  }
  if (localAddress != null) {
    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
    sock.bind(localAddress);
  }
  int timeout=HttpConnectionParams.getConnectionTimeout(params);
  try {
    sock.connect(remoteAddress,timeout);
  }
 catch (  SocketTimeoutException ex) {
    throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"+ remoteAddress.getAddress()+ " timed out");
  }
  return sock;
}
 

Example 42

From project httpcore, under directory /httpcore-nio/src/main/java/org/apache/http/impl/nio/.

Source file: DefaultClientIOEventDispatch.java

  15 
vote

@Override protected void onConnected(final NHttpClientIOTarget conn){
  int timeout=HttpConnectionParams.getSoTimeout(this.params);
  conn.setSocketTimeout(timeout);
  Object attachment=conn.getContext().getAttribute(IOSession.ATTACHMENT_KEY);
  this.handler.connected(conn,attachment);
}
 

Example 43

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

Source file: AndroidHttpClient.java

  15 
vote

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

Example 44

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

Source file: IgnitedHttp.java

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

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

Source file: ClientExecuteSOCKS.java

  15 
vote

public Socket connectSocket(final Socket socket,final InetSocketAddress remoteAddress,final InetSocketAddress localAddress,final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  if (remoteAddress == null) {
    throw new IllegalArgumentException("Remote address may not be null");
  }
  if (params == null) {
    throw new IllegalArgumentException("HTTP parameters may not be null");
  }
  Socket sock;
  if (socket != null) {
    sock=socket;
  }
 else {
    sock=createSocket(params);
  }
  if (localAddress != null) {
    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
    sock.bind(localAddress);
  }
  int timeout=HttpConnectionParams.getConnectionTimeout(params);
  try {
    sock.connect(remoteAddress,timeout);
  }
 catch (  SocketTimeoutException ex) {
    throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"+ remoteAddress.getAddress()+ " timed out");
  }
  return sock;
}
 

Example 46

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

Source file: SyncService.java

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

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

Source file: SyncService.java

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

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

Source file: SyncService.java

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

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

Source file: SyncService.java

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

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

Source file: DatasetGraphAccessorHTTP.java

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

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

Source file: SimpleArtifactCopier.java

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

From project jsword, under directory /src/main/java/org/crosswire/common/util/.

Source file: WebResource.java

  15 
vote

/** 
 * Construct a WebResource for the given URL, going through the optional proxy and port, while timing out if too much time has passed.
 * @param theURI the Resource to get via HTTP
 * @param theProxyHost the proxy host or null
 * @param theProxyPort the proxy port or null, where null means use the standard port
 * @param theTimeout the length of time in milliseconds to allow a connection to respond before timing out
 */
public WebResource(URI theURI,String theProxyHost,Integer theProxyPort,int theTimeout){
  uri=theURI;
  client=new DefaultHttpClient();
  HttpParams params=client.getParams();
  HttpConnectionParams.setSoTimeout(params,theTimeout);
  HttpConnectionParams.setConnectionTimeout(params,theTimeout);
  if (theProxyHost != null && theProxyHost.length() > 0) {
    HttpHost proxy=new HttpHost(theProxyHost,theProxyPort == null ? -1 : theProxyPort.intValue());
    ConnRouteParams.setDefaultProxy(params,proxy);
  }
  ProxySelectorRoutePlanner routePlanner=new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(),ProxySelector.getDefault());
  ((AbstractHttpClient)client).setRoutePlanner(routePlanner);
}
 

Example 53

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

Source file: HttpHelper.java

  15 
vote

/** 
 * Create an HttpClient.
 * @return a properly set HttpClient
 */
private static DefaultHttpClient createHttpClient(){
  HttpParams params=new BasicHttpParams();
  HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  schemeRegistry.register(new Scheme(STRING_HTTP,PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme(STRING_HTTPS,SSLSocketFactory.getSocketFactory(),443));
  HttpConnectionParams.setConnectionTimeout(params,HTTP_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,HTTP_TIMEOUT);
  ConnManagerParams.setTimeout(params,HTTP_TIMEOUT);
  HttpConnectionParams.setSocketBufferSize(params,SOCKET_BUFFER_SIZE);
  HttpProtocolParams.setContentCharset(params,HTTP.UTF_8);
  HttpProtocolParams.setHttpElementCharset(params,HTTP.UTF_8);
  HttpProtocolParams.setUserAgent(params,String.format(USER_AGENT_FORMAT_STRING,AndroidUtils.getApplicationLabel(),AndroidUtils.getVersionCode(),android.os.Build.VERSION.RELEASE,android.os.Build.MODEL));
  DefaultHttpClient client=new DefaultHttpClient(new ThreadSafeClientConnManager(params,schemeRegistry),params);
  enableGzipCompression(client);
  return client;
}
 

Example 54

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

Source file: NetworkClient.java

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

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

Source file: ClienteSeneca.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: Checkin.java

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

From project MyHeath-Android, under directory /src/com/buaa/shortytall/network/.

Source file: AbstractNetWorkThread.java

  15 
vote

protected String executePost(List<BasicNameValuePair> pairs) throws ClientProtocolException, IOException {
  setUrl();
  if (mUrl == null) {
    return null;
  }
  HttpPost httpPost=new HttpPost(mUrl);
  httpPost.setEntity(new UrlEncodedFormEntity(pairs,HTTP.UTF_8));
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setSoTimeout(params,TIMEOUT);
  HttpConnectionParams.setConnectionTimeout(params,TIMEOUT);
  HttpClientParams.setRedirecting(params,false);
  if (mHttpClient == null) {
    mHttpClient=new DefaultHttpClient();
  }
  mHttpClient.setParams(params);
  DefaultCoookieStore cookieStore=DefaultCoookieStore.getInstance(MyHealth.getCurrentContext());
  mHttpClient.setCookieStore(cookieStore);
  HttpResponse response=mHttpClient.execute(httpPost);
  cookieStore.saveCookies(MyHealth.getCurrentContext());
  int statusCode=response.getStatusLine().getStatusCode();
  if (statusCode == 200) {
    return EntityUtils.toString(response.getEntity());
  }
  return null;
}
 

Example 59

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

Source file: BetterHttp.java

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

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

Source file: SyncService.java

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

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

Source file: ModSSLSocketFactory.java

  15 
vote

public Socket connectSocket(final Socket sock,final String host,final int port,final InetAddress localAddress,int localPort,final HttpParams params) throws IOException {
  if (host == null) {
    throw new IllegalArgumentException("Target host may not be null.");
  }
  if (params == null) {
    throw new IllegalArgumentException("Parameters may not be null.");
  }
  Socket underlying=sock;
  if (underlying == null)   underlying=new Socket();
  SSLSocket sslsock=(SSLSocket)this.socketfactory.createSocket(underlying,host,port,true);
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0)     localPort=0;
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress;
  if (this.nameResolver != null) {
    remoteAddress=new InetSocketAddress(this.nameResolver.resolve(host),port);
  }
 else {
    remoteAddress=new InetSocketAddress(host,port);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  try {
    hostnameVerifier.verify(host,sslsock);
  }
 catch (  IOException iox) {
    try {
      sslsock.close();
    }
 catch (    Exception x) {
    }
    throw iox;
  }
  return sslsock;
}
 

Example 62

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

Source file: AndroidHttpClient.java

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

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

Source file: HttpClientFactory.java

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

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

Source file: MultihomePlainSocketFactory.java

  15 
vote

/** 
 * Attempts to connects the socket to any of the  {@link InetAddress}es the  given host name resolves to. If connection to all addresses fail, the   last I/O exception is propagated to the caller.
 * @param sock socket to connect to any of the given addresses
 * @param host Host name to connect to
 * @param port the port to connect to
 * @param localAddress local address
 * @param localPort local port
 * @param params HTTP parameters 
 * @throws IOException if an error occurs during the connection
 * @throws SocketTimeoutException if timeout expires before connecting
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException {
  if (host == null) {
    throw new IllegalArgumentException("Target host may not be null.");
  }
  if (params == null) {
    throw new IllegalArgumentException("Parameters may not be null.");
  }
  if (sock == null)   sock=createSocket();
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0)     localPort=0;
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sock.bind(isa);
  }
  int timeout=HttpConnectionParams.getConnectionTimeout(params);
  InetAddress[] inetadrs=InetAddress.getAllByName(host);
  List<InetAddress> addresses=new ArrayList<InetAddress>(inetadrs.length);
  addresses.addAll(Arrays.asList(inetadrs));
  Collections.shuffle(addresses);
  IOException lastEx=null;
  for (  InetAddress address : addresses) {
    try {
      sock.connect(new InetSocketAddress(address,port),timeout);
      break;
    }
 catch (    SocketTimeoutException ex) {
      throw ex;
    }
catch (    IOException ex) {
      sock=new Socket();
      lastEx=ex;
    }
  }
  if (lastEx != null) {
    throw lastEx;
  }
  return sock;
}
 

Example 65

From project platform_frameworks_support, under directory /volley/src/com/android/volley/toolbox/.

Source file: HttpClientStack.java

  15 
vote

@Override public HttpResponse performRequest(Request<?> request,Map<String,String> additionalHeaders) throws IOException, AuthFailureError {
  HttpUriRequest httpRequest;
  byte[] postBody=request.getPostBody();
  if (postBody != null) {
    HttpPost postRequest=new HttpPost(request.getUrl());
    postRequest.addHeader("Content-Type",request.getPostBodyContentType());
    HttpEntity entity;
    entity=new ByteArrayEntity(postBody);
    postRequest.setEntity(entity);
    httpRequest=postRequest;
  }
 else {
    httpRequest=new HttpGet(request.getUrl());
  }
  addHeaders(httpRequest,additionalHeaders);
  addHeaders(httpRequest,request.getHeaders());
  onPrepareRequest(httpRequest);
  HttpParams httpParams=httpRequest.getParams();
  int timeoutMs=request.getTimeoutMs();
  HttpConnectionParams.setConnectionTimeout(httpParams,5000);
  HttpConnectionParams.setSoTimeout(httpParams,timeoutMs);
  return mClient.execute(httpRequest);
}
 

Example 66

From project platform_packages_apps_im, under directory /src/com/android/im/imps/.

Source file: HttpDataChannel.java

  15 
vote

/** 
 * Constructs a new HttpDataChannel for a connection.
 * @param connection the connection which uses the data channel.
 */
public HttpDataChannel(ImpsConnection connection) throws ImException {
  super(connection);
  mTxManager=connection.getTransactionManager();
  ImpsConnectionConfig cfg=connection.getConfig();
  try {
    String host=cfg.getHost();
    if (host == null || host.length() == 0) {
      throw new ImException(ImErrorInfo.INVALID_HOST_NAME,"Empty host name.");
    }
    mPostUri=new URI(cfg.getHost());
    if (mPostUri.getPath() == null || "".equals(mPostUri.getPath())) {
      mPostUri=new URI(cfg.getHost() + "/");
    }
    if (!"http".equalsIgnoreCase(mPostUri.getScheme()) && !"https".equalsIgnoreCase(mPostUri.getScheme())) {
      throw new ImException(ImErrorInfo.INVALID_HOST_NAME,"Non HTTP/HTTPS host name.");
    }
    mHttpClient=AndroidHttpClient.newInstance("Android-Imps/0.1");
    HttpParams params=mHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params,cfg.getReplyTimeout());
    HttpConnectionParams.setSoTimeout(params,cfg.getReplyTimeout());
  }
 catch (  URISyntaxException e) {
    throw new ImException(ImErrorInfo.INVALID_HOST_NAME,e.getLocalizedMessage());
  }
  mContentTypeHeader=new BasicHeader("Content-Type",cfg.getTransportContentType());
  String msisdn=cfg.getMsisdn();
  mMsisdnHeader=(msisdn != null) ? new BasicHeader("MSISDN",msisdn) : null;
  mParser=cfg.createPrimitiveParser();
  mSerializer=cfg.createPrimitiveSerializer();
}
 

Example 67

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

Source file: HttpUtils.java

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

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

Source file: AndroidHttpClient.java

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

Source file: AndroidHttpClient.java

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

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

Source file: ProxyServlet.java

  15 
vote

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

Example 71

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

Source file: BetterHttp.java

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

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

Source file: HttpHelper.java

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

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

Source file: HttpTransport.java

  15 
vote

/** 
 * Reconfigures the HTTP client used for execution based on the variables set in the HttpTransport.<br /> <br /> The HttpTransport variables include: <code>_connectionTimeout</code> and <code>_socketIdleTimeout</code>.
 */
private void configureHttpClient(){
  HttpParams params=this._httpClient.getParams();
  if (this._followRedirects)   HttpClientParams.setRedirecting(params,false);
 else   HttpClientParams.setRedirecting(params,true);
  HttpConnectionParams.setConnectionTimeout(params,this._connectTimeout);
  HttpConnectionParams.setSoTimeout(params,this._socketIdleTimeout);
}
 

Example 74

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

Source file: HttpHelper.java

  15 
vote

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

Example 75

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

Source file: HttpHelper.java

  15 
vote

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

Example 76

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

Source file: FakeSocketFactory.java

  15 
vote

public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 77

From project rest-driver, under directory /rest-server-driver/src/main/java/com/github/restdriver/serverdriver/.

Source file: RestServerDriver.java

  15 
vote

private static Response doHttpRequest(ServerDriverHttpUriRequest request){
  HttpClient httpClient=new DefaultHttpClient();
  HttpParams httpParams=httpClient.getParams();
  HttpConnectionParams.setConnectionTimeout(httpParams,(int)request.getConnectionTimeout());
  HttpConnectionParams.setSoTimeout(httpParams,(int)request.getSocketTimeout());
  HttpClientParams.setRedirecting(httpParams,false);
  if (request.getProxyHost() != null) {
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY,request.getProxyHost());
  }
  HttpUriRequest httpUriRequest=request.getHttpUriRequest();
  if (!httpUriRequest.containsHeader(USER_AGENT)) {
    httpUriRequest.addHeader(USER_AGENT,DEFAULT_USER_AGENT);
  }
  HttpResponse response;
  try {
    long startTime=System.currentTimeMillis();
    response=httpClient.execute(httpUriRequest);
    long endTime=System.currentTimeMillis();
    return new DefaultResponse(response,(endTime - startTime));
  }
 catch (  ClientProtocolException cpe) {
    throw new RuntimeClientProtocolException(cpe);
  }
catch (  UnknownHostException uhe) {
    throw new RuntimeUnknownHostException(uhe);
  }
catch (  HttpHostConnectException hhce) {
    throw new RuntimeHttpHostConnectException(hhce);
  }
catch (  IOException e) {
    throw new RuntimeException("Error executing request",e);
  }
 finally {
    httpClient.getConnectionManager().shutdown();
  }
}
 

Example 78

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

Source file: ZenossAPIv2.java

  15 
vote

public ZenossAPIv2(String UserName,String Password,String URL,String BAUser,String BAPassword) throws Exception {
  if (URL.contains("https://")) {
    this.PrepareSSLHTTPClient();
  }
 else {
    this.PrepareHTTPClient();
  }
  if (!BAUser.equals("") || !BAPassword.equals("")) {
    CredentialsProvider credProvider=new BasicCredentialsProvider();
    credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,AuthScope.ANY_PORT),new UsernamePasswordCredentials(BAUser,BAPassword));
    httpclient.setCredentialsProvider(credProvider);
  }
  HttpParams httpParameters=new BasicHttpParams();
  int timeoutConnection=20000;
  HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
  int timeoutSocket=30000;
  HttpConnectionParams.setSoTimeout(httpParameters,timeoutSocket);
  httpclient.setParams(httpParameters);
  HttpPost httpost=new HttpPost(URL + "/zport/acl_users/cookieAuthHelper/login");
  List<NameValuePair> nvps=new ArrayList<NameValuePair>();
  nvps.add(new BasicNameValuePair("__ac_name",UserName));
  nvps.add(new BasicNameValuePair("__ac_password",Password));
  nvps.add(new BasicNameValuePair("submitted","true"));
  nvps.add(new BasicNameValuePair("came_from",URL + "/zport/dmd"));
  httpost.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8));
  HttpResponse response=httpclient.execute(httpost);
  response.getEntity().consumeContent();
  this.ZENOSS_INSTANCE=URL;
  this.ZENOSS_USERNAME=UserName;
  this.ZENOSS_PASSWORD=Password;
}
 

Example 79

From project ROM-Updater, under directory /src/org/elegosproject/romupdater/.

Source file: DownloadManager.java

  15 
vote

public static boolean checkHttpFile(String url){
  try {
    HttpParams httpParameters=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters,3000);
    Log.i(TAG,"Testing " + url + "...");
    URL theUrl=new URL(url);
    HttpURLConnection connection=(HttpURLConnection)theUrl.openConnection();
    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
      connection.disconnect();
    }
 else {
      Log.i(TAG,"HTTP Response code: " + connection.getResponseCode());
      return false;
    }
  }
 catch (  IOException e) {
    Log.e(TAG,e.toString());
    return false;
  }
  return true;
}
 

Example 80

From project rozkladpkp-android, under directory /src/org/tyszecki/rozkladpkp/.

Source file: StationSearch.java

  15 
vote

public StationSearch(){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,2000);
  HttpConnectionParams.setSoTimeout(params,2000);
  client=new DefaultHttpClient(params);
  client.removeRequestInterceptorByClass(org.apache.http.protocol.RequestExpectContinue.class);
  client.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class);
}
 

Example 81

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

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 82

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

Source file: Network.java

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

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

Source file: AndroidHttpClient.java

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

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

Source file: DestinationServiceImpl.java

  15 
vote

@Override public HttpClient getClient(URL url){
  if (!isSupportedProtocol(url)) {
    throw new IllegalArgumentException(MessageFormat.format("Protocol ''{0}'' is not suppported by this method",url.getProtocol()));
  }
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,CONNECT_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,READ_TIMEOUT);
  HttpConnectionParams.setTcpNoDelay(params,true);
  DefaultHttpClient client=new DefaultHttpClient(connectionManager,params);
  setProxy(client,url);
  setCredentials(client,url);
  return client;
}
 

Example 85

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

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 86

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

Source file: Checkin.java

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

From project springside4, under directory /examples/showcase/src/main/java/org/springside/examples/showcase/demos/web/.

Source file: RemoteContentServlet.java

  15 
vote

/** 
 * ????????????HttpClient???.
 */
@Override public void init() throws ServletException {
  PoolingClientConnectionManager cm=new PoolingClientConnectionManager();
  cm.setMaxTotal(CONNECTION_POOL_SIZE);
  httpClient=new DefaultHttpClient(cm);
  HttpParams httpParams=httpClient.getParams();
  HttpConnectionParams.setSoTimeout(httpParams,TIMEOUT_SECONDS * 1000);
}
 

Example 88

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

Source file: HttpFetchingImageStore.java

  15 
vote

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

Example 89

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

Source file: RESTMusicService.java

  15 
vote

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

Example 90

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

Source file: RESTMusicService.java

  15 
vote

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

Example 91

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

Source file: RESTMusicService.java

  15 
vote

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

Example 92

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

Source file: RESTMusicService.java

  15 
vote

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

Example 93

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

Source file: RESTMusicService.java

  15 
vote

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

Example 94

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

Source file: EasySSLSocketFactory.java

  15 
vote

/** 
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,java.lang.String,int,java.net.InetAddress,int,org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock,String host,int port,InetAddress localAddress,int localPort,HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
  int connTimeout=HttpConnectionParams.getConnectionTimeout(params);
  int soTimeout=HttpConnectionParams.getSoTimeout(params);
  InetSocketAddress remoteAddress=new InetSocketAddress(host,port);
  SSLSocket sslsock=(SSLSocket)((sock != null) ? sock : createSocket());
  if ((localAddress != null) || (localPort > 0)) {
    if (localPort < 0) {
      localPort=0;
    }
    InetSocketAddress isa=new InetSocketAddress(localAddress,localPort);
    sslsock.bind(isa);
  }
  sslsock.connect(remoteAddress,connTimeout);
  sslsock.setSoTimeout(soTimeout);
  return sslsock;
}
 

Example 95

From project SyncMyPix, under directory /src/com/nloko/android/.

Source file: Utils.java

  15 
vote

public static InputStream downloadPictureAsStream(String url) throws IOException {
  if (url == null) {
    throw new IllegalArgumentException("url");
  }
  HttpClient httpclient=null;
  InputStream stream=null;
  try {
    HttpParams params=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params,5000);
    HttpConnectionParams.setSoTimeout(params,10000);
    httpclient=new DefaultHttpClient(params);
    HttpGet httpget=new HttpGet(url);
    HttpResponse response=httpclient.execute(httpget);
    HttpEntity entity=response.getEntity();
    if (entity != null) {
      BufferedHttpEntity buff=new BufferedHttpEntity(entity);
      stream=buff.getContent();
    }
  }
 catch (  IOException ex) {
    Log.e(null,android.util.Log.getStackTraceString(ex));
    throw ex;
  }
 finally {
    try {
      if (httpclient != null) {
        httpclient.getConnectionManager().shutdown();
      }
      if (stream != null) {
        stream.close();
      }
    }
 catch (    Exception e) {
    }
  }
  return stream;
}
 

Example 96

From project TaxiCop, under directory /src/com/taxicop/client/.

Source file: NetworkUtilities.java

  15 
vote

public static void CreateHttpClient(){
  Log.i(TAG,"CreateHttpClient(): ");
  mHttpClient=new DefaultHttpClient();
  final HttpParams params=mHttpClient.getParams();
  HttpConnectionParams.setConnectionTimeout(params,REGISTRATION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,REGISTRATION_TIMEOUT);
  ConnManagerParams.setTimeout(params,REGISTRATION_TIMEOUT);
}
 

Example 97

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

Source file: FeedHttpClientHolder.java

  15 
vote

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

Example 98

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

Source file: MmsCommunication.java

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

From project todo.txt-touch, under directory /src/com/todotxt/todotxttouch/util/.

Source file: Util.java

  15 
vote

public static HttpParams getTimeoutHttpParams(){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT);
  HttpConnectionParams.setSoTimeout(params,SOCKET_TIMEOUT);
  return params;
}
 

Example 100

From project tomcat-maven-plugin, under directory /tomcat-maven-plugin-it/src/main/java/org/apache/tomcat/maven/it/.

Source file: AbstractWarProjectIT.java

  15 
vote

@Before public void setUp() throws Exception {
  httpClient=new DefaultHttpClient();
  final HttpParams params=httpClient.getParams();
  HttpConnectionParams.setConnectionTimeout(params,getTimeout());
  HttpConnectionParams.setSoTimeout(params,getTimeout());
  webappHome=ResourceExtractor.simpleExtractResources(getClass(),"/" + getWarArtifactId());
  verifier=new Verifier(webappHome.getAbsolutePath());
  boolean debugVerifier=Boolean.getBoolean("verifier.maven.debug");
  verifier.setMavenDebug(debugVerifier);
  verifier.setDebugJvm(Boolean.getBoolean("verifier.debugJvm"));
  verifier.displayStreamBuffers();
  verifier.deleteArtifact("org.apache.tomcat.maven.it",getWarArtifactId(),"1.0-SNAPSHOT","war");
}