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.newtonehome.hobbled_tone.client.DataAccess.java

@Override
protected Void doInBackground(Void... params) {

    Log.d(TAG, "starting DataAccess");

    //      ServiceResponse response = Resting.get("http://192.168.1.100/sys_stat",3000);
    //      //from w ww  .  j av  a2  s . c o  m
    //      Log.d(TAG,"response is " + response);

    //HttpContext localContext = new BasicHttpContext();
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet("http://192.168.1.100:3000/sys_stat/0");

    try {
        HttpResponse response = client.execute(get);
        Log.d(TAG, "response is " + response.getStatusLine().toString());

        HttpEntity entity = response.getEntity();

        if (entity != null) {
            InputStream instream = entity.getContent();
            String result = convertStreamToString(instream);
            instream.close();
            Log.d(TAG, "result is " + result);
        }

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Log.d(TAG, "done");

    return null;
}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

/**
 * Update the data of the trip/*from  ww w .  j  ava 2  s .  c  o m*/
 * 
 * @param sid
 * @param trip_id
 * @param avail_seats
 * @return
 */
public static String tripUpdateData(String sid, int trip_id, int avail_seats) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("id", String.valueOf(trip_id), true));
    listToParse.add(new ParamObject("avail_seats", String.valueOf(avail_seats), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "trip_update_data.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String status = null;
    if (object != null) {
        object.get("successful").getAsBoolean();
        status = object.get("status").getAsString();
        return status;
    }

    return status;
}

From source file:SearchForSimilarImages.java

public String GetUrlContentAsString(String searchToken, String tagsString, String imageTypeAsString,
        String sizeAsString, String licenseAsString, String safeSearchAsString) {

    StringBuffer body = null;/*from  w  ww  .  j a va 2s . c  o m*/
    String imageType = null, sizeType = null, licenseType = null, safeSearchType = null;
    try {

        if (!imageTypeAsString.equals("unspecified")) {
            imageType = "&imagetype=" + imageTypeAsString;
        } else {
            imageType = "";
        }

        if (!sizeAsString.equals("unspecified")) {
            sizeType = "&size=" + sizeAsString;
        } else {
            sizeType = "";
        }

        if (!licenseAsString.equals("unspecified")) {
            licenseType = "&license=" + licenseAsString;
        } else {
            licenseType = "";
        }

        if (!safeSearchAsString.equals("unspecified")) {
            safeSearchType = "&safesearch=" + safeSearchAsString;
        } else {
            safeSearchType = "";
        }
        String count = "&count=2";
        // String count = "";
        String url = "https://bingapis.azure-api.net/api/v5/images/search?q=" + tagsString + count
                + "&mkt=en-us" + imageType + sizeType + licenseType + safeSearchType;

        System.out.println("url to search " + url);

        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(url);
        request.setHeader("Ocp-Apim-Subscription-Key", searchToken);

        HttpResponse response = client.execute(request);

        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        body = new StringBuffer();
        String line;
        while ((line = reader.readLine()) != null) {
            body.append(line);
        }

        // System.out.println(body);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return body.toString();

}

From source file:SearchForSimilarImages.java

public String GetUrlContentAsStringWithNumber(String searchToken, String tagsString, String imageTypeAsString,
        String sizeAsString, String licenseAsString, String safeSearchAsString, String count) {

    StringBuffer body = null;/*from www .  j  av a2s  . c o m*/
    String imageType = null, sizeType = null, licenseType = null, safeSearchType = null;
    try {

        if (!imageTypeAsString.equals("unspecified")) {
            imageType = "&imagetype=" + imageTypeAsString;
        } else {
            imageType = "";
        }

        if (!sizeAsString.equals("unspecified")) {
            sizeType = "&size=" + sizeAsString;
        } else {
            sizeType = "";
        }

        if (!licenseAsString.equals("unspecified")) {
            licenseType = "&license=" + licenseAsString;
        } else {
            licenseType = "";
        }

        if (!safeSearchAsString.equals("unspecified")) {
            safeSearchType = "&safesearch=" + safeSearchAsString;
        } else {
            safeSearchType = "";
        }
        String countParameter = "&count=" + count;
        // String count = "";
        String url = "https://bingapis.azure-api.net/api/v5/images/search?q=" + tagsString + countParameter
                + "&mkt=en-us" + imageType + sizeType + licenseType + safeSearchType;

        System.out.println("url to search " + url);

        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(url);
        request.setHeader("Ocp-Apim-Subscription-Key", searchToken);

        HttpResponse response = client.execute(request);

        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        body = new StringBuffer();
        String line;
        while ((line = reader.readLine()) != null) {
            body.append(line);
        }

        // System.out.println(body);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return body.toString();

}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

public static String offer_accepted(String sid, int offer_id) {
    listToParse.clear();/*  www . j  ava 2 s .c  om*/
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("offer_id", String.valueOf(offer_id), true));
    JsonObject object = null;

    try {
        object = JSonRequestProvider.doRequest(listToParse, "offer_status.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    new ArrayList<PassengerObject>();
    String status = "";
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            status = object.get("status").getAsString();
        }
    }

    return status;
}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

public static String rateUser(String sid, int userid, int tripid, int rating) {
    listToParse.clear();//  ww  w  .  j a v  a 2  s.  c  om
    listToParse.add(new ParamObject("sid", sid, false));
    listToParse.add(new ParamObject("recipient", String.valueOf(userid), true));
    listToParse.add(new ParamObject("trip", String.valueOf(tripid), true));
    listToParse.add(new ParamObject("rating", String.valueOf(rating), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "ride_rate.php");

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    String status = "";
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            status = object.get("status").getAsString();
        }
    }
    return status;
}

From source file:com.openingdesign.qna.service.impl.QueryAndResponseLocalServiceImpl.java

private void createPadFromTemplate(QueryAndResponse qnr, String templatePadId) throws PortalException {

    // /ep/copyPad?old=padId&new=padId
    String urlText = RandomPadIdGenerator.BASE_URL + "ep/copyPad?old=" + templatePadId + "&new="
            + qnr.getEtherpadId();/*from   w w  w. java2 s.  co  m*/
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(urlText);
    System.out.println("COPY_PAD, URI=" + get.getURI());
    try {
        HttpResponse response = client.execute(get);
        System.out.println("RESPONSE: status_line=" + response.getStatusLine());

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        throw new PortalException("unable to create pad from template");
    } catch (IOException e) {
        e.printStackTrace();
        throw new PortalException("unable to create pad from template");
    }
}

From source file:com.phonty.improved.Login.java

public boolean process() {
    StringBuilder builder = new StringBuilder();
    final String cookieName = "sessionid";
    httppost = new HttpPost(APIURL);

    try {/*www  .j a v  a2s. c o m*/
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", login));
        nvps.add(new BasicNameValuePair("password", password));

        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = client.execute(httppost);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();

        if (statusCode == 200) {
            List<Cookie> cookies = client.getCookieStore().getCookies();
            if (cookies.isEmpty()) {
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    if (cookieName.equals(cookies.get(i).getName())) {
                        // We get the session id. That what auth is.
                        SESSION_COOKIE = cookies.get(i);
                        SESSION_ID = cookies.get(i).getValue();
                    }
                }
            }

            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);
                this.VALUE = line;
            }
        } else {
            this.VALUE = "0.0";
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    if (this.VALUE.equals("AUTH_OK")) {
        return true;
    } else {
        logout();
        return false;
    }
}

