List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java
/** * Driver send an offer to the hitchhiker * //from w w w .j a v a 2s .c o 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.d(TAG, sid); Log.d(TAG, String.valueOf(trip_id)); Log.d(TAG, String.valueOf(query_id)); Log.d(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; }
From source file:org.apache.geode.rest.internal.web.RestSecurityDUnitTest.java
private HttpResponse doRequest(HttpRequestBase request, String username, String password) throws MalformedURLException { HttpHost targetHost = new HttpHost(HOSTNAME, this.restPort, PROTOCOL); CloseableHttpClient httpclient = HttpClients.custom().build(); HttpClientContext clientContext = HttpClientContext.create(); // if username is null, do not put in authentication if (username != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password)); httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); clientContext.setCredentialsProvider(credsProvider); clientContext.setAuthCache(authCache); }//from w w w .java 2 s . com try { return httpclient.execute(targetHost, request, clientContext); } catch (ClientProtocolException e) { e.printStackTrace(); fail("Rest GET should not have thrown ClientProtocolException!"); } catch (IOException e) { e.printStackTrace(); fail("Rest GET Request should not have thrown IOException!"); } return null; }
From source file:com.phonty.improved.Calls.java
public boolean get(String country) { Log.e("RESPONSE", "Start getting"); String line = null;/*w ww . j a v a 2 s.c om*/ StringBuilder builder = new StringBuilder(); try { String locale = context.getResources().getConfiguration().locale.getCountry(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("locale", locale)); 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)); while ((line = reader.readLine()) != null) { builder.append(line); Log.e("RESPONSE", line); if (parse(line) != null) return true; else return false; } } else { } } catch (ClientProtocolException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return false; }
From source file:org.megam.deccanplato.provider.box.handler.UserImpl.java
/** * @return/*from w w w . j ava 2 s.com*/ */ private Map<String, String> create() { Map<String, String> outMap = new HashMap<>(); final String BOX_UPLOAD = "/users"; Map<String, String> headerMap = new HashMap<String, String>(); headerMap.put("Authorization", "BoxAuth api_key=" + args.get(API_KEY) + "&auth_token=" + args.get(TOKEN)); Map<String, String> boxList = new HashMap<>(); boxList.put("login", args.get(LOGIN_ID)); boxList.put("name", args.get(NAME)); boxList.put("role", args.get(ROLE)); boxList.put("status", args.get(STATUS)); Gson obj = new GsonBuilder().setPrettyPrinting().create(); TransportTools tools = new TransportTools(BOX_URI + BOX_UPLOAD, null, headerMap); tools.setContentType(ContentType.APPLICATION_JSON, obj.toJson(boxList)); String responseBody = null; TransportResponse response = null; try { response = TransportMachinery.post(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:com.phonty.improved.Balance.java
public String get() { StringBuilder builder = new StringBuilder(); String value = "0"; CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore);//from w w w .j a v a 2s .com try { String locale = context.getResources().getConfiguration().locale.getCountry(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("locale", locale)); 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); value = Parse(line); this.VALUE = value; } } else { this.VALUE = "0.0"; } } catch (ClientProtocolException e) { this.VALUE = "0.0"; e.printStackTrace(); } catch (IOException e) { this.VALUE = "0.0"; e.printStackTrace(); } return value; }
From source file:com.phonty.improved.Rates.java
public boolean get(String country) { Log.e("RESPONSE", "Start getting"); String line = null;// ww w . j a va 2 s . c o m StringBuilder builder = new StringBuilder(); try { String locale = context.getResources().getConfiguration().locale.getCountry(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("country", country)); nvps.add(new BasicNameValuePair("locale", locale)); 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)); while ((line = reader.readLine()) != null) { builder.append(line); Log.e("RESPONSE", line); if (parse(line) != null) return true; else return false; } } else { } } catch (ClientProtocolException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return false; }
From source file:com.ibm.dtf.EmployeeAdapterResource.java
@ApiOperation(value = "Employee Details by Id", notes = "Return the employee detials, by Id") @ApiResponses(value = { @ApiResponse(code = 200, message = "Property value returned."), @ApiResponse(code = 404, message = "Property value not found.") }) @GET//from w w w .jav a 2 s. c o m @Path("/details/{id}") @Produces(MediaType.TEXT_PLAIN) public String getDetails( @ApiParam(value = "The name of the property to lookup", required = true) @PathParam("id") String id) { // Get the value of the property: System.out.println(">> in getDetails() ..."); System.out.println(">> id :[" + id + "]"); String rsp = null; try { rsp = getHttp(API_ENDPOINT + "/" + id); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rsp; }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java
/** * Announce a trip to the web service/*ww w .ja va2 s . c om*/ * * @return true if succeeded */ public static String announceTrip(String session_id, String destination, float current_lat, float current_lon, int avail_seats, Date date) { listToParse.clear(); listToParse.add(new ParamObject("sid", session_id, false)); listToParse.add(new ParamObject("destination", destination, true)); listToParse.add(new ParamObject("avail_seats", String.valueOf(avail_seats), true)); if (date != null) { listToParse.add(new ParamObject("date", String.valueOf(date.getTime()), true)); } if (current_lat < Constants.COORDINATE_INVALID) { listToParse.add(new ParamObject("current_lat", String.valueOf(current_lat), true)); } if (current_lon < Constants.COORDINATE_INVALID) { listToParse.add(new ParamObject("current_lon", String.valueOf(current_lon), true)); } JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "trip_announce.php"); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int tripId = -1; JsonElement status = object.get("status"); if (object != null && object.get(ERROR) == null && status != null) { JsonElement id = object.get("id"); if (status.getAsString().equals("announced") && id != null) { tripId = id.getAsInt(); Model.getInstance().setTripId(tripId); Log.d(TAG, String.valueOf(Model.getInstance().getTripId())); } return status.getAsString(); } else { setError(object); return ERROR; } }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java
/** * Get profile of given user id/*from www. j ava 2 s.c o m*/ * * @param session_id * actual session id * @param id * of an user */ public static Profile getProfile(String session_id, int id) { listToParse.clear(); listToParse.add(new ParamObject("id", String.valueOf(id), false)); listToParse.add(new ParamObject("sid", session_id, false)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "get_profile.php"); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } boolean suc = false; String username = null; String email = "xxx"; String firstname = "xxx"; String lastname = "xxx"; String tel = "xxx"; String description = null; boolean email_public = false; boolean firstname_public = false; boolean lastname_public = false; boolean tel_public = false; int userid = 0; double rating_avg = 0; int rating_num = 0; if (object != null) { suc = object.get("successful").getAsBoolean(); userid = object.get("id").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(); if (email_public) { email = object.get("email").getAsString(); } if (firstname_public) { firstname = object.get("firstname").getAsString(); } if (lastname_public) { lastname = object.get("lastname").getAsString(); } if (tel_public) { tel = object.get("tel").getAsString(); } username = object.get("username").getAsString(); description = object.get("description").getAsString(); Log.i(TAG, "GETPROFILE_: description:" + description); object.get("regdate").getAsString(); rating_avg = object.get("rating_avg").getAsFloat(); rating_num = object.get("rating_num").getAsInt(); } // String userid = object.get("id").getAsString(); // TODO // String regdate = object.get("regdate").getAsString(); Profile profile; Date date = new Date(); if (suc) { profile = new Profile(userid, 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.dhbw.organizer.calendar.backend.manager.NetworkManager.java
/** * Downloads a File from the given URl via HTTP GET and gzipped and returns * an open InputStream to read from//from w w w . j a va 2 s. co m * * @param url * @return InputStream */ public InputStream downloadHttpFile(String url) { if (isOnline()) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); if (!httpGet.containsHeader("Accept-Encoding")) { httpGet.addHeader("Accept-Encoding", "gzip"); } HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpGet); int httpStatus = httpResponse.getStatusLine().getStatusCode(); Log.i(TAG, "downloadHttpFile() url = " + url + " HTTP: " + httpStatus); HttpEntity entity = httpResponse.getEntity(); return AndroidHttpClient.getUngzippedContent(entity); } catch (ClientProtocolException e) { e.printStackTrace(); Log.e(TAG, "downloadHttpFile() ERROR: " + e.getMessage()); return null; } catch (IOException e) { Log.e(TAG, "downloadHttpFile() ERROR: " + e.getMessage()); e.printStackTrace(); return null; } } else return null; }