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:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

/**
 * End the trip/*  w w  w.  j a v  a2  s .c  om*/
 * 
 * @param sid
 * @param trip_id
 * @return ERROR when error
 */
public static String endTrip(String sid, int trip_id) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));
    if (trip_id > -1) {
        listToParse.add(new ParamObject("id", String.valueOf(trip_id), true));
    }

    JsonObject json = null;
    try {
        json = JSonRequestProvider.doRequest(listToParse, "trip_end.php");
        JsonElement status = json.get("status");
        if (json != null && json.get(ERROR) == null && status != null) {
            return json.get("status").getAsString();
        } else {
            setError(json);
            return ERROR;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        Log.e(TAG, json == null ? "JSON = NULL" : json.toString());
    }
    return ERROR;
}

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

public static String userUpdatePos(String sid, float lat, float lon) {
    listToParse.clear();/*from   w w  w. j  ava  2  s .c  o  m*/
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("lat", String.valueOf(lat), true));
    listToParse.add(new ParamObject("lon", String.valueOf(lon), true));

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

        return status;
    }

    return status;
}

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

/**
 * Dummy method don't touch it/*from ww  w  . j  av  a2 s . c o  m*/
 * 
 * @param name
 * @return
 */
public static String dummyMethod(String name, String mood) {
    Log.d(TAG, "To Parse name:" + name);
    Log.d(TAG, "To Parse mood:" + mood);
    listToParse.clear();
    listToParse.add(new ParamObject("name", name, true));
    listToParse.add(new ParamObject("mood", mood, false));

    JsonObject object = null;
    String out_pos = null;
    String out_get = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "test.php");

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (object != null) {
        out_pos = object.get("output_pos").toString();
        out_get = object.get("output_get").toString();
    }

    Log.d(TAG, "Postoutput:" + out_pos);
    Log.d(TAG, "Getoutput:" + out_get);
    return null;
}

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

public static String getOpenTrip(String sessionID) {
    String status = ERROR;//from w w  w  .  j  av  a 2  s.  c  om

    listToParse.clear();
    listToParse.add(new ParamObject("sid", sessionID, false));
    JsonObject json = null;
    try {
        json = JSonRequestProvider.doRequest(listToParse, "trip_get_open.php");
        if (json != null && json.get(ERROR) == null) {
            if (json.get("trip_id") != null) {
                Trip trip = new Trip(json.get("trip_id").getAsInt(), Model.getInstance().getUserId(),
                        json.get("avail_seats").getAsInt(), json.get("destination").getAsString(),
                        json.get("creation").getAsLong(), 0);
                Model.getInstance().setOpenTrip(trip);
                return "TRUE";
            } else {
                return "FALSE";
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
    }
    setError(json);
    return status;
}

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

public boolean send(String phone, String message) {
    StringBuilder builder = new StringBuilder();
    try {/*from w  ww. j a v  a 2  s.c  om*/
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("phone", phone));
        nvps.add(new BasicNameValuePair("message", message));

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

        StatusLine statusLine = response.getStatusLine();
        int 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);
                STATUS = Parse(line);
            }
        } else {
            this.STATUS = "0.0";
        }
    } catch (ClientProtocolException e) {
        this.STATUS = "SE";
        e.printStackTrace();
    } catch (IOException e) {
        this.STATUS = "SE";
        e.printStackTrace();
    }

    if (STATUS.equals("OK"))
        return true;
    return false;
}

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

public static PositionObject getUserPosition(String sid, int user_id) {
    listToParse.clear();/*from   w  w  w.  jav  a2  s  . c  o m*/
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("user_id", String.valueOf(user_id), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "get_position.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    JsonArray array;
    PositionObject posObj = null;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            array = object.get("position").getAsJsonArray();
            float lat = array.get(0).getAsFloat();
            float lon = array.get(1).getAsFloat();
            posObj = new PositionObject(lat, lon);
        }

    }
    return posObj;
}

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

/**
 * Hitchhiker can accept or decline an offer
 * /*w  w  w. ja  va2  s  . c  o  m*/
 * @param sid
 * @param offer_id
 * @param accept
 * @return status
 */
public static String handleOffer(String sid, int offer_id, boolean accept) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

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

    try {
        object = JSonRequestProvider.doRequest(listToParse, "offer_handle.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();
            Log.d(null, "STATUS after handleOFFER: " + status);
            return status;
        }
    }
    Log.d(null, "STATUS after handleOFFER: " + status);
    return status;
}

From source file:org.megam.deccanplato.provider.box.handler.UserImpl.java

/**
 * @return/*from w ww .  j  av  a 2 s.com*/
 */
private Map<String, String> delete() {
    Map<String, String> outMap = new HashMap<>();
    final String BOX_UPLOAD = "/users/" + args.get(USER_ID);

    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put("Authorization", "BoxAuth api_key=" + args.get(API_KEY) + "&auth_token=" + args.get(TOKEN));

    TransportTools tools = new TransportTools(BOX_URI + BOX_UPLOAD, null, headerMap);
    String responseBody = null;
    TransportResponse response = null;
    try {
        response = TransportMachinery.delete(tools);
        responseBody = response.entityToString();
        System.out.println("OUTPUT:" + responseBody);
    } catch (ClientProtocolException ce) {
        ce.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    outMap.put(OUTPUT, responseBody);
    return outMap;
}

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

/**
 * Returns the Profile of the logged user
 * //w w w.  ja v  a 2 s . c  o m
 * @param sid
 * @return Profile
 */
public static Profile getOwnProfile(String sid) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

    JsonObject object = null;

    try {
        object = JSonRequestProvider.doRequest(listToParse, "own_profile.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    int id = 0;
    String username = null;
    String email = null;
    String firstname = null;
    String lastname = null;
    String tel = null;
    String description = null;
    boolean email_public = false;
    boolean firstname_public = false;
    boolean lastname_public = false;
    boolean tel_public = false;

    double rating_avg = 0;
    int rating_num = 0;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        id = object.get("id").getAsInt();
        username = object.get("username").getAsString();
        Log.i(TAG, "USERNAME:" + username);
        email = object.get("email").getAsString();
        firstname = object.get("firstname").getAsString();
        lastname = object.get("lastname").getAsString();
        tel = object.get("tel").getAsString();
        description = object.get("description").getAsString();
        object.get("regdate").getAsString();
        rating_avg = object.get("rating_avg").getAsFloat();
        rating_num = object.get("rating_num").getAsInt();
        email_public = object.get("email_public").getAsBoolean();
        firstname_public = object.get("firstname_public").getAsBoolean();
        lastname_public = object.get("lastname_public").getAsBoolean();
        tel_public = object.get("tel_public").getAsBoolean();
    }

    // String userid = object.get("id").getAsString();
    // TODO
    // String regdate = object.get("regdate").getAsString();
    Profile profile;

    Date date = new Date();
    if (suc) {
        profile = new Profile(id, username, email, firstname, lastname, tel, description, date, email_public,
                firstname_public, lastname_public, tel_public, rating_avg, rating_num);
        return profile;
    }
    return null;
}

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

/**
 * Delete the active query/* www.j a v a 2 s. c  o m*/
 * 
 * @param sid
 * @param id
 *            query id
 * @return String status
 */
public static String stopQuery(String sid, int id) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

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

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "query_delete.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    boolean suc = false;
    String status = null;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            // status = object.get("status").getAsString();
            status = "deleted";
            Log.d(TAG, "STATUS AFTER STOPQUERY:" + status);
            return status;
        }
        Log.d(TAG, "Status after STOPQUERY:" + status + ", suc" + suc);
    }

    return status;
}