List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:es.tsb.ltba.nomhad.gateway.NomhadGateway.java
/** * Put a measurement in Nomhad Server with a correctly formatted date. * /*from w w w .jav a 2 s.c om*/ * @param server * IP of the server. * @param usr * user code. * @param pwd * user password. * @param indicatorGroup * indicator group where the measurement will be place. * @param indicator * indicator corresponding to the measurement. * @param measurement * measured value. * @param formattedate * Time formated according to the Nomhad requisites. * YYYYMMDD'T'HHmmSS'+0100' * @return response from the server. */ public String putMeasurement(String server, String usr, String pwd, String indicatorGroup, String indicator, String measurement, String formattedate, String deviceId) { StringBuilder uri = new StringBuilder(); String header = new String(NOMHAD_URL_HEADER); String body = new String(BODY); if (server.contains(":")) { header = header.replace("localhost:8443", server); } else { LogUtils.logDebug(moduleContext, getClass(), "putMeasurement", new String[] { "Replacing 'localhost' by " + server }, null); header = header = header.replace("localhost", server); LogUtils.logDebug(moduleContext, getClass(), "putMeasurement", new String[] { "New header: " + header }, null); } try { properties.load(new FileInputStream(home + "/" + PROPERTIES_FILE)); isDeployed = properties.getProperty("es.tsbtecnologias.nomhad.ltba.deployed"); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } if (isDeployed.equalsIgnoreCase("true")) { LogUtils.logDebug(moduleContext, getClass(), "putMeasurement", new String[] { "Remote server is a deployed server (PRE or PRO but no DEV)" }, null); header = header.replace("nomhad", "ltba"); } uri.append(header); uri.append(usr); uri.append(OBSERVATIONS_REQUEST); body = body.replace("INDICATOR_GROUP", indicatorGroup); body = body.replace("INDICATOR_MEASURED", indicator); body = body.replace("VALUE_MEASURED", measurement); body = body.replace("19520723T120000+0100", formattedate); body = body.replace(DEVICE_ID, deviceId); NomhadHttpClient nhc = new NomhadHttpClient(usr, pwd); try { LogUtils.logInfo(moduleContext, getClass(), "putMeasurement", new String[] { "------<>-------POSTING TO NOMHAD-------------\nURI: " + uri.toString() + "\nBODY: " + body.toString() + "\nSERVER RESPONSE:" + nhc.post(uri.toString(), body) }, null); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { nhc.stopClient(); } return uri.toString(); }
From source file:com.mingsoft.weixin.util.BaseUtils.java
/** * ???JSON// w w w . ja v a 2 s . c om * @param pathUrl ? * @return ??JSON,???: * jsonsStr.getString("?JSON???") */ public Map<String, Object> jsonStrAuthor(String pathUrl) { HttpGet get = HttpClientConnectionManager.getGetMethod(pathUrl); DefaultHttpClient HTTPCLIENT = new DefaultHttpClient(); try { HttpResponse responses = (HttpResponse) HTTPCLIENT.execute(get); String jsonStr = EntityUtils.toString(responses.getEntity(), "utf-8"); logger.debug("JSON:" + jsonStr); return JsonUtil.getMap4Json(jsonStr); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.phonty.improved.Contacts.java
public boolean delete(String contact_id) { StringBuilder builder = new StringBuilder(); try {// w w w.j a v a 2 s .co m List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("id", contact_id)); 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); } } else { this.VALUE = "0.0"; } } catch (ClientProtocolException e) { this.VALUE = "Protocol exception"; e.printStackTrace(); } catch (IOException e) { this.VALUE = "I.O. Exception"; e.printStackTrace(); } if (VALUE.equals("OK")) return true; else return false; }
From source file:com.seamusdawkins.autocomplete.MainActivity.java
public static JSONObject doGet(Activity act, String url, String charset) { HttpGet conn = new HttpGet(url); conn.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); JSONObject o = null;//from www . j a v a 2s.c om HttpResponse resp; int status = 0; resp = null; try { HttpClient httpClient = new DefaultHttpClient(); resp = httpClient.execute(conn); } catch (ClientProtocolException e) { } catch (IOException e) { } try { if (resp != null) { status = resp.getStatusLine().getStatusCode(); } if (status == 200) { InputStream content = resp.getEntity().getContent(); BufferedReader buffer = new BufferedReader(new InputStreamReader(content)); String text; StringBuilder sb = new StringBuilder(); while ((text = buffer.readLine()) != null) { sb.append(text); } return new JSONObject(sb.toString()); } else { JSONObject obj = new JSONObject(); obj.put("status", String.valueOf(status)); return obj; } } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.megam.deccanplato.provider.box.handler.FileImpl.java
/** * @return//from w w w.ja v a 2 s.co m */ private Map<String, String> share() { Map<String, String> outMap = new HashMap<>(); final String BOX_UPLOAD = "/files/" + args.get(FILE_ID); 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> access = new HashMap<>(); access.put("access", "open"); access.put("unshared_at", "2013-02-28T12:07:46.981+05:30"); Map<String, String> pAccess = new HashMap<>(); pAccess.put("can_download ", "Company"); pAccess.put(" can_preview ", "Company"); Map<String, Map<String, String>> links = new HashMap<>(); links.put("shared_link", access); links.put("permissions", pAccess); TransportTools tools = new TransportTools(BOX_URI + BOX_UPLOAD, null, headerMap); GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter()); Gson obj = gson.setPrettyPrinting().create(); System.out.println(obj.toJson(links)); tools.setContentType(ContentType.APPLICATION_JSON, obj.toJson(links)); String responseBody = ""; TransportResponse response = null; try { response = TransportMachinery.put(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:org.megam.deccanplato.provider.salesforce.chatter.handler.FeedImpl.java
/** * this method deletes a feed item form user feed * it takes input as feed id//w w w .j av a2 s . c om * @param outMap * @return */ private Map<String, String> delete() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v25.0/chatter/feed-items/" + 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.delete(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }
From source file:com.reicast.emulator.debug.About.java
private JSONArray getContent(String urlString) throws IOException, JSONException { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(urlString); try {// w ww. ja v a 2 s.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 { } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return new JSONArray(builder.toString()); }
From source file:com.phonty.improved.Contacts.java
public boolean edit(String id, String phone, String name) { StringBuilder builder = new StringBuilder(); try {/*from w w w . j a v a 2 s . c o m*/ List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("id", id)); nvps.add(new BasicNameValuePair("phone", phone)); nvps.add(new BasicNameValuePair("name", name)); 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); } } else { this.VALUE = "0.0"; } } catch (ClientProtocolException e) { this.VALUE = "Protocol exception"; e.printStackTrace(); } catch (IOException e) { this.VALUE = "I.O. Exception"; e.printStackTrace(); } if (VALUE.equals("OK")) return true; else return false; }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.FeedImpl.java
/** * This method shows news feeds // w ww .java 2s . co m * @param outMap * @return */ private Map<String, String> feed() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ANSWER_ACTIVITY_URL = "/services/data/v25.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_ANSWER_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.FeedImpl.java
/** * this method shows list of likes of a users comment or post * it takes in put as /*from w w w. ja v a2s . com*/ * @param outMap * @return */ private Map<String, String> like() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v25.0/chatter/feed-items/" + args.get(ID) + "/likes"; 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; }