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.imaginary.home.device.hue.HueMethod.java

protected @Nonnull HttpClient getClient() {
    boolean ssl = hue.getAPIEndpoint().startsWith("https");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    //noinspection deprecation
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "Imaginary Home");

    Properties p = hue.getCustomProperties();
    String proxyHost = p.getProperty("proxyHost");
    String proxyPort = p.getProperty("proxyPort");

    if (proxyHost != null) {
        int port = 0;

        if (proxyPort != null && proxyPort.length() > 0) {
            port = Integer.parseInt(proxyPort);
        }/*from   ww  w  .  j  a va  2  s .c  o  m*/
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                new HttpHost(proxyHost, port, ssl ? "https" : "http"));
    }
    return new DefaultHttpClient(params);
}

From source file:org.dasein.cloud.digitalocean.DigitalOcean.java

public @Nonnull HttpClient getClient(boolean multipart) throws InternalException {
    ProviderContext ctx = getContext();/* w ww. j av  a2s  .c  o  m*/
    if (ctx == null) {
        throw new InternalException("No context was specified for this request");
    }

    final HttpParams params = new BasicHttpParams();
    int timeout = 15000;
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    if (!multipart) {
        HttpProtocolParams.setContentCharset(params, Consts.UTF_8.toString());
    }
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");

    Properties p = ctx.getCustomProperties();
    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPortStr = p.getProperty("proxyPort");
        int proxyPort = 0;
        if (proxyPortStr != null) {
            proxyPort = Integer.parseInt(proxyPortStr);
        }
        if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort));
        }
    }
    DefaultHttpClient client = new DefaultHttpClient(params);
    client.addRequestInterceptor(new HttpRequestInterceptor() {
        public void process(final HttpRequest request, final HttpContext context)
                throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }
            request.setParams(params);
        }
    });
    client.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                Header header = entity.getContentEncoding();
                if (header != null) {
                    for (HeaderElement codec : header.getElements()) {
                        if (codec.getName().equalsIgnoreCase("gzip")) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            break;
                        }
                    }
                }
            }
        }
    });
    return client;
}

From source file:cn.edu.szjm.support.http.IgnitedHttp.java

/**
 * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN
 * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)}
 * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE}
 * permission</b>.//  w  ww .  j  a  va  2  s . co m
 * 
 * @param context
 *            the current context
 */
public void updateProxySettings(Context context) {
    if (context == null) {
        return;
    }
    HttpParams httpParams = httpClient.getParams();
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
    if (nwInfo == null) {
        return;
    }
    Log.i(LOG_TAG, nwInfo.toString());
    if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = Proxy.getHost(context);
        if (proxyHost == null) {
            proxyHost = Proxy.getDefaultHost();
        }
        int proxyPort = Proxy.getPort(context);
        if (proxyPort == -1) {
            proxyPort = Proxy.getDefaultPort();
        }
        if (proxyHost != null && proxyPort > -1) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } else {
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
        }
    } else {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
    }
}

From source file:org.bedework.util.http.BasicHttpClient.java

/**
 * @param host default host or null//from  w  ww.j a  va  2s .  c o m
 * @param port default port if host supplied or -1 for default
 * @param scheme default scheme if host supplied or null for default
 * @param timeOut - millisecs, 0 for no timeout
 * @param followRedirects true for auto handling
 * @throws HttpException
 */
public BasicHttpClient(final String host, final int port, final String scheme, final int timeOut,
        final boolean followRedirects) throws HttpException {
    super(connManager, null);
    setKeepAliveStrategy(kas);

    if (sslDisabled) {
        warn("*******************************************************");
        warn(" SSL disabled");
        warn("*******************************************************");
    }

    final HttpParams params = getParams();

    if (host != null) {
        hostSpecified = true;
        final HttpHost httpHost = new HttpHost(host, port, scheme);
        params.setParameter(ClientPNames.DEFAULT_HOST, httpHost);
    }

    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut);

    // XXX Should have separate value for this.
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut * 2);

    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects);
}

From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java

