List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:com.moklet.smarttrafficsystem.login.LoginActivity.java
public void postLoginData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); /* login.php returns true if username and password is equal to saranga */ HttpPost httppost = new HttpPost("http://api.edoferiyus.com/api/login"); try {//from ww w. ja v a2s.c o m // Add user name and password List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("username", etPengguna.getText().toString())); nameValuePairs.add(new BasicNameValuePair("birthdate", etBirthdate.getText().toString())); nameValuePairs.add(new BasicNameValuePair("licensenumber", etLicenseNumber.getText().toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request Log.w("SENCIDE", "Execute HTTP Post Request"); HttpResponse response = httpclient.execute(httppost); responeLogin = inputStreamToString(response.getEntity().getContent()).toString(); Log.w("SENCIDE", responeLogin); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.example.dex.MainActivity.java
/** * dex//from w w w .j a va 2 s .c o m * @return */ private InputStream downloadFile() { try { HttpClient client = new DefaultHttpClient(); HttpHost targetHost = new HttpHost("goodev.sinaapp.com", 80, "http"); HttpGet httpGet = new HttpGet(SECONDARY_DEX_URL); HttpResponse response = client.execute(targetHost, httpGet); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { InputStream is = response.getEntity().getContent(); return is; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.sgcv.rest.jsf.web.cliente.bbean.CompraBBean.java
public List<Compra> getDocuments() throws Exception { if (documents != null) { return documents; }/*from w w w. j a v a 2 s.c o m*/ /*//Envia el path de peticion get de producto, listado de producto ClientResponse response = restClient.clientGetResponse("producto"); //verifica que no haya error con la pagina.. si es 200 caso de exito, sino fallo if (response.getStatus() != 200) { throw new RuntimeException("Failed service call: HTTP error code : " + response.getStatus()); }*/ try { ClientRequest request = new ClientRequest( "http://localhost:8080/Rest-JSF-Web-PrimeFaces/webresources/compra"); request.accept("application/json"); org.jboss.resteasy.client.ClientResponse<String> response = request.get(String.class); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } // get producto as JSON, el json se guarda como string jsonHistory = response.getEntity(String.class); // convert to Java array / list of Cliente instances, Convierte el json a una Lista de Productos //fromJson pasa de la notacion json a java, Si fuera en caso contrario se usaria toJson Compra[] docs = GsonConverter.getGson().fromJson(jsonHistory, Compra[].class); documents = Arrays.asList(docs); return documents; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.dhbw.organizer.calendar.backend.manager.NetworkManager.java
/** * this function tests to download the file from the given URL and returns * the HTTP status code/*ww w.j a v a2 s. c o m*/ * * @param url * @return http status code, or 0 by any error */ public int testHttpUrl(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, "url = " + url + " HTTP: " + httpStatus); return httpStatus; } catch (ClientProtocolException e) { e.printStackTrace(); Log.e(TAG, "ERROR: " + e.getMessage()); return 0; } catch (IOException e) { Log.e(TAG, "ERROR: " + e.getMessage()); e.printStackTrace(); return 0; } catch (IllegalStateException e) { Log.e(TAG, "ERROR: " + e.getMessage()); e.printStackTrace(); return 0; } } else return 0; }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.AccountImpl.java
/** * this method deletes an account in salesforce.com and returns a success message with deleted account id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /* www . j av a2 s. c o m*/ */ private Map<String, String> delete() { Map<String, String> outMap = new HashMap<String, String>(); final String SALESFORCE_DELETE_ACCOUNT_URL = args.get(INSTANCE_URL) + SALESFORCE_ACCOUNT_URL + 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(SALESFORCE_DELETE_ACCOUNT_URL, null, header); try { TransportMachinery.delete(tst); outMap.put(OUTPUT, DELETE_STRING + args.get(ID)); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.AccountImpl.java
/** * this method lists all account in salesforce.com and returns a list of all account details. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /* w w w.j a va 2 s. co m*/ */ private Map<String, String> list() { Map<String, String> outMap = new HashMap<String, String>(); final String SALESFORCE_LIST_ACCOUNT_URL = args.get(INSTANCE_URL) + "/services/data/v28.0/query/?q=SELECT+Name,Id+FROM+Account"; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(SALESFORCE_LIST_ACCOUNT_URL, null, header); try { String responseBody = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, responseBody); } 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.crm.handler.LeadsImpl.java
/** * this method deletes a lead in salesforce.com and returns a success message with deleted lead id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap //from www . ja v a 2 s . c o m */ private Map<String, String> delete() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_DELETE_LEAD_URL = args.get(INSTANCE_URL) + SALESFORCE_LEAD_URL + 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(SALESFORCE_DELETE_LEAD_URL, null, header); try { TransportMachinery.delete(tst); outMap.put(OUTPUT, DELETE_STRING + args.get(ID)); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.PartnerImpl.java
/** * this method deletes an account in salesforce.com and returns a success message with deleted account id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /*from ww w . jav a2 s . c o m*/ */ private Map<String, String> delete() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_DELETE_PARTNER_URL = args.get(INSTANCE_URL) + SALESFORCE_PARTNER_URL + 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(SALESFORCE_DELETE_PARTNER_URL, null, header); try { TransportMachinery.delete(tst); outMap.put(OUTPUT, DELETE_STRING + args.get(ID)); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java
/** * Hitchhiker wants to show all offers which were made to him * /* w ww .java2 s . c o m*/ * @param sid */ public static List<OfferObject> viewOffer(String sid) { listToParse.clear(); listToParse.add(new ParamObject("sid", sid, false)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "offer_view.php"); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } boolean suc = false; List<OfferObject> offerObjects = null; if (object != null) { suc = object.get("successful").getAsBoolean(); if (suc) { JsonArray array; try { array = object.get("offers").getAsJsonArray(); offerObjects = new ArrayList<OfferObject>(); for (int i = 0; i < array.size(); i++) { JsonObject Iobject = array.get(i).getAsJsonObject(); int offer_id = Iobject.get("offer").getAsInt(); int user_id = Iobject.get("userid").getAsInt(); String username = Iobject.get("username").getAsString(); float rating = Iobject.get("rating").getAsFloat(); float rating_num = Iobject.get("rating_num").getAsFloat(); float lat = Iobject.get("lat").getAsFloat(); float lon = Iobject.get("lon").getAsFloat(); OfferObject oObject = new OfferObject(offer_id, user_id, username, rating, rating_num, lat, lon); offerObjects.add(oObject); } Model.getInstance().setOfferHolder(offerObjects); } catch (Exception ex) { offerObjects = new ArrayList<OfferObject>(); } return offerObjects; } } Model.getInstance().setOfferHolder(offerObjects); return offerObjects; }
From source file:org.megam.deccanplato.provider.salesforce.crm.handler.AccountImpl.java
/** * this method creates an account in salesforce.com and returns that account id. * This method gets input from a MAP(contains json data) and returns a MAp. * @param outMap /*w w w . ja va 2s . co m*/ */ private Map<String, String> create() { Map<String, String> outMap = new HashMap<String, String>(); final String SALESFORCE_CREATE_ACCOUNT_URL = args.get(INSTANCE_URL) + SALESFORCE_ACCOUNT_URL; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); Map<String, Object> accountAttrMap = new HashMap<String, Object>(); accountAttrMap.put(S_NAME, args.get(NAME)); TransportTools tst = new TransportTools(SALESFORCE_CREATE_ACCOUNT_URL, null, header); Gson obj = new GsonBuilder().setPrettyPrinting().create(); tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(accountAttrMap)); try { String responseBody = TransportMachinery.post(tst).entityToString(); outMap.put(OUTPUT, responseBody); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }