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.JSonRequestReaderWS.java

/**
 * Delete the active query// ww  w . ja va2 s  .  com
 * 
 * @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.i(TAG, "STATUS AFTER STOPQUERY:" + status);
            return status;
        }
        Log.i(TAG, "Status after STOPQUERY:" + status + ", suc" + suc);
    }

    return status;
}

From source file:servlet.SecurityServlet.java

private String getUserMailAddressFromJsonResponse(String accessToken, HttpSession httpSession) {
    String email = null;/*from  w w w .j  ava2  s  . com*/
    HttpClient httpclient = new DefaultHttpClient();
    try {
        //         if (accessToken != null && ! "".equals(accessToken)) {
        if (accessToken != null) {
            String newUrl = "https://graph.facebook.com/me/friends?access_token=" + accessToken;
            httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(newUrl);
            System.out.println("Get info from face --> executing request: " + httpget.getURI());
            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = httpclient.execute(httpget, responseHandler);
            JSONObject json = (JSONObject) JSONSerializer.toJSON(responseBody);

            System.out.println("from json " + json.toString());

            String facebookId = json.getString("id");
            String firstName = json.getString("first_name");
            String lastName = json.getString("last_name");
            email = json.getString("email");

            //put user data in session
            httpSession.setAttribute("FACEBOOK_USER",
                    firstName + " " + lastName + ", facebookId:" + facebookId);

        } else {
            System.err.println("Token za facebook je null");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
    return email;
}

From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.NewsFeedImpl.java

/**
 * Returns all feed items from all groups the logged-in user either
 * owns or is a member of, as well as all files, records, and all
 * users the current user follows.//  w w  w.ja va2  s .c  o  m
 * @param outMap
 * @return
 */
private Map<String, String> feed() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/feeds/news/" + args.get(ID)
            + "/feed-items";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCE_CHATTER_ACTIVITY_URL, null,
            header);
    try {
        String response = TransportMachinery.get(tst).entityToString();
        outMap.put(OUTPUT, response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.NewsFeedImpl.java

/**
 * This class shows news feed url of a user and news feed modified url
 * it takes input as user id. /*from w  ww  . ja v a  2s .  c o  m*/
 * @param outMap
 * @return
 */
private Map<String, String> list() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/feeds/news/" + args.get(ID);
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCE_CHATTER_ACTIVITY_URL, null,
            header);

    try {
        String response = TransportMachinery.get(tst).entityToString();
        outMap.put(OUTPUT, response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

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

/**
 * Try to login into the app with given username and password
 * //ww  w. j a  va  2 s.co  m
 * @param name
 *            username
 * @param pw
 *            password
 * 
 * @return status (see vHike/webservice/design.html)
 */
public static String login(String username, String pw) {

    listToParse.clear();
    listToParse.add(new ParamObject("username", username, true));
    listToParse.add(new ParamObject("password", pw, true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "login.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
    }
    String sid = null;
    String status = null;
    if (suc) {
        status = object.get("status").getAsString();
        Log.i(TAG, "STATUS NACH DEM LOGIN:" + status);
        if (!status.equals("invalid")) {
            sid = object.get("sid").getAsString();
            Model.getInstance().setSid(sid);
            Model.getInstance().setOwnProfile(getOwnProfile(sid));
        }
        return status;
    }
    return status;
}

From source file:com.huangyifei.etag.HttpClientWrapper.java

@Override
public HttpResult excute() {
    HttpResult result = null;/* w w  w.j  a  v a2  s  . c o m*/
    try {
        response = client.execute(request);
        result = new HttpResult();
        result.statusCode = response.getStatusLine().getStatusCode();
        if (response.getEntity() != null) {
            result.body = EntityUtils.toString(response.getEntity());
        }
        Header header = response.getFirstHeader(EtagCache.ETAG_RESPONSE_HEADER);
        if (header != null) {
            result.etag = header.getValue();
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:de.felixschulze.acra.JsonSender.java

private void sendHttpPost(String data, URL url, String login, String password) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {// ww  w .j  av a  2  s  .c om
        HttpPost httPost = new HttpPost(url.toString());

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("json", data));

        httPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

        HttpResponse httpResponse = httpClient.execute(httPost);

        Log.d(LOG_TAG, "Server Status: " + httpResponse.getStatusLine());
        Log.d(LOG_TAG, "Server Response: " + EntityUtils.toString(httpResponse.getEntity()));

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

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

/**
 * Start searching for drivers/*from w w w  .  j av a 2  s. c o  m*/
 * 
 * @param sid
 * @param destination
 * @param current_lat
 * @param current_lon
 * @param seats
 * @return int id of the query
 */
public static int startQuery(String sid, String destination, float current_lat, float current_lon, int seats) {
    Log.i(TAG, sid);
    Log.i(TAG, destination);
    Log.i(TAG, String.valueOf(current_lat));
    Log.i(TAG, String.valueOf(current_lon));
    Log.i(TAG, String.valueOf(seats));
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

    listToParse.add(new ParamObject("destination", destination, true));
    listToParse.add(new ParamObject("current_lat", String.valueOf(current_lat), true));
    listToParse.add(new ParamObject("current_lon", String.valueOf(current_lon), true));
    listToParse.add(new ParamObject("seats", String.valueOf(seats), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "query_start.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    int id = Constants.QUERY_ID_ERROR;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            id = object.get("id").getAsInt();
            Log.i(TAG, String.valueOf(id));
            return id;
        }
    }

    return id;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.RetrieveSEEHandler.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {/*from  w w  w. j  a va2  s  . com*/
        if (SkillproService.getSkillproProvider().getSEERepo().isEmpty()) {
            getAllSEE();
        } else {
            getNewSEE();
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception",
                e.getMessage(), SWT.SHEET);
    } catch (IOException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception",
                e.getMessage(), SWT.SHEET);
    }
    return null;
}

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

/**
 * Driver send an offer to the hitchhiker
 * /*from   w  w  w .  j  av a  2  s  .  co m*/
 * @param sid
 * @param trip_id
 * @param query_id
 * @param message
 * @return status
 */
public static String sendOffer(String sid, int trip_id, int query_id, String message) {

    Log.i(TAG, sid);
    Log.i(TAG, String.valueOf(trip_id));
    Log.i(TAG, String.valueOf(query_id));
    Log.i(TAG, message);

    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));
    listToParse.add(new ParamObject("trip", String.valueOf(trip_id), true));
    listToParse.add(new ParamObject("query", String.valueOf(query_id), true));
    listToParse.add(new ParamObject("message", String.valueOf(message), true));

    JsonObject object = null;

    try {
        object = JSonRequestProvider.doRequest(listToParse, "offer.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();
            if (status.equals("sent")) {
                status = String.valueOf(object.get("offer_id").getAsInt());
            }
            return status;
        }
    }
    return status;
}