private boolean webServiceImageUrl() {

    try {//from  ww  w.  j a v  a 2s.c  o m
        Log.d("webServiceUserInfo", "called");
        HttpParams p = new BasicHttpParams();
        p.setParameter("user", "1");
        HttpClient httpclient = new DefaultHttpClient(p);
        String url = "http://ip.roaming4world.com/esstel/profile-data/profile_pic_download.php?self_contact="
                + prefs.getString(stored_user_country_code, "NoValue")
                + prefs.getString(stored_user_mobile_no, "NoValue")
                //           +"918860357393"
                + "&type=thumb";

        Log.d("url", url + " #");
        ResponseHandler<String> responseHandler;
        String responseBody;
        responseHandler = new BasicResponseHandler();

        HttpPost httppost = new HttpPost(url);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("user", "1"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        responseBody = httpclient.execute(httppost, responseHandler);

        JSONObject json = new JSONObject(responseBody);
        JSONArray response = json.getJSONArray("contacts");
        String path = json.getString("path");
        Log.d("pathtst", path + " #");
        Log.d("response", response + " #");
        phone_no = new String[response.length()];
        url_image = new String[response.length()];
        name = new String[response.length()];
        status = new String[response.length()];
        for (int i = 0; i < response.length(); i++) {
            JSONObject position = response.getJSONObject(i);
            Log.d("position", position + " #");
            phone_no[i] = position.getString("p");

            String url_update = position.getString("t");

            if (!url_update.equals("No image")) {
                url_image[i] = path + url_update;
            } else {
                url_image[i] = position.getString("t");
            }

            name[i] = position.getString("un");
            name[i] = Uri.decode(name[i]);
            status[i] = Uri.decode(position.getString("s"));

            username = position.getString("un");
            number = position.getString("p");
            user_status = position.getString("s");
            user_urlpath = url_image[i];

            Log.d(i + " phone_no  ", phone_no[i] + "   !");
            Log.d(i + " name ", name[i] + "   !");
            Log.d(i + " status ", status[i] + "   !");
            Log.d(i + " url", url_image[i] + "   !");

            dbContacts = new DBContacts(mcontext);

            dbContacts.openToWrite();

            String check = dbContacts.insert_or_update_R4Wcontact_detail_in_db(number, username, user_status,
                    user_urlpath);

            if (check.equals("update")) {
                updated_number.add(number);
                updated_url.add(user_urlpath);
            }

            //dbContacts.insert_R4Wcontact_detail_in_db(phone_no[i], name[i], status[i], url_image[i]);
        }

        dbContacts.close();
        return true;
    } catch (Exception t) {

        t.printStackTrace();

        return false;
    }

}

From source file:cn.tiup.httpproxy.ProxyServlet.java

/** Reads a servlet config parameter by the name {@code hcParamName} of type {@code type}, and
 * set it in {@code hcParams}./*from   ww  w  . j  a v a2s  .  c  om*/
 */
protected void readConfigParam(HttpParams hcParams, String hcParamName, Class<?> type) {
    String val_str = getConfigParam(hcParamName);
    if (val_str == null)
        return;
    Object val_obj;
    if (type == String.class) {
        val_obj = val_str;
    } else {
        try {
            //noinspection unchecked
            val_obj = type.getMethod("valueOf", String.class).invoke(type, val_str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    hcParams.setParameter(hcParamName, val_obj);
}

From source file:fr.eolya.utils.http.HttpLoader.java

private HttpParams getHttpParams() {
    HttpParams httpParams = new BasicHttpParams();

    // connection
    HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeOut);
    HttpConnectionParams.setSoTimeout(httpParams, sockeTimeOut);

    // protocol// w  w  w. j a v a2 s .c o m
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, "utf-8");

    // user-agent
    if (!StringUtils.isEmpty(userAgent)) {
        httpParams.setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    }

    // redirect
    httpParams.setParameter("http.protocol.handle-redirects", followRedirect);

    return httpParams;
}

From source file:de.derschimi.proxyservlet.TestServlet.java

/** Reads a servlet config parameter by the name {@code hcParamName} of type {@code type}, and
 * set it in {@code hcParams}.//from w  w  w. j a  va  2s  . c o m
 */
protected void readConfigParam(HttpParams hcParams, String hcParamName, Class type) {
    String val_str = getConfigParam(hcParamName);
    if (val_str == null)
        return;
    Object val_obj;
    if (type == String.class) {
        val_obj = val_str;
    } else {
        try {
            //noinspection unchecked
            val_obj = type.getMethod("valueOf", String.class).invoke(type, val_str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    hcParams.setParameter(hcParamName, val_obj);
}

From source file:org.dasein.cloud.aws.platform.CloudFrontMethod.java

protected @Nonnull HttpClient getClient(String url) throws InternalException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new InternalException("No context was specified for this request");
    }//from  w  w  w  . ja  v a  2 s .c om
    boolean ssl = url.startsWith("https");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");

    Properties p = ctx.getCustomProperties();

    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPort = p.getProperty("proxyPort");

        if (proxyHost != null) {
            int port = 0;

            if (proxyPort != null && proxyPort.length() > 0) {
                port = Integer.parseInt(proxyPort);
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                    new HttpHost(proxyHost, port, ssl ? "https" : "http"));
        }
    }
    return new DefaultHttpClient(params);
}

From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java

private void updateOfflineMissedCalls() {

    String from_summary = "", noc = "", from_detailed = "", lt = "", ct = "";
    Cursor c;/*from w ww  .  j a  va 2 s . c o  m*/
    String time = "", value;
    try {

        dbContacts = new DBContacts(mcontext);
        //   dbContacts.openToWrite();
        dbContacts.openToRead();
        c = dbContacts.fetch_details_from_MIssedCall_Offline_Table();

        if (c.getCount() > 0) {
            c.moveToFirst();
            value = c.getString(2);
            time = "&time=" + value;
            //  time = "&time=" + "1408434902";
        }

        c.close();
        dbContacts.close();

        Log.d("webService App Resume", "called");
        HttpParams p = new BasicHttpParams();
        p.setParameter("user", "1");
        HttpClient httpclient = new DefaultHttpClient(p);
        String url = "http://ip.roaming4world.com/esstel/app_resume_info.php?contact="
                + prefs.getString(stored_user_country_code, "NoValue")
                + prefs.getString(stored_user_mobile_no, "NoValue") + time;

        Log.d("url", url + " #");

        HttpGet httpget = new HttpGet(url);
        ResponseHandler<String> responseHandler;
        String responseBody;
        responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpget, responseHandler);

        dbContacts.openToWrite();

        JSONObject json = new JSONObject(responseBody);

        Log.d("response11", json + " #");

        if (json.getString("verify_from_pc").equals("true")) {
            Intent i = new Intent(mcontext, DesktopVerificationcode_Activity.class);
            i.putExtra("verify_code", json.getString("verify_code"));
            i.putExtra("countdown_time", json.getString("countdown_time"));
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mcontext.startActivity(i);
        }

        prefs.edit().putString(stored_min_call_credit, json.getString("min_call_credit")).commit();
        prefs.edit().putString(stored_user_bal, json.getString("user_bal")).commit();
        prefs.edit().putString(stored_server_ipaddress, json.getString("server_ip")).commit();

        Log.d("stored_server_ip address", json.getString("server_ip") + " #");
        Log.d("stored_user_bal", json.getString("user_bal") + " #");

        if (json.getString("valid").equals("true")) {

            JSONArray summary = json.getJSONArray("summary");
            JSONArray detailed = json.getJSONArray("detailed");

            for (int i = 0; i < summary.length(); i++) {
                JSONObject summarydata = summary.getJSONObject(i);
                from_summary = summarydata.getString("from");
                noc = summarydata.getString("noc");
                lt = summarydata.getString("lt");

                Log.d("from_summary", from_summary + " #");
                Log.d("noc", noc + " #");
                Log.d("lt", lt + " #");

                dbContacts.insert_MIssedCall_Offline_detail_in_db(from_summary, lt, noc);

                /*
                mBuilder.setSmallIcon(R.drawable.notification_icon);
                mBuilder.setContentTitle("Missed call (" + noc +")");
                mBuilder.setContentText(from_summary + "   " + lt);
                mBuilder.setContentIntent(resultPendingIntent);
                mNotificationManager.notify(Integer.parseInt(lt), mBuilder.build());
                */
                String count = "Missed call (" + noc + ")";

                CharSequence dateText = DateUtils.getRelativeTimeSpanString(Long.parseLong(lt) * 1000,
                        System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
                        DateUtils.FORMAT_ABBREV_RELATIVE);

                String num_date = from_summary + "   last on " + dateText.toString();

                showNotification(count, num_date, Integer.parseInt(lt));

            }

            for (int i = 0; i < detailed.length(); i++) {
                JSONObject detaileddata = detailed.getJSONObject(i);
                from_detailed = detaileddata.getString("from");
                ct = detaileddata.getString("ct");

                Log.d("from_detailed", from_detailed + " #");
                Log.d("ct", ct + " #");

                dbContacts.insert_MIssedCall_detail_in_db(from_detailed, ct);
            }

            dbContacts.close();

        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}