List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:org.megam.deccanplato.provider.sugarcrm.handler.BusinessActivityImpl.java
/** * This method deals with update business activity for users,accounts and leads, * and it takes outMap MAP(contains json data) value as input and returns a MAP * this method uses MutableSugar class to populate sugarCRM json input. * @param outMap.//w w w .j a v a 2s . com * */ private Map<String, String> update(Map<String, String> outMap) { MutableSugar scu = new MutableSugar(name(), args); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(scu); List<NameValuePair> userAttr = new ArrayList<NameValuePair>(); userAttr.add(new BasicNameValuePair(METHOD, SET_METHOD)); userAttr.add(new BasicNameValuePair(INPUT_TYPE, TYPE)); userAttr.add(new BasicNameValuePair(RESPONSE_TYPE, TYPE)); userAttr.add(new BasicNameValuePair(DATA, json)); TransportTools tst = new TransportTools(SUGAR_URL, userAttr); String responseBody = null; TransportResponse response = null; try { response = TransportMachinery.post(tst); responseBody = response.entityToString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } outMap.put(OUTPUT, responseBody); return outMap; }
From source file:androidmapsdefinitivo.android.bajaintec.com.androidmapsdefinitivo.Control.RestClient.java
private void executeRequest(HttpUriRequest request, String url) { HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse;//w ww. ja va 2s. com try { httpResponse = client.execute(request); responseCode = httpResponse.getStatusLine().getStatusCode(); message = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); response = convertStreamToString(instream); // Closing the input stream will trigger connection release instream.close(); } } catch (ClientProtocolException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } catch (IOException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } }
From source file:rpi.rpiface.GetAsyncTask.java
/** * Se ejecuta en paralelo sin bloquear el sistema * // www. j a v a2 s . c om * @param param * Array de parmetros: el primero se corresponde con el * movimiento a realizar, 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 una lista con los parmetros List<NameValuePair> params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair(rpiParam, value)); // Se pasa la lista a un string debidamente formateado String paramString = URLEncodedUtils.format(params, "iso-8859-15"); // Se crea la url String url = rpi + ":" + port + rpiPath + "?" + paramString; Log.i(LOGTAG + " Asynctask" + " Http get:", url); // Se crea un objeto httpget HttpGet httpGet = new HttpGet(url); try { // Se ejecuta el cliente pasndole como parmetro la peticin get. HttpResponse response = httpClient.execute(httpGet); Log.i(LOGTAG + " Asynctask" + " Http Response:", response.toString()); } catch (ClientProtocolException e) { Log.i(LOGTAG + " Asynctask" + " Http Response:", "Error en el protocolo http"); e.printStackTrace(); return false; } catch (IOException e) { Log.i(LOGTAG + " Asynctask" + " Http Response:", "Conexin abortada. No se pudo contactar con el servidor"); e.printStackTrace(); return false; } return true; }
From source file:com.example.apis.ifashion.WOEIDUtils.java
private String fetchWOEIDxmlString(Context context, String queryString) { YahooWeatherLog.d("fetch WOEID xml string"); String qResult = ""; HttpClient httpClient = NetworkUtils.createHttpClient(); HttpGet httpGet = new HttpGet(queryString); try {/*from w w w .j ava 2s . co m*/ HttpEntity httpEntity = httpClient.execute(httpGet).getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); Reader in = new InputStreamReader(inputStream); BufferedReader bufferedreader = new BufferedReader(in); StringBuilder stringBuilder = new StringBuilder(); String readLine = null; while ((readLine = bufferedreader.readLine()) != null) { YahooWeatherLog.d(readLine); stringBuilder.append(readLine + "\n"); } qResult = stringBuilder.toString(); } } catch (ClientProtocolException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (ConnectTimeoutException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (SocketTimeoutException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } finally { httpClient.getConnectionManager().shutdown(); } return qResult; }
From source file:com.liato.bankdroid.banking.banks.FirstCard.java
@Override public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException { super.updateTransactions(account, urlopen); Matcher matcher;//from ww w. j a v a 2 s .c o m try { response = urlopen.open("https://www.firstcard.se/mkol/translist.jsp?p=a&cardID=" + account.getId()); matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); while (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: date 101006 * 2: specification GOOGLE *RealArcade * 3: currency USD * 4: amount 3,49 * 5: amount in local currency 24,08 * */ String strDate = Html.fromHtml(matcher.group(1)).toString().trim(); strDate = "20" + strDate.charAt(0) + strDate.charAt(1) + "-" + strDate.charAt(2) + strDate.charAt(3) + "-" + strDate.charAt(4) + strDate.charAt(5); transactions.add(new Transaction(strDate, Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(5)).negate())); } account.setTransactions(transactions); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:service.S4ServiceClient.java
/** * Sends a test request to the service/*from www .ja v a 2s. c om*/ * @return true if the service is available */ public boolean testEndpoint() { HttpGet get = new HttpGet(getEndpointUrl().substring(0, getEndpointUrl().lastIndexOf("/"))); CloseableHttpResponse response = null; try { response = httpClient.execute(get, ctx); StatusLine sl = response.getStatusLine(); int statusCode = sl.getStatusCode(); if (statusCode != 200) { System.out.println("Error communicating with endpoint."); System.out.println(response.toString()); System.out.println(getContent(response)); return false; } else { System.out.println("Endpoint returned status SUCCESS."); System.out.println(response.toString()); System.out.println("Response body: "); System.out.println(getContent(response)); return true; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { } } return false; }
From source file:com.liato.bankdroid.banking.banks.Swedbank.java
@Override public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException { super.updateTransactions(account, urlopen); if (account.getType() == Account.LOANS || account.getType() == Account.OTHER) return; //No transaction history for loans String response = null;//from www . java 2 s.c o m Matcher matcher; try { Log.d(TAG, "Opening: https://mobilbank.swedbank.se/banking/swedbank/account.html?id=" + account.getId()); response = urlopen .open("https://mobilbank.swedbank.se/banking/swedbank/account.html?id=" + account.getId()); matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); while (matcher.find()) { transactions.add(new Transaction("20" + matcher.group(1).trim(), Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3)))); } account.setTransactions(transactions); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java
/** * Returns the history for the user/*from ww w .j a va 2 s. c om*/ * * @param sid * @param role * see {@link Constants} * @return List of {@link HistoryRideObject} */ public static List<HistoryRideObject> getHistory(String sid, String role) { Log.d(TAG, "SID:" + sid); Log.d(TAG, "Role:" + role); listToParse.clear(); listToParse.add(new ParamObject("sid", sid, false)); listToParse.add(new ParamObject("role", role, true)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "ride_history.php"); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } List<HistoryRideObject> historyObjects = null; List<HistoryPersonObject> historyPersons = null; boolean suc = false; JsonArray array_rides; if (object != null) { suc = object.get("successful").getAsBoolean(); if (suc) { array_rides = object.get("rides").getAsJsonArray(); Log.d(TAG, "Array rides: " + array_rides.toString()); Log.d(TAG, "Array rides: " + array_rides.size()); historyObjects = new ArrayList<HistoryRideObject>(); for (int i = 0; i < array_rides.size(); i++) { historyPersons = new ArrayList<HistoryPersonObject>(); JsonObject IObject = array_rides.get(i).getAsJsonObject(); int tripid = IObject.get("trip").getAsInt(); int avail_seats = IObject.get("avail_seats").getAsInt(); String destination = IObject.get("destination").getAsString(); String creation = IObject.get("creation").getAsString(); String ending = IObject.get("ending").getAsString(); if (role.equals(Constants.ROLE_DRIVER)) { JsonArray array_passengers = IObject.get("passengers").getAsJsonArray(); for (int j = 0; j < array_passengers.size(); j++) { JsonObject passObjects = array_passengers.get(j).getAsJsonObject(); int userid = passObjects.get("userid").getAsInt(); String username = passObjects.get("username").getAsString(); float rating = passObjects.get("rating").getAsFloat(); int rating_num = passObjects.get("rating_num").getAsInt(); boolean rated = passObjects.get("rated").getAsBoolean(); HistoryPersonObject person = new HistoryPersonObject(userid, username, rating, rating_num, rated); historyPersons.add(person); } } else { JsonArray array_drivers = IObject.get("passengers").getAsJsonArray(); for (int j = 0; j < array_drivers.size(); j++) { JsonObject passObjects = array_drivers.get(j).getAsJsonObject(); int userid = passObjects.get("userid").getAsInt(); String username = passObjects.get("username").getAsString(); float rating = passObjects.get("rating").getAsFloat(); int rating_num = passObjects.get("rating_num").getAsInt(); boolean rated = passObjects.get("rated").getAsBoolean(); HistoryPersonObject person = new HistoryPersonObject(userid, username, rating, rating_num, rated); historyPersons.add(person); } JsonObject driver = IObject.get("driver").getAsJsonObject(); int userid = driver.get("userid").getAsInt(); String username = driver.get("username").getAsString(); float rating = driver.get("rating").getAsFloat(); int rating_num = driver.get("rating_num").getAsInt(); boolean rated = driver.get("rated").getAsBoolean(); HistoryPersonObject person = new HistoryPersonObject(userid, username, rating, rating_num, rated); historyPersons.add(person); } Log.d(null, "IN READER HISTORYPERSONS" + historyPersons.size()); HistoryRideObject ride = new HistoryRideObject(tripid, avail_seats, creation, ending, destination, historyPersons); historyObjects.add(ride); } } Model.getInstance().setHistoryObjHolder(historyObjects); } return historyObjects; }
From source file:it.sasabz.android.sasabus.classes.hafas.XMLAsyncRequest.java
@Override protected String doInBackground(Void... params) { String ret = ""; if (!haveNetworkConnection()) { return ret; }// w ww .j a v a 2 s . c om try { HttpClient http = new DefaultHttpClient(); HttpPost post = new HttpPost(SASAbus.getContext().getString(R.string.xml_server)); StringEntity se = new StringEntity(request, HTTP.UTF_8); se.setContentType("text/xml"); post.setEntity(se); HttpResponse response = http.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { ret = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; }
From source file:org.wso2.ml.client.MLClient.java
public CloseableHttpResponse createAnalysis(JSONObject analysesConf, long projectId) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(mlHost + "/api/analyses"); httpPost.setHeader(MLConstants.AUTHORIZATION_HEADER, getBasicAuthKey()); httpPost.setHeader(MLConstants.CONTENT_TYPE, MLConstants.CONTENT_TYPE_APPLICATION_JSON); String analysisName = analysesConf.get("name").toString(); try {//from www . ja va 2s . c om String payload; if (analysisName == null) { payload = "{\"comments\":\"Test Analysis\",\"projectId\":" + projectId + "}"; } else if (projectId == -1) { payload = "{\"name\":\"" + analysisName + "\",\"comments\":\"Test Analysis\"}"; } else { payload = "{\"name\":\"" + analysisName + "\",\"comments\":\"Test Analysis\",\"projectId\":" + projectId + "}"; } StringEntity params = new StringEntity(payload); httpPost.setEntity(params); return httpClient.execute(httpPost); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }