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:es.deustotech.piramide.utils.net.RestClient.java

public static HttpEntity connect(String url, HttpEntity httpEntity) {
    final DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.protocol.content-charset", "UTF-8");
    httpClient.setParams(params);/*from  ww  w. ja  v a 2s.c om*/
    final HttpGet httpGet = new HttpGet(url); //request object
    HttpResponse response = null;

    try {
        response = httpClient.execute(httpGet);
    } catch (ClientProtocolException cpe) {
        Log.d(Constants.TAG, cpe.getMessage());
    } catch (IOException ioe) {
        Log.d(Constants.TAG, ioe.getMessage());
    }
    return httpEntity = response.getEntity();
}

From source file:at.bitfire.davdroid.webdav.DavHttpClient.java

public static DefaultHttpClient getDefault() {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, "DAVdroid/" + Constants.APP_VERSION);

    // use defaults of AndroidHttpClient
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // don't allow redirections
    HttpClientParams.setRedirecting(params, false);

    DavHttpClient httpClient = new DavHttpClient(params);

    // use our own, SNI-capable LayeredSocketFactory for https://
    SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry();
    schemeRegistry.register(new Scheme("https", new TlsSniSocketFactory(), 443));

    // allow gzip compression
    GzipDecompressingEntity.enable(httpClient);
    return httpClient;
}

From source file:neembuu.uploader.versioning.CheckUser.java

public static void getCanCustomizeNormalizing(UserSetPriv usp) {
    boolean canCustomizeNormalizing = true;
    String normalization = ".neembuu";
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.useragent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    HttpClient httpclient = NUHttpClient.getHttpClient();
    HttpGet httpget = new HttpGet("http://neembuu.com/uploader/api/user.xml?userid=" + UserImpl.I().uid());
    NULogger.getLogger().info("Checking for user priviledges ...");
    try {/*from www  .  java  2  s .c o  m*/
        HttpResponse response = httpclient.execute(httpget);
        String respxml = EntityUtils.toString(response.getEntity());
        canCustomizeNormalizing = getCanCustomizeNormalizingFromXml(respxml);
        normalization = getNormalization(respxml);
        NULogger.getLogger().log(Level.INFO, "CanCustomizeNormalizing: {0}", canCustomizeNormalizing);
    } catch (Exception ex) {
        NULogger.getLogger().log(Level.INFO, "Exception while checking update\n{0}", ex);
    }
    usp.setCanCustomizeNormalizing(canCustomizeNormalizing);
    usp.setNormalization(normalization);
}

From source file:neembuu.release1.settings.OnlineSettingImpl.java

public static String getRaw(String... p) {
    //Get the version.xml and read the version value.
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.useragent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    DefaultHttpClient httpclient = new DefaultHttpClient(params);
    String pth = "";
    for (String p_ele : p) {
        pth = pth + "/" + p_ele;
    }/*w w w.j  ava  2s .  c  om*/
    HttpGet httpget = new HttpGet("http://neembuu.sourceforge.net" + pth);
    LoggerUtil.L().log(Level.INFO, "Getting online setting ...{0}", p);
    try {
        HttpResponse response = httpclient.execute(httpget);
        String respxml = EntityUtils.toString(response.getEntity());
        return respxml;
    } catch (Exception ex) {
        LoggerUtil.L().log(Level.INFO, "Exception while getting resource " + p, ex);
    }

    return null;
}

From source file:com.nebkat.junglist.bot.http.ConnectionManager.java

public static HttpClient getHttpClient() {
    if (sHttpClient == null) {
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        schemeRegistry.register(new Scheme("https", 443, new EasySSLSocketFactory()));

        HttpParams params = new BasicHttpParams();
        params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
        connectionManager.setDefaultMaxPerRoute(30);
        connectionManager.setMaxTotal(30);

        sHttpClient = new DefaultHttpClient(connectionManager, params);

        ((DefaultHttpClient) sHttpClient).addResponseInterceptor((response, context) -> {
            if (response.containsHeader("Location")) {
                context.setAttribute(REDIRECTED, true);
            }//from  w ww .ja va  2  s  . co  m
        });
    }
    return sHttpClient;
}

From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java

