Example usage for org.apache.http.params HttpParams setParameter

List of usage examples for org.apache.http.params HttpParams setParameter

Introduction

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

Prototype

HttpParams setParameter(String str, Object obj);

Source Link

Usage

From source file:com.msopentech.thali.utilities.universal.HttpKeyHttpClient.java

protected ClientConnectionManager androidCreateClientConnectionManager() {
    // Note that HttpKeySocksProxyClientConnOperator only supports SOCKS connections
    // which is why we return a standard ThreadSafeClientConnManager when there is no
    // proxy and return a version with createConnectionOperator overridden only when
    // the connection is for SOCKS.

    ThreadSafeClientConnManager connManager;
    HttpParams httpParams = getParams();
    httpParams.setParameter(ConnManagerParams.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(maxConnections));
    httpParams.setParameter(ConnManagerParams.MAX_TOTAL_CONNECTIONS, maxConnections);

    if (proxy == null) {
        connManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    } else {//from   w  ww .ja va  2s  .c om
        connManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry) {
            @Override
            protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg) {
                return new HttpKeySocksProxyClientConnOperator(schreg, proxy);
            }
        };
    }

    return connManager;
}

From source file:com.jrodeo.queue.messageset.provider.TestHttpClient4.java

public TestHttpClient4() {
    super();/*from   w ww. java 2 s. co  m*/
    HttpParams params = new SyncBasicHttpParams();
    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);
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    this.mgr = new PoolingClientConnectionManager(schemeRegistry);
    this.httpclient = new DefaultHttpClient(this.mgr, params);
    this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {

        public boolean retryRequest(final IOException exception, int executionCount,
                final HttpContext context) {
            return false;
        }

    });
}

From source file:gmusic.api.api.comm.ApacheConnector.java

public ApacheConnector() {
    final HttpParams params = new BasicHttpParams();
    params.removeParameter("User-Agent");
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
    // HttpConnectionParams.setConnectionTimeout(params, 150000);
    // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis);
    httpClient = new DefaultHttpClient(params);
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:se.inera.certificate.proxy.filter.ProxyFilter.java

private void doInit() {
    if (!isInitiated) {
        connectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault());
        connectionManager.setMaxTotal(maxConnections);
        connectionManager.setDefaultMaxPerRoute(maxDefaultPerRoute);

        // TODO: Hardcoded for now... (PW)
        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT_MS);
        params.setParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_SO_TIMEOUT_MS);
        params.setParameter(CoreConnectionPNames.SO_LINGER, DEFAULT_SO_LINGER_S);

        httpClient = new HttpProxyClient(connectionManager, params);

        isInitiated = true;/* w w w  .jav  a 2s  .c om*/
    }
}

From source file:cl.mmoscoso.geocomm.sync.GeoCommRegisterAsyncTask.java

@Override
protected Boolean doInBackground(Void... params) {

    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpParams httpParams = httpclient.getParams();
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);

    HttpPost httppost = new HttpPost(this.hostname);

    try {//from   ww w.ja  va 2 s  .co  m
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("username", this.name));
        nameValuePairs.add(new BasicNameValuePair("password", this.pass));
        nameValuePairs.add(new BasicNameValuePair("email", this.e_mail));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        int responseCode = response.getStatusLine().getStatusCode();
        switch (responseCode) {
        case 200:
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                String responseBody = EntityUtils.toString(entity);
                //Log.i(TAGNAME, responseBody);
                JSONObject jObj;
                try {
                    //Log.i(TAGNAME, "tamao: "+ responseBody);
                    jObj = new JSONObject(responseBody);
                    Log.i(TAGNAME, "tamao22: " + jObj.getInt("status"));
                    this.status = jObj.getInt("status");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            break;
        }

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

    return true;
}

From source file:cl.mmoscoso.geocomm.sync.GeoCommDeletePointAsyncTask.java

@Override
protected Boolean doInBackground(Void... params) {

    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpParams httpParams = httpclient.getParams();
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);

    HttpPost httppost = new HttpPost(this.hostname);

    //http://172.16.50.35/~ramirez/testAddPoint.php
    //http://172.16.57.132/~laost/Symfony/web/app_dev.php/addPoint/

    try {// w w  w  .ja v a  2 s  .c  o m
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("id", Integer.toString(this.id_point)));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        int responseCode = response.getStatusLine().getStatusCode();
        Log.i(TAGNAME, "ERROR: " + responseCode);
        switch (responseCode) {
        default:
            Log.i(TAGNAME, "ERROR");
            //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show();
            break;
        case 200:
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                String responseBody = EntityUtils.toString(entity);
                //Log.i(TAGNAME, responseBody);
                JSONObject jObj;
                try {
                    Log.i(TAGNAME, "tamao: " + responseBody);
                    jObj = new JSONObject(responseBody);
                    this.status = jObj.getInt("status");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            break;
        }

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

    return true;
}

From source file:com.griddynamics.jagger.invoker.http.HttpInvoker.java

@Override
protected HttpParams getHttpClientParams(HttpQuery query) {
    HttpParams clientParams = new BasicHttpParams();
    for (Map.Entry<String, Object> clientParam : query.getClientParams().entrySet()) {
        clientParams.setParameter(clientParam.getKey(), clientParam.getValue());
    }/*from w w  w . j a v  a  2  s.c  om*/
    return clientParams;
}

From source file:cn.edu.bit.whitesail.crawl.Crawler.java

public Crawler() {
    httpClient = new DefaultHttpClient();
    parser = new HtmlParser();
    HttpParams params = httpClient.getParams();

    params.setParameter("http.useragent", "BaiFan Robot");
    // combine cookie
    params.setParameter("http.protocol.single-cookie-header", Boolean.TRUE);
    // socket time out
    params.setParameter("http.socket.timeout", 20000);
    // limit the redirect times
    params.setParameter("http.protocol.max-redirects", 3);
    // cookie policy,
    params.setParameter("http.protocol.cookie-policy", "compatibility");
}

From source file:org.apache.chemistry.opencmis.client.bindings.spi.http.ApacheClientHttpInvoker.java

@Override
protected DefaultHttpClient createHttpClient(UrlBuilder url, BindingSession session) {
    // set params
    HttpParams params = createDefaultHttpParams(session);
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);

    // set up scheme registry and connection manager
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(new Scheme("https", 443, getSSLSocketFactory(url, session)));

    // set up connection manager
    PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(registry);

    // set max connection a
    String keepAliveStr = System.getProperty("http.keepAlive", "true");
    if ("true".equalsIgnoreCase(keepAliveStr)) {
        String maxConnStr = System.getProperty("http.maxConnections", "5");
        int maxConn = 5;
        try {//  w  w  w  .  ja  v a2s. c om
            maxConn = Integer.parseInt(maxConnStr);
        } catch (NumberFormatException nfe) {
            // ignore
        }
        connManager.setDefaultMaxPerRoute(maxConn);
        connManager.setMaxTotal(4 * maxConn);
    }

    // set up proxy
    ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(registry, null);

    // set up client
    DefaultHttpClient httpclient = new DefaultHttpClient(connManager, params);
    httpclient.setRoutePlanner(routePlanner);

    return httpclient;
}

From source file:cz.cvut.jirutjak.fastimport.droid.utils.ExtraKeyStoreHttpClientFactory.java

public HttpClient createHttpClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", createAdditionalCertsSSLSocketFactory(), 443));

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE,
            new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS_PER_ROUTE));

    ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    return new DefaultHttpClient(connManager, params);
}