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:com.TaxiDriver.jy.DriverQuery.java

public static String jobQuery(String msgtype, String job_id, int rating, String driver_id) {

    HttpPost postJob = new HttpPost(HttpHelper.domain + "jobquery.php");
    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    // The default value is zero, that means the timeout is not used.
    int timeoutConnection = 3000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = 4900;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    DefaultHttpClient clientJob = new DefaultHttpClient(httpParameters);

    try {/*  w w  w . j  a v a 2s.  c o  m*/
        List<NameValuePair> infoJob = new ArrayList<NameValuePair>(2);
        infoJob.add(new BasicNameValuePair("msgtype", msgtype));
        infoJob.add(new BasicNameValuePair("job_id", job_id));
        infoJob.add(new BasicNameValuePair("rating", Integer.toString(rating)));
        infoJob.add(new BasicNameValuePair("driver_id", driver_id));
        postJob.setEntity(new UrlEncodedFormEntity(infoJob));
        HttpResponse response = clientJob.execute(postJob);

        String result = "done";

        return result;

    } catch (Exception e) {

        return null;
    }

}

From source file:ch.ethz.dcg.pancho3.view.youtube.Query.java

private void initializeHttpClient() {
    // Initialize Http client
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT);
    httpClient = new DefaultHttpClient(params);

    HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler(2, true);
    httpClient.setHttpRequestRetryHandler(retryHandler);
}

From source file:com.jgoetsch.eventtrader.source.WordPressLoginFilter.java

public void doAction(HttpClient client, AbstractHttpMsgSource httpMsgSource) {
    try {//from  w w  w.j  av  a2s  . c  o  m
        if (getLoginUrl() == null || getLoginUrl().length() == 0)
            throw new IllegalStateException("Required property \"loginUrl\" not set");
        else {
            HttpPost post = new HttpPost(getLoginUrl());
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("log", httpMsgSource.getUsername()));
            nvps.add(new BasicNameValuePair("pwd", httpMsgSource.getPassword()));
            nvps.add(new BasicNameValuePair("redirect_to", "wp-admin/"));
            nvps.add(new BasicNameValuePair("testcookie", "1"));
            post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            HttpParams postParams = new BasicHttpParams();
            postParams.setBooleanParameter("http.protocol.handle-redirects", false);
            post.setParams(postParams);

            HttpResponse rsp = client.execute(post);
            HttpEntity entity = rsp.getEntity();
            if (entity != null)
                entity.consumeContent(); // release connection gracefully

            if (rsp.getStatusLine().getStatusCode() >= 400)
                throw new IOException("Login POST request failed with error code " + rsp.getStatusLine());
            else if (rsp.getStatusLine().getStatusCode() != 302)
                throw new IOException(
                        "Login failed, redirect response not received (probably incorrect username/password)");
            else {
                log.debug("Successfully logged into " + getLoginUrl() + " as user "
                        + httpMsgSource.getUsername());
            }
        }
    } catch (IOException e) {
        log.error("Wordpress site login failed", e);
    }

}

From source file:org.doubango.ngn.services.impl.NgnHttpClientService.java

@Override
public boolean start() {
    Log.d(TAG, "Starting...");

    if (mClient == null) {
        mClient = new DefaultHttpClient();
        final HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, sTimeoutConnection);
        HttpConnectionParams.setSoTimeout(params, sTimeoutSocket);
        ((DefaultHttpClient) mClient).setParams(params);
        return true;
    }/*from   ww w . j  a  v  a  2s .  c o m*/
    Log.e(TAG, "Already started");
    return false;
}

From source file:com.gmail.nagamatu.radiko.installer.MySSLSocketFactory.java

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

        SSLSocketFactory sf = new MySSLSocketFactory(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:org.apache.tuscany.sca.host.http.client.HttpClientFactory.java

public HttpClient createHttpClient() {
    HttpParams defaultParameters = new BasicHttpParams();
    //defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 10);

    ConnManagerParams.setMaxTotalConnections(defaultParameters, 1024);
    ConnPerRoute connPerRoute = new ConnPerRouteBean(256);
    ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, connPerRoute);

    HttpProtocolParams.setContentCharset(defaultParameters, HTTP.UTF_8);
    HttpConnectionParams.setConnectionTimeout(defaultParameters, 60000);
    HttpConnectionParams.setSoTimeout(defaultParameters, 60000);

    SchemeRegistry supportedSchemes = new SchemeRegistry();
    supportedSchemes/*w  ww .  j a v a 2 s  .  co m*/
            .register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80));
    supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(defaultParameters,
            supportedSchemes);

    return new DefaultHttpClient(connectionManager, defaultParameters);
}