public static HttpClient genClient(PoolType poolConf) {

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();

    cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute());
    cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal());

    //Set all the params up front, instead of mutating them? Maybe this matters
    HttpParams params = new BasicHttpParams();
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout());
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout());
    params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay());
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount());
    params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength());
    params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize());
    params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding());

    final String uuid = UUID.randomUUID().toString();
    params.setParameter(CLIENT_INSTANCE_ID, uuid);

    //Pass in the params and the connection manager
    DefaultHttpClient client = new DefaultHttpClient(cm, params);

    SSLContext sslContext = ProxyUtilities.getTrustingSslContext();
    SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    SchemeRegistry registry = cm.getSchemeRegistry();
    Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf);
    registry.register(scheme);/*from  ww  w .j  a va 2  s.c  o m*/

    client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout()));

    LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid);

    return client;
}

From source file:it.restrung.rest.misc.HttpClientFactory.java

/**
 * Private helper to initialize an http client
 *
 * @return the initialize http client/* w w w .  j  av  a  2  s.  com*/
 */
private static synchronized DefaultHttpClient initializeClient() {
    //prepare for the https connection
    //call this in the constructor of the class that does the connection if
    //it's used multiple times
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new FakeSocketFactory(), 443));

    HttpParams params;
    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpClientParams.setRedirecting(params, true);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    // ignore that the ssl cert is self signed
    ThreadSafeClientConnManager clientConnectionManager = new ThreadSafeClientConnManager(params,
            schemeRegistry);

    instance = new DefaultHttpClient(clientConnectionManager, params);
    instance.setRedirectHandler(new DefaultRedirectHandler()); //If the link has a redirect
    return instance;
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

public static void post(String URL, Map<String, String> params) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URL);
    HttpParams httpParams = new BasicHttpParams();
    for (Entry<String, String> entryParam : params.entrySet()) {
        httpParams.setParameter(entryParam.getKey(), entryParam.getValue());
    }//from   w  w w. ja  v a2s  .com
    httpPost.setParams(httpParams);
    client.execute(httpPost);
}

From source file:cn.loveapple.client.android.util.ApiUtil.java

public static String getHttpBody(String url, PackageManager packageManager) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }//from  w w  w  . j  a  v  a  2  s  .c  o m

    String body = null;
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpParams params = httpClient.getParams();
    // SYSTEM INFO
    params.setParameter("", "");
    params.setParameter("", "");
    params.setParameter("", "");
    HttpConnectionParams.setConnectionTimeout(params, 1000);
    HttpConnectionParams.setSoTimeout(params, 1000);
    HttpPost httpRequest = new HttpPost(url);
    HttpResponse httpResponse = null;

    try {
        httpResponse = httpClient.execute(httpRequest);
    } catch (Exception e) {
        Log.e(LOG_TAG, "http response execute failed.", e);
        return null;
    }
    if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        HttpEntity httpEntity = httpResponse.getEntity();

        try {
            body = EntityUtils.toString(httpEntity);
        } catch (Exception e) {
            Log.e(LOG_TAG, "get http response body failed.", e);
            return null;
        } finally {
            try {
                httpEntity.consumeContent();
            } catch (IOException e) {
            }
        }
    }
    httpClient.getConnectionManager().shutdown();

    return body;
}

From source file:com.android.fastergallery.common.HttpClientFactory.java

/**
 * Creates an HttpClient with the specified userAgent string.
 * /*from   ww w . j  a  v  a  2 s .com*/
 * @param userAgent
 *            the userAgent string
 * @return the client
 */
public static HttpClient newHttpClient(String userAgent) {
    // AndroidHttpClient is available on all platform releases,
    // but is hidden until API Level 8
    try {
        Class<?> clazz = Class.forName("android.net.http.AndroidHttpClient");
        Method newInstance = clazz.getMethod("newInstance", String.class);
        Object instance = newInstance.invoke(null, userAgent);

        HttpClient client = (HttpClient) instance;

        // ensure we default to HTTP 1.1
        HttpParams params = client.getParams();
        params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        // AndroidHttpClient sets these two parameters thusly by default:
        // HttpConnectionParams.setSoTimeout(params, 60 * 1000);
        // HttpConnectionParams.setConnectionTimeout(params, 60 * 1000);

        // however it doesn't set this one...
        ConnManagerParams.setTimeout(params, 60 * 1000);

        return client;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}