Example usage for org.apache.http.params BasicHttpParams BasicHttpParams

List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams

Introduction

In this page you can find the example usage for org.apache.http.params BasicHttpParams BasicHttpParams.

Prototype

public BasicHttpParams() 

Source Link

Usage

From source file:org.cvasilak.jboss.mobile.admin.net.ssl.CustomHTTPClient.java

public static synchronized AbstractHttpClient getHttpClient() {
    try {/*from  w ww  .  j  a  v  a2s  .  c om*/
        if (client == null) {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(null, null);

            SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            registry.register(new Scheme("https", sf, 443));

            ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

            client = new DefaultHttpClient(ccm, params);
        }
    } catch (Exception e) {
        Log.d(TAG, "unable to create http client", e);
    }

    return client;
}

From source file:com.fitforbusiness.webservice.WebService.java

public WebService() {
    HttpParams myParams = new BasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(myParams, 100000);
    HttpConnectionParams.setSoTimeout(myParams, 100000);
    httpClient = new DefaultHttpClient(myParams);
    localContext = new BasicHttpContext();
}

From source file:com.squeezecontrol.image.HttpFetchingImageStore.java

public HttpFetchingImageStore(String baseUrl, String username, String password) {
    this.baseUrl = baseUrl;

    HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds. Tweak to taste.
    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);
    }//from w w  w  .j  a v a  2s. c  o  m
}

From source file:com.catchoom.servicerecognition.CatchoomApplication.java

@Override
public void onCreate() {
    super.onCreate();

    // Set up/*from   w ww  .  j a v  a  2s. c  o  m*/
    CatchoomApplication.preferences = getSharedPreferences(CatchoomApplication.PREFS_EDITOR_NAME,
            Context.MODE_PRIVATE);
    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    CatchoomApplication.catchoom = new Catchoom();
    imageManager = new ImageManager();
    context = getApplicationContext();
}

From source file:net.sf.dvstar.transmission.protocol.TestConnection.java

public static void testConnection() throws Exception {
    // make sure to use a proxy that supports CONNECT
    HttpHost target = new HttpHost("195.74.67.237", 80, "http");
    HttpHost proxy = new HttpHost("192.168.4.7", 3128, "http");

    // general setup
    SchemeRegistry supportedSchemes = new SchemeRegistry();

    // Register the "http" and "https" protocol schemes, they are
    // required by the default operator to look up socket factories.
    supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, true);

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, supportedSchemes);

    DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params);

    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpGet req = new HttpGet("/");

    System.out.println("executing request to " + target + " via " + proxy);
    HttpResponse rsp = httpclient.execute(target, req);
    HttpEntity entity = rsp.getEntity();

    System.out.println("----------------------------------------");
    System.out.println(rsp.getStatusLine());
    Header[] headers = rsp.getAllHeaders();
    for (int i = 0; i < headers.length; i++) {
        System.out.println(headers[i]);
    }//  w w  w .  j  a  va 2 s  . co  m
    System.out.println("----------------------------------------");

    if (entity != null) {
        System.out.println(EntityUtils.toString(entity));
    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:org.meruvian.midas.core.util.ConnectionUtil.java

public static HttpParams getHttpParams(int connectionTimeout, int socketTimeout) {
    HttpParams params = new BasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, socketTimeout);

    return params;
}

From source file:com.comcast.freeflow.examples.artbook.models.DribbbleFetch.java

public DribbbleFetch() {
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);
}

From source file:com.nikolak.weatherapp.ForecastIO.ForecastAPI.java

private String getAPIresponse(String apiURL) {
    DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
    HttpGet httpget = new HttpGet(apiURL);
    httpget.setHeader("Content-type", "application/json");

    InputStream inputStream = null;
    String result = null;//from ww  w. j  a  va2 s. c  o  m
    try {
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        inputStream = entity.getContent();
        // json is UTF-8 by default
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        result = sb.toString();
        return result;
    } catch (Exception e) {
        Log.e("URL Exception", e.toString());
        return null;
    } finally {
        try {
            if (inputStream != null)
                inputStream.close();
        } catch (IOException e) {
            Log.e("URL Get", e.toString());
        }
    }
}

From source file:com.guess.license.plate.Network.ThreadSafeHttpClientFactory.java

private HttpClient createHttpClient() {
    HttpParams httpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTP_PORT);
    schemeRegistry.register(httpScheme);

    Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTPS_PORT);
    schemeRegistry.register(httpsScheme);

    ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    HttpClient tmpClient = new DefaultHttpClient(tsConnManager, httpParams);

    HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(tmpClient.getParams(), TIMEOUT);
    addUserAgent(tmpClient);//from  w w w  .j  av  a 2s .c o m

    return tmpClient;
}

From source file:com.strato.hidrive.api.HttpClientManager.java

private DefaultHttpClient createHttpClient() {
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 5000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    int timeoutSocket = 5000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    return new DefaultHttpClient(httpParameters);
}