From source file:net.giovannicapuano.galax.util.Utils.java

/**
 * Perform a HTTP GET request.//from  ww w  .  j ava2 s . co m
 */
public static HttpData get(String path, Context context) {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);

    int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    String body = "";

    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    HttpContext localContext = new BasicHttpContext();

    localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context));
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());

    try {
        HttpGet httpGet = new HttpGet(context.getString(R.string.server) + path);
        HttpResponse response = httpClient.execute(httpGet, localContext);

        status = response.getStatusLine().getStatusCode();
        body = EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return new HttpData(status, body);
}

From source file:com.photon.phresco.Screens.HttpRequest.java

/**
 * Send the JSON data to specified URL and get the httpResponse back
 *
 * @param sURL// ww w . j a v  a 2 s .c om
 * @param jObject
 * @return InputStream
 * @throws IOException
 */
public static InputStream post(String sURL, JSONObject jObject) throws IOException {
    HttpResponse httpResponse = null;
    InputStream is = null;

    HttpPost httpPostRequest = new HttpPost(sURL);
    HttpEntity entity;

    httpPostRequest.setHeader("Accept", "application/json");
    httpPostRequest.setHeader(HTTP.CONTENT_TYPE, "application/json");
    httpPostRequest.setEntity(new ByteArrayEntity(jObject.toString().getBytes("UTF-8")));
    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    int timeoutConnection = TIME_OUT;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = TIME_OUT;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
    httpResponse = httpClient.execute(httpPostRequest);

    if (httpResponse != null) {
        entity = httpResponse.getEntity();
        is = entity.getContent();
    }
    return is;
}

From source file:eu.musesproject.client.connectionmanager.HttpConnectionsHelper.java

/**
 * Http post implementation //from ww  w .j  ava  2 s  . co m
 * @param url
 * @param data
 * @return httpResponse
 * @throws ClientProtocolException
 * @throws IOException
 */

public synchronized HttpResponse doPost(String type, String url, String data)
        throws ClientProtocolException, IOException {
    HttpResponse httpResponse = null;
    HttpPost httpPost = new HttpPost(url);
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT);
    DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
    StringEntity s = new StringEntity(data.toString());
    s.setContentEncoding("UTF-8");
    s.setContentType("application/xml");
    httpPost.addHeader("connection-type", type);
    httpPost.setEntity(s);
    httpPost.addHeader("accept", "application/xml");
    if (cookie == null || cookie.isExpired(new Date())) {
        try {
            httpResponse = httpclient.execute(httpPost);
            List<Cookie> cookies = httpclient.getCookieStore().getCookies();
            if (cookies.isEmpty()) {
                Log.d(TAG, "None");
            } else {
                cookie = cookies.get(0);
                cookieExpiryDate = cookie.getExpiryDate();
                Log.d(TAG, "Curent cookie expiry : " + cookieExpiryDate);
            }
        } catch (ClientProtocolException e) {
            Log.d(TAG, e.getMessage());
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }

    } else {
        httpPost.addHeader("accept", "application/xml");
        httpclient.getCookieStore().addCookie(cookie);
        try {
            httpResponse = httpclient.execute(httpPost);
        } catch (ClientProtocolException e) {
            Log.d(TAG, e.getMessage());
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }
    }
    return httpResponse;
}

From source file:com.weiboa.data.WeiboOAuthConnect.java

public WeiboOAuthConnect(SharedPreferences sp) {
    super(sp);/*from   ww  w .j a  v  a  2 s . com*/

    // initialize http connection
    HttpParams parameters = new BasicHttpParams();
    HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(parameters, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(parameters, false);
    HttpConnectionParams.setTcpNoDelay(parameters, true);
    HttpConnectionParams.setSocketBufferSize(parameters, 8192);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager tsccm = new ThreadSafeClientConnManager(parameters, schReg);
    mClient = new DefaultHttpClient(tsccm, parameters);

    mConsumer = new CommonsHttpOAuthConsumer(com.weiboa.oauth.OAuthKeys.CONSUMER_KEY,
            com.weiboa.oauth.OAuthKeys.CONSUMER_SECRET);

    loadSavedKeys(sp);
}