Example usage for org.apache.http.client ClientProtocolException printStackTrace

List of usage examples for org.apache.http.client ClientProtocolException printStackTrace

Introduction

In this page you can find the example usage for org.apache.http.client ClientProtocolException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static String getHttpClientString(String path) {
    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
    HttpClient client = new DefaultHttpClient(httpParams);
    DefaultHttpClient httpClient = (DefaultHttpClient) client;
    HttpResponse httpResponse = null;/*from ww  w  .j  a  va2s .co m*/
    String result = "";
    try {
        httpResponse = httpClient.execute(new HttpGet(path));
        int res = httpResponse.getStatusLine().getStatusCode();
        if (res == 200) {
            InputStream in = httpResponse.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "GBK"));
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line.trim());
            }
            reader.close();
            in.close();
            result = sb.toString();
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result;
}

From source file:th.ac.kmutt.chart.rest.application.Main.java

private static void systemConfig(SystemM param) {
    SystemM sys = param;/*from   w ww .ja  va 2 s  .c o m*/
    String url = "system";
    HttpPost httppost = new HttpPost("http://localhost:8081/ChartServices/rest/" + url);
    XStream xstream = new XStream(new Dom4JDriver());
    Class c = null;
    try {
        c = Class.forName(sys.getClass().getName());
    } catch (ClassNotFoundException e2) {
        e2.printStackTrace();
    }
    xstream.processAnnotations(c);

    ByteArrayEntity entity = null;

    String xString = xstream.toXML(sys);
    try {
        entity = new ByteArrayEntity(xString.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }

    httppost.setEntity(entity);

    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    HttpResponse response = null;
    HttpEntity resEntity = null;
    try {
        response = httpclient.execute(httppost);
        resEntity = response.getEntity();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //httpclient.getConnectionManager().shutdown();
    try {
        httpclient.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.noisepages.nettoyeur.usb.DeviceInfo.java

/**
 * Synchronously retrieves device info from the web. This method must not be invoked on the main
 * thread as it performs blocking network operations that may cause the app to become
 * unresponsive.//from w  w w  .j av  a 2s.co  m
 * 
 * Requires android.permission.INTERNET.
 * 
 * @param device for which to retrieve information
 * @return device info, or null on failure
 */
public static DeviceInfo retrieveDeviceInfo(UsbDevice device) {
    DeviceInfo info = null;
    try {
        info = retrieveDeviceInfo(device.getVendorId(), device.getProductId());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return info;
}

From source file:fr.julienvermet.bugdroid.util.NetworkUtils.java

public static NetworkResult readJson(String url) {
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    int statusCode = 0;
    try {//from  w  ww . j  av  a 2s. c om
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            reader.close();
        } else {
            Log.e(NetworkUtils.class.toString(), "Failed to download Json content");
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {

    }

    return new NetworkResult(statusCode, builder.toString());
}

From source file:fr.julienvermet.bugdroid.util.NetworkUtils.java

public static NetworkResult postJson(String url, JSONObject data) {
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    int statusCode = 0;
    try {/*www.  j  av  a 2  s  .  com*/
        StringEntity se = new StringEntity(data.toString());
        httpPost.setEntity(se);
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");

        HttpResponse response = client.execute(httpPost);
        StatusLine statusLine = response.getStatusLine();
        statusCode = statusLine.getStatusCode();
        // if (statusCode == 201) {
        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        reader.close();
        // }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {

    }
    return new NetworkResult(statusCode, builder.toString());
}

From source file:Main.java

public static String getResultPost(String uri, List<NameValuePair> params) {
    String Result = null;/*from w w  w .j  av  a2s . com*/
    try {
        if (uri == null) {
            return "";
        }
        HttpPost httpRequest = new HttpPost(uri);
        BasicHttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
        httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse httpResponse = httpClient.execute(httpRequest);
        int res = httpResponse.getStatusLine().getStatusCode();
        if (res == 200) {

            StringBuilder builder = new StringBuilder();
            BufferedReader bufferedReader2 = new BufferedReader(
                    new InputStreamReader(httpResponse.getEntity().getContent()));
            for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2.readLine()) {
                builder.append(s);
            }
            Result = builder.toString();

        }

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block

        e.printStackTrace();
        return "";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return Result;
}

From source file:com.amazon.advertising.api.sample.ItemLookupSample.java

private static void getItemInfo(String asin, SignedRequestsHelper helper) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    Map<String, String> params = new HashMap<String, String>();
    params.put("Service", "AWSECommerceService");
    params.put("Version", "2011-08-01");
    params.put("Operation", "ItemLookup");
    params.put("ItemId", asin);
    params.put("ResponseGroup", "Images");
    String requestUrl = helper.sign(params);

    System.out.println("Request is \"" + requestUrl + "\"");
    HttpGet httpGet = new HttpGet(requestUrl);
    String responseBody = "";
    try {//from w  ww.j  a v a2  s  .  com
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpGet, responseHandler);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(responseBody);
}

From source file:net.evecom.android.util.HttpUtil.java

public static String queryStringForPost(HttpPost request) {
    String result = null;/*from w  w  w  .  j  av  a2 s  .  co m*/
    try {
        HttpResponse response = HttpUtil.getHttpResponse(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            result = EntityUtils.toString(response.getEntity());
            return result;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        result = "";
        return result;
    } catch (IOException e) {
        e.printStackTrace();
        result = "";
        return result;
    }
    return null;
}

From source file:net.evecom.android.util.HttpUtil.java

public static String queryStringForGet(String url) {
    HttpGet request = HttpUtil.getHttpGet(url);
    String result = null;/*from   w  ww . j av  a  2  s .co m*/
    try {
        HttpResponse response = HttpUtil.getHttpResponse(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            result = EntityUtils.toString(response.getEntity());
            return result;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        result = "";
        return result;
    } catch (IOException e) {
        e.printStackTrace();
        result = "";
        return result;
    }
    return null;
}

From source file:com.seer.datacruncher.load.LoadRunner.java

private static HttpResponse postRequest(HttpClient client, String action) {
    HttpResponse response = null;//from   ww  w. ja v a 2  s . com
    try {
        HttpPost httpPostDatabase = new HttpPost(properties.getProperty("url") + "/" + action);
        System.out.println("Requesting: " + httpPostDatabase.getURI());
        response = client.execute(httpPostDatabase);
        printResponse(response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return response;
}