From source file:com.worthed.googleplus.HttpUtils.java

/**
 * Send post request.//from  w w  w . jav a  2 s.  c  om
 * @param url 
 * @param params
 * @return It's a error if result start with "Error:".
 */
public String doPost(String url, List<NameValuePair> params) {
    HttpClient httpClient = getHttpClient();
    /* HTTPPost */
    HttpPost httpRequest = new HttpPost(url);
    String strResult = ERROR_PREFIX;

    try {
        /* ? */
        httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        /* ??? */
        HttpResponse httpResponse = httpClient.execute(httpRequest);
        /* ??200 ok */
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            /* ? */
            strResult = EntityUtils.toString(httpResponse.getEntity());
        } else {
            strResult += httpResponse.getStatusLine().toString();
        }
    } catch (ClientProtocolException e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    } catch (Exception e) {
        strResult += e.getMessage().toString();
        e.printStackTrace();
        return null;
    }
    Log.w(TAG, strResult);
    return strResult;
}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

/**
 * update the position of the user (driver)
 * /*from  w  w w  . j  a va  2  s  .  c o  m*/
 * @param sid
 * @param trip_id
 * @param current_lat
 * @param current_lon
 * @return
 */
public static String tripUpdatePos(String sid, int trip_id, float current_lat, float current_lon) {

    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("id", String.valueOf(trip_id), true));
    listToParse.add(new ParamObject("current_lat", String.valueOf(current_lat), true));
    listToParse.add(new ParamObject("current_lon", String.valueOf(current_lon), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "trip_update_pos.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String status = null;
    if (object != null) {
        object.get("successful").getAsBoolean();
        status = object.get("status").getAsString();
        return status;
    }

    return status;
}