Example usage for org.apache.http.client HttpClient getParams

List of usage examples for org.apache.http.client HttpClient getParams

Introduction

In this page you can find the example usage for org.apache.http.client HttpClient getParams.

Prototype

@Deprecated
HttpParams getParams();

Source Link

Document

Obtains the parameters for this client.

Usage

From source file:eu.trentorise.smartcampus.aac.AACService.java

protected static HttpClient getHttpClient() {
    HttpClient httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    return httpClient;
}

From source file:cn.sharesdk.net.NetworkHelper.java

public static PostResult httpPost(String url, ArrayList<NameValuePair> pairs) {
    PostResult postResult = new PostResult();
    if (pairs == null || pairs.size() == 0) {
        postResult.setSuccess(false);//from  ww  w.j  a  v  a2  s  .c o  m
        postResult.setResponseMsg("post date of the request params is null !");
        return postResult;
    }

    try {
        HttpPost httppost = new HttpPost(url);
        httppost.addHeader("charset", HTTP.UTF_8);
        httppost.setHeader("Accept", "application/json,text/x-json,application/jsonrequest,text/json");

        HttpEntity entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8);
        httppost.setEntity(entity);

        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();

        String resString = EntityUtils.toString(response.getEntity());
        postResult = parse(status, resString);
    } catch (Exception e) {
        Ln.i("NetworkHelper", "=== post Ln ===", e);
    }

    return postResult;
}

From source file:edu.tum.cs.ias.knowrob.BarcodeWebLookup.java

public static String lookUpEANsearch(String ean) {

    String res = "";
    if (ean != null && ean.length() > 0) {

        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        //httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-16");

        try {// w  ww . ja  va2  s. co  m

            HttpGet httpget = new HttpGet("http://www.ean-search.org/perl/ean-search.pl?ean=" + ean + "&os=1");
            httpget.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
            httpget.getParams().setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, "ASCII");

            System.out.println(httpget.getURI());

            // Create a response handler

            ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
                public byte[] handleResponse(HttpResponse response)
                        throws ClientProtocolException, IOException {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        return EntityUtils.toByteArray(entity);
                    } else {
                        return null;
                    }
                }
            };

            byte[] response = httpclient.execute(httpget, handler);

            //   String responseBody = httpclient.execute(httpget, handler);

            //            new HeapByteBuffer(responseBody.getBytes(), 0, responseBody.getBytes().length));
            //            
            //            Charset a  = Charset.forName("UTF-8");
            //            a.newEncoder().encode(responseBody.getBytes());
            //            
            //            System.out.println(responseBody);

            // Parse response document
            res = response.toString();

        } catch (UnsupportedEncodingException uee) {
            uee.printStackTrace();
        } catch (ClientProtocolException cpe) {
            cpe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (httpclient != null) {
                httpclient.getConnectionManager().shutdown();
            }
        }

    }
    return res;
}

From source file:com.impetus.client.couchdb.utils.CouchDBTestUtils.java

/**
 * Initiate http client.//w w w . j  a v a  2  s .  com
 * 
 * @param kunderaMetadata
 *            the kundera metadata
 * @param persistenceUnit
 *            the persistence unit
 * @return the http client
 */
public static HttpClient initiateHttpClient(final KunderaMetadata kunderaMetadata, String persistenceUnit) {
    PersistenceUnitMetadata pumMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(kunderaMetadata,
            persistenceUnit);

    SchemeSocketFactory ssf = null;
    ssf = PlainSocketFactory.getSocketFactory();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    int port = Integer.parseInt(pumMetadata.getProperty(PersistenceProperties.KUNDERA_PORT));
    String host = pumMetadata.getProperty(PersistenceProperties.KUNDERA_NODES);
    String userName = pumMetadata.getProperty(PersistenceProperties.KUNDERA_USERNAME);
    String password = pumMetadata.getProperty(PersistenceProperties.KUNDERA_PASSWORD);

    schemeRegistry.register(new Scheme("http", port, ssf));
    PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry);
    HttpClient httpClient = new DefaultHttpClient(ccm);

    try {
        // Http params
        httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

        // basic authentication
        if (userName != null && password != null) {
            ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(new AuthScope(host, port),
                    new UsernamePasswordCredentials(userName, password));
        }
        // request interceptor
        ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() {
            public void process(final HttpRequest request, final HttpContext context) throws IOException {

            }
        });
        // response interceptor
        ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(final HttpResponse response, final HttpContext context) throws IOException {

            }
        });
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    return httpClient;
}

From source file:cn.mdict.utils.IOUtil.java

public static boolean httpGetFile(String url, OutputStream os, StatusReport statusReport) {
    try {/*  ww w. j  a va2 s  .c o  m*/
        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, HttpUserAgent);
        HttpGet get = new HttpGet(url);
        if (statusReport != null)
            statusReport.onStart();
        HttpResponse response = client.execute(get);
        if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() != 200) {
            get.abort();
            return false;
        }
        HttpEntity entity = response.getEntity();
        long length = entity.getContentLength();
        if (statusReport != null)
            statusReport.onGetTotal(length);
        boolean result = streamDuplicate(entity.getContent(), os, statusReport);
        return result;
    } catch (Exception e) {
        if (statusReport != null)
            statusReport.onError(e);
        else
            e.printStackTrace();
    }
    return false;
}

From source file:org.ebayopensource.fidouafclient.curl.Curl.java

private static HttpClient createHttpsClient() {
    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
    SchemeRegistry registry = new SchemeRegistry();
    SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
    socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
    registry.register(new Scheme("https", socketFactory, 443));
    HttpClient client = new DefaultHttpClient();
    SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
    DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
    return httpClient;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode getFromServer(String urlString) {
    JsonNode ret = null;//from   w w  w. j  a va  2s  .co  m
    LOG.d("GET api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpGet httpget = null;
    URL url = null;
    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        httpget.setHeader("Content-type", "application/json");
        httpget.setHeader("Accept", ACCEPT);
        httpget.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:org.xwiki.android.authenticator.rest.XWikiConnector.java

/**
 * Configures the httpClient to connect to the URL provided.
 *///from   w  w  w .  j  a  v a 2 s . c  o m
public static HttpClient getHttpClient() {
    HttpClient httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS);

    return httpClient;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode deleteFromServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;/*  ww w  .j  a  v a2 s .  c o  m*/
    LOG.d("DELETE api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HTTPDeleteWithBody httpdelete = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httpdelete = new HTTPDeleteWithBody(url.toString());
        httpdelete.setHeader("Content-type", "application/json");
        httpdelete.setHeader("Accept", ACCEPT);
        httpdelete.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httpdelete.setEntity(se);
        HttpResponse response = httpclient.execute(httpdelete);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:it.smartcommunitylab.carpooling.controllers.UserAuthController.java

public static HttpResponse postJSON(String url, String body) throws Exception {

    final HttpResponse resp;
    final HttpPost post = new HttpPost(url);

    post.setHeader("Accept", "application/json");
    post.setHeader("Content-Type", "application/json");

    StringEntity input = new StringEntity(body, "UTF-8");
    input.setContentType("application/json");
    post.setEntity(input);//  www  .  j a va 2s .  co m

    HttpClient httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 30000);
    HttpConnectionParams.setSoTimeout(params, 30000);
    ConnManagerParams.setTimeout(params, 30000);

    resp = httpClient.execute(post);
    return resp;
}