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.elegosproject.romupdater.DownloadManager.java

public static boolean checkHttpFile(String url) {
    try {/*  w w  w  . j a  v a  2 s.  co m*/
        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;
}

From source file:com.dealoka.lib.net.HttpUtils.java

public static HttpClient getNewHttpClient() {
    try {/*  ww  w  . j  av a 2 s  .co m*/
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

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

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

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

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

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  www.jav  a  2 s.co  m
    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: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 {// w w  w  . j  ava2s .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:org.switchyard.quickstarts.rules.multi.RulesMultiThreadBindingUtils.java

/**
 * Gets the client./*w w  w.ja  v  a 2s . c o  m*/
 *
 * @return the client
 */
public static DefaultHttpClient getClient() {
    DefaultHttpClient ret = null;

    // sets up parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    params.setBooleanParameter("http.protocol.expect-continue", false);

    // registers schemes for both http and https
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    registry.register(new Scheme("https", sslSocketFactory, 443));

    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
    ret = new DefaultHttpClient(manager, params);
    return ret;
}

From source file:com.ninja.examples.utility.net.APIRequest.java

public static DefaultHttpClient getClient() {
    if (httpclient == null) {
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setUseExpectContinue(params, false);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "utf-8");

        params.setBooleanParameter("http.protocol.expect-continue", false);

        HttpConnectionParams.setConnectionTimeout(params, WS_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, WS_TIMEOUT);

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

        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);

        httpclient = new DefaultHttpClient(manager, params);

        httpclient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
            public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
                return 50;
            }//from  w w  w .ja  va 2  s .c  om
        });

    }
    return httpclient;
}

From source file:com.core.ServerConnector.java

public static String post(String endpoint, Map<String, String> params) throws Exception {
    String result = null;/*w w w  .j  a v  a  2  s .c o m*/
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);
    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    HttpPost httppost = new HttpPost(endpoint);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        nameValuePairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        result = SystemUtil.convertStreamToString(instream);

        instream.close();
    }

    return result;
}

From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java

@SuppressLint("NewApi")

public static JsonNode performGET(String urlString) {
    JsonNode ret = null;/*  w  w  w.  ja  va  2  s .c o  m*/

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 20000);
    HttpConnectionParams.setSoTimeout(myParams, 20000);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    HttpGet httpget = null;

    URL url = null;

    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        LOG.d("Request " + url.toString());
        httpget.setHeader("Content-type", "application/json");
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("Response " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);

    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.blueserial.MyApplication.java

private static DefaultHttpClient createClient() {
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    DefaultHttpClient httpclient = new DefaultHttpClient(cm, params);
    httpclient.getCookieStore().getCookies();
    return httpclient;
}

From source file:wuit.common.crawler.search.Crawler.java

public static String doGetHttp(String url) {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 12000);
    HttpConnectionParams.setSoTimeout(params, 9000);
    HttpClient httpclient = new DefaultHttpClient(params);
    String rs = "";
    try {/*  w w w  . jav a2 s  . c o m*/
        //            System.out.println(url);
        HttpGet httpget = new HttpGet(url);

        HttpContext httpContext = new BasicHttpContext();
        //            httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
        httpget.addHeader("User-Agent",
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; .NET CLR 1.1.4322; CIBA; .NET CLR 2.0.50727)");

        HttpResponse response = httpclient.execute(httpget, httpContext);
        HttpUriRequest realRequest = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST);
        HttpHost targetHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        url = targetHost.toString() + realRequest.getURI();
        int resStatu = response.getStatusLine().getStatusCode();//? 
        if (resStatu == 200) {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                rs = EntityUtils.toString(entity, "iso-8859-1");
                String in_code = getEncoding(rs);
                String encode = getHtmlEncode(rs);
                if (encode.isEmpty()) {
                    httpclient.getConnectionManager().shutdown();
                    return "";
                } else {
                    if (!in_code.toLowerCase().equals("utf-8")
                            && !in_code.toLowerCase().equals(encode.toLowerCase())) {
                        if (!in_code.toLowerCase().equals("iso-8859-1"))
                            rs = new String(rs.getBytes("iso-8859-1"), in_code);
                        if (!encode.toLowerCase().equals(in_code.toLowerCase()))
                            rs = new String(rs.getBytes(in_code), encode);
                    }
                }
                try {
                } catch (RuntimeException ex) {
                    httpget.abort();
                    throw ex;
                } finally {
                    // Closing the input stream will trigger connection release
                    //                    try { instream.close(); } catch (Exception ignore) {}
                }
            }
        }
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
        return rs;
    }
}