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:com.musevisions.android.SudokuSolver.HttpPostUtils.java

static public String send(HttpPostSettings settings, List<NameValuePair> values) {
    try {// w w  w  . ja  va 2s.com
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(settings.getPostTarget());
        httppost.setEntity(new UrlEncodedFormEntity(values));
        HttpResponse response = httpclient.execute(httppost);
        return EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.hat.tools.HttpUtils.java

public static void SendRequest(String url, Handler handler) {
    HttpGet request = new HttpGet(url);
    HttpClient httpClient = new DefaultHttpClient();

    byte[] data = null;
    InputStream in = null;/*  w  w w .j  a v  a 2  s . c  o  m*/
    try {
        HttpResponse response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            in = response.getEntity().getContent();
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
                out.write(buf, 0, len);
            }
            data = out.toByteArray();
            Message msg = new Message();
            msg.what = HTTP_FINISH;
            Bundle bundle = new Bundle();
            bundle.putByteArray("data", data);
            msg.setData(bundle);
            handler.sendMessage(msg);
            out.close();
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.apache.usergrid.apm.service.UsergridInternalRestServerConnector.java

public static boolean isCrashNotificationDisabled(String orgName, String appName) {
    String restServerUrl = DeploymentConfig.geDeploymentConfig().getUsergridRestUrl();
    //String restServerUrl = "http://instaops-apigee-mobile-app-prod.apigee.net/";
    restServerUrl += "/" + orgName + "/" + appName + "/apm/apigeeMobileConfig";
    log.info("Checking if crash notification is disabled for " + orgName + " app : " + appName);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getMethod = new HttpGet(restServerUrl);
    HttpResponse response;/*from  w w  w .  j a  v  a  2  s .  c o  m*/
    try {
        response = httpClient.execute(getMethod);

        HttpEntity entity = response.getEntity();
        String jsonObject = EntityUtils.toString(entity);
        ObjectMapper mapper = new ObjectMapper();
        App app = mapper.readValue(jsonObject, App.class);
        Set<AppConfigCustomParameter> parameters = app.getDefaultAppConfig().getCustomConfigParameters();
        for (AppConfigCustomParameter param : parameters) {
            if (param.getTag().equalsIgnoreCase("ALARM")
                    && param.getParamKey().equalsIgnoreCase("SUPPRESS_ALARMS")
                    && param.getParamValue().equalsIgnoreCase("TRUE"))
                ;
            {
                return true;
            }
        }

    } catch (ClientProtocolException e) {
        log.error("Problem connectiong to Usergrid internal REST server " + restServerUrl);
        e.printStackTrace();

    } catch (IOException e) {
        log.error("Problem connectiong to Usergrid internal REST server " + restServerUrl);
        e.printStackTrace();
    }
    httpClient = null;
    return false;
}

From source file:com.fufang.httprequest.HttpPostBuild.java

public static String postBuildJson(String url, String params)
        throws UnsupportedEncodingException, ClientProtocolException, IOException {

    CloseableHttpClient httpClient = HttpClients.createDefault();
    String postResult = null;/*from  ww  w.jav a2s. c o m*/

    HttpPost httpPost = new HttpPost(url);
    System.out.println(" request " + httpPost.getRequestLine());

    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000)
            .build();
    httpPost.setConfig(requestConfig);
    StringEntity entity = new StringEntity(params.toString(), "UTF-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);

    try {
        HttpResponse response = httpClient.execute(httpPost);
        int status = response.getStatusLine().getStatusCode();
        if (status >= 200 && status < 300) {
            HttpEntity responseEntity = response.getEntity();
            postResult = EntityUtils.toString(responseEntity);
        } else {
            System.out.println("unexpected response status - " + status);
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return postResult;
}

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

public static String queryStringForPost(String url) {
    HttpPost request = HttpUtil.getHttpPost(url);// HttpPost request = new
                                                 // HttpPost(url);return
                                                 // request;
    String result = null;/*from w w  w .  j  a v a  2  s .c  o  m*/
    try {
        HttpResponse response = HttpUtil.getHttpResponse(request);// post
                                                                  // HttpResponse
                                                                  // response
                                                                  // = new
                                                                  // DefaultHttpClient().execute(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.giovannicapuano.galax.util.Utils.java

/**
 * Perform a HTTP GET request./*  w  ww .  j  a  va2  s  .  c  om*/
 */
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:net.giovannicapuano.galax.util.Utils.java

/**
 * Perform a HTTP POST request.//ww w . jav  a2 s . co m
 */
public static HttpData postData(String path, List<NameValuePair> post, 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 {
        HttpPost httpPost = new HttpPost(context.getString(R.string.server) + path);
        httpPost.setEntity(new UrlEncodedFormEntity(post));
        HttpResponse response = httpClient.execute(httpPost, 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:net.wedjaa.elasticparser.tester.ESSearchTester.java

private static int countIndexed() {
    System.out.println("Getting the indexing status");
    int indexed = 0;

    HttpGet statusGet = new HttpGet("http://localhost:9500/unit/_stats");
    try {//from w  w w  . j a  v  a  2s. c  o  m
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();
        System.out.println("Executing request");
        HttpResponse response = httpclient.execute(statusGet);
        System.out.println("Processing response");
        InputStream isResponse = response.getEntity().getContent();
        BufferedReader isReader = new BufferedReader(new InputStreamReader(isResponse));
        StringBuilder strBuilder = new StringBuilder();
        String readLine;
        while ((readLine = isReader.readLine()) != null) {
            strBuilder.append(readLine);
        }
        isReader.close();
        System.out.println("Done - reading JSON");
        JSONObject esResponse = new JSONObject(strBuilder.toString());
        indexed = esResponse.getJSONObject("indices").getJSONObject("unit").getJSONObject("total")
                .getJSONObject("docs").getInt("count");
        System.out.println("Indexed docs: " + indexed);
        httpclient.close();
    } catch (ClientProtocolException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    return indexed;
}

From source file:org.flakor.androidtool.utils.HttpUtil.java

public static String queryStringForPost(HttpPost request) {
    String result = null;//from  www  .  j  a va  2s  .  c o m
    try {
        // ?
        HttpResponse response = HttpUtil.getHttpResponse(request);
        // ??
        if (response.getStatusLine().getStatusCode() == 200) {
            // ?
            result = EntityUtils.toString(response.getEntity());
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        result = "?";
    } catch (IOException e) {
        e.printStackTrace();
        result = "?";
    } finally {
        return result;
    }
}

From source file:org.ebaysf.ostara.upgrade.util.GitUtils.java

public static Collection<String> getListOfGitCommitters(String gitUrl) {
    Set<String> committers = new HashSet<>(); // Need unique entries

    if (gitUrl == null)
        return committers;

    String[] parts = gitUrl.split("(/)|(:)|(@)");

    if (parts.length < 4) {
        LOG.warn("Malformed git url " + gitUrl);
        return committers;
    }/*from   www  . j  a  v  a2s.c  om*/

    // Get date 1 year ago
    String date = getISODate(1);

    String url = "https://github.com/api/v3/repos/" + parts[parts.length - 2] + "/"
            + parts[parts.length - 1].substring(0, parts[parts.length - 1].length() - 4) + "/commits?since="
            + date;

    try {
        StringBuilder sb = readData(committers, url);

        // Malformed url
        if (sb == null) {
            return committers;
        }
        JSONArray ar = new JSONArray(sb.toString());

        // if no committers  found in last 1 year then check last 2 year 
        if (ar.length() == 0) {
            date = getISODate(2);
            url = "https://github.com/api/v3/repos/" + parts[parts.length - 2] + "/"
                    + parts[parts.length - 1].substring(0, parts[parts.length - 1].length() - 4)
                    + "/commits?since=" + date;
            sb = readData(committers, url);
            ar = new JSONArray(sb.toString());
        }

        for (int i = 0; i < ar.length(); i++) {
            JSONObject json = (JSONObject) ar.get(i);
            json = (JSONObject) json.get("commit");
            json = (JSONObject) json.get("author");
            committers.add(json.get("email").toString());
        }

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

    return committers;
}