List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
/** * End the trip/*from ww w.j a v a 2 s . co m*/ * * @param sid * @param trip_id * @return */ public static String endTrip(String sid, int trip_id) { listToParse.clear(); listToParse.add(new ParamObject("sid", sid, false)); listToParse.add(new ParamObject("id", String.valueOf(trip_id), true)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "trip_ended.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:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
/** * Update the data of the trip//w w w. j a v a 2s .com * * @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:rpi.rpiface.PostAsyncTask.java
/** * Se ejecuta en paralelo sin bloquear el sistema * /*from www . j ava2 s. co m*/ * @param param * Array de parmetros: el primero se corresponde con el texto a * envir, el segundo con la direccin, el tercero con el puerto y * el cuarto con el path */ protected Boolean doInBackground(String... param) { // Se asignan variables a los parmetros del asynctask String value = param[0]; String rpi = param[1]; String port = param[2]; String rpiPath = param[3]; String rpiParam = param[4]; // Se crea un cliente http HttpClient httpClient = new DefaultHttpClient(); // Se crea la url String url = rpi + ":" + port + rpiPath; // Se crea un objeto httpPost HttpPost httpPost = new HttpPost(url); // Se crea una lista con los parmetros List<NameValuePair> params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair(rpiParam, value)); // String paramString = URLEncodedUtils.format(params, "iso-8859-15"); Log.i(LOGTAG + " Asynctask" + " Http get:", url); try { // Se le pasan los parmetros debidamente formateados al httpPost httpPost.setEntity(new UrlEncodedFormEntity(params, "iso-8859-15")); // Se ejecuta el cliente pasndole como parmetro la peticin post. HttpResponse response = httpClient.execute(httpPost); Log.i(LOGTAG + " Asynctask" + " Http Response:", response.toString()); } catch (ClientProtocolException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java
private String readVideosFromRemoteService() { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet("http://vimeo.com/api/v2/group/shortfilms/videos.json"); try {/*from www . java 2s . c o m*/ HttpResponse response = client.execute(httpGet); 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); } } else { Log.e("readVideos", "Failed to download file"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:com.oauth.servlet.AuthorizationCallbackServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {// ww w . j a va2 s .c om System.err.println(req.getQueryString()); System.err.println(req.getRequestURI()); String token = null; String responseBody = null; if (req.getParameter("code") != null) { HttpClient httpclient = new DefaultHttpClient(); String authCode = req.getParameter("code"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { if (req.getRequestURI().indexOf("git") > 0) { HttpGet httpget = new HttpGet(client.getAccessTokenUrl(authCode)); responseBody = httpclient.execute(httpget, responseHandler); int accessTokenStartIndex = responseBody.indexOf("access_token=") + "access_token=".length(); token = responseBody.substring(accessTokenStartIndex, responseBody.indexOf("&", accessTokenStartIndex)); } else if (req.getRequestURI().indexOf("isam") > 0) { System.err.println(iSAMClient.getAccessTokenUrl()); HttpPost httpPost = new HttpPost(iSAMClient.getAccessTokenUrl()); httpPost.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); System.err.println("Post Params--------"); for (Iterator<NameValuePair> postParamIter = iSAMClient.getPostParams(authCode) .iterator(); postParamIter.hasNext();) { NameValuePair postParam = postParamIter.next(); System.err.println(postParam.getName() + "=" + postParam.getValue()); } httpPost.setEntity(new UrlEncodedFormEntity(iSAMClient.getPostParams(authCode))); System.err.println("Post Params--------"); responseBody = httpclient.execute(httpPost, responseHandler); token = parseJsonString(responseBody); } else { resp.sendError(HttpStatus.SC_FORBIDDEN); } System.err.println(responseBody); req.setAttribute("Response", responseBody); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } resp.sendRedirect("userDetails.jsp?token=" + token); } /*else if(req.getParameter("access_token") != null) { Writer w = resp.getWriter(); w.write("<html><body><center>"); w.write("<h3>"); w.write("User Code [" + req.getParameter("access_token") + "] has successfully logged in!"); w.write("</h3>"); w.write("</center></body></html>"); w.flush(); w.close(); } */else { Writer w = resp.getWriter(); w.write("<html><body><center>"); w.write("<h3>"); w.write("UNAUTHORIZED Access!"); w.write("</h3>"); w.write("</center></body></html>"); w.flush(); w.close(); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
/** * Logout the user with given session id * //from w ww. j ava 2 s . c o m * @param session_id * @return true, if logout succeeded */ public static String logout(String session_id) { listToParse.clear(); listToParse.add(new ParamObject("sid", session_id, false)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "logout.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(); status = object.get("status").getAsString(); } if (suc) { return status; } else { return status; } }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
/** * Dummy method don't touch it//from w w w. j a v a 2 s . com * * @param name * @return */ public static String dummyMethod(String name, String mood) { Log.i(TAG, "To Parse name:" + name); Log.i(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.i(TAG, "Postoutput:" + out_pos); Log.i(TAG, "Getoutput:" + out_get); return null; }
From source file:com.kingja.springmvc.util.HttpRequestUtils.java
public String get(String path) { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from ww w .j a v a 2 s. c om // httpget. HttpGet httpget = new HttpGet(path); // get. CloseableHttpResponse response = httpclient.execute(httpget); try { // ?? HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toString(entity); } } finally { response.close(); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // ,? try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } return ""; }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
public static PositionObject getUserPosition(String sid, int user_id) { listToParse.clear();/*from www.ja va 2 s. co 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, "getPosition.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.JSonRequestReaderWS.java
/** * Hitchhiker can accept or decline an offer * /*from w ww .jav a 2 s . co 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.i(null, "STATUS after handleOFFER: " + status); return status; } } Log.i(null, "STATUS after handleOFFER: " + status); return status; }