List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:com.deployd.Deployd.java
public static void login(String username, String password, final LoginEventHandler loggedIn) { AsyncTask<JSONObject, JSONObject, JSONObject> query = new AsyncTask<JSONObject, JSONObject, JSONObject>() { @Override// www . ja v a 2 s . co m protected JSONObject doInBackground(JSONObject... arg0) { // TODO Auto-generated method stub try { JSONObject result = Deployd.post(arg0[0], "/users/login"); return result; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(JSONObject result) { // TODO Auto-generated method stub super.onPostExecute(result); if (result == null) { loggedIn.failed(); } DeploydObject jres = new DeploydObject(result); loggedIn.loggedIn(jres); } }; try { JSONObject pass = new JSONObject(); pass.put("username", username); pass.put("password", password); query.execute(pass); } catch (Exception e) { } }
From source file:com.deployd.Deployd.java
public static void signup(String username, String displayName, String password, final SignupEventHandler signedUp) { AsyncTask<JSONObject, JSONObject, JSONObject> query = new AsyncTask<JSONObject, JSONObject, JSONObject>() { @Override/* w ww . j a v a2 s .c om*/ protected JSONObject doInBackground(JSONObject... arg0) { // TODO Auto-generated method stub try { JSONObject result = Deployd.post(arg0[0], "/users/signup"); return result; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(JSONObject result) { // TODO Auto-generated method stub super.onPostExecute(result); if (result == null) { signedUp.failed(); return; } DeploydObject jres = new DeploydObject(result); signedUp.signupComplete(jres); } }; try { JSONObject pass = new JSONObject(); pass.put("username", username); pass.put("password", password); pass.put("displayName", password); query.execute(pass); } catch (Exception e) { } }
From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java
public static Long createCycle(ZephyrConfigModel zephyrData) { Long cycleId = 0L;/* www . j a v a 2s .c om*/ HttpResponse response = null; try { String createCycleURL = URL_CREATE_CYCLES.replace("{SERVER}", zephyrData.getRestClient().getUrl()); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("E dd, yyyy hh:mm a"); String dateFormatForCycleCreation = sdf.format(date); JSONObject jObject = new JSONObject(); String cycleName = zephyrData.getCyclePrefix() + dateFormatForCycleCreation; SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MMM/yy"); String startDate = sdf1.format(date); GregorianCalendar gCal = new GregorianCalendar(); if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("30 days")) { gCal.add(Calendar.DAY_OF_MONTH, +29); } else if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("7 days")) { gCal.add(Calendar.DAY_OF_MONTH, +6); } String endDate = sdf1.format(gCal.getTime()); jObject.put("name", cycleName); jObject.put("projectId", zephyrData.getZephyrProjectId()); jObject.put("versionId", zephyrData.getVersionId()); jObject.put("startDate", startDate); jObject.put("endDate", endDate); StringEntity se = new StringEntity(jObject.toString(), "utf-8"); HttpPost createCycleRequest = new HttpPost(createCycleURL); createCycleRequest.setHeader("Content-Type", "application/json"); createCycleRequest.setEntity(se); response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest, zephyrData.getRestClient().getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { JSONObject cycleObj = new JSONObject(string); cycleId = cycleObj.getLong("id"); } catch (JSONException e) { e.printStackTrace(); } } else if (statusCode == 405) { try { throw new ClientProtocolException("ZAPI plugin license is invalid" + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } return cycleId; }
From source file:org.ubicompforall.cityexplorer.buildingblock.BusTimeStep.java
public static String connect(String url) { String result = ""; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response;//from w w w .j ava 2s . c o m try { response = httpclient.execute(httpget); // Examine the response status debug(2, response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { // A Simple JSON Response Read InputStream instream = entity.getContent(); result = convertStreamToString(instream); // now you have the string representation of the HTML request instream.close(); } } catch (ClientProtocolException e) { debug(-1, e.getCause() + " " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { debug(-1, e.getCause() + " " + e.getMessage()); } return result; }
From source file:de.kollode.redminebrowser.sync.SyncHelper.java
public static JSONObject getJsonFromUrl(String url) { Log.i(sTag, url);/*w ww . ja va2s .c o m*/ HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response; try { response = httpclient.execute(httpget); // Examine the response status Log.i(sTag, response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { return new JSONObject(readInputStream(entity.getContent())); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.tinyhydra.botd.BotdServerOperations.java
public static void GetTopTen(final Activity activity, final Handler handler, boolean override) { final SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0); final List<JavaShop> TopTen = new ArrayList<JavaShop>(); for (int i = 0; i < 10; i++) { TopTen.add(new JavaShop()); }/*from w w w . j ava 2 s . c om*/ if (settings.getLong(Const.LastTopTenQueryTime, 0) > (Calendar.getInstance().getTimeInMillis() - 180000) & !override) { Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); } else new Thread() { @Override public void run() { BufferedReader in = null; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(activity.getResources().getString(R.string.server_url))); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); SharedPreferences.Editor editor = settings.edit(); editor.putString(Const.LastTopTenQueryResults, sb.toString()); editor.putLong(Const.LastTopTenQueryTime, Calendar.getInstance().getTimeInMillis()); editor.commit(); Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); // more generic error handling //TODO: implement better error handling } catch (URISyntaxException usex) { usex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (ClientProtocolException cpex) { cpex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (IOException iex) { iex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }.start(); }
From source file:com.tinyhydra.botd.BotdServerOperations.java
public static void CastVote(final Activity activity, final Handler handler, final String email, final String shopId, final String shopRef) { new Thread() { @Override/* ww w . j av a2s . c o m*/ public void run() { try { URI uri = new URI(activity.getResources().getString(R.string.server_url)); HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(uri); JSONObject voteObj = new JSONObject(); // user's phone-account-email-address is used to prevent multiple votes // the server will validate. 'shopId' is a consistent id for a specific location // but can't be used to get more data. 'shopRef' is an id that changes based on // some criteria that google places has imposed, but will let us grab data later on // and various Ref codes with the same id will always resolve to the same location. voteObj.put(JSONvalues.email.toString(), email); voteObj.put(JSONvalues.shopId.toString(), shopId); voteObj.put(JSONvalues.shopRef.toString(), shopRef); put.setEntity(new StringEntity(voteObj.toString())); HttpResponse response = client.execute(put); InputStream is = response.getEntity().getContent(); int ch; StringBuffer sb = new StringBuffer(); while ((ch = is.read()) != -1) { sb.append((char) ch); } if (sb.toString().equals("0")) { Utils.PostToastMessageToHandler(handler, "Vote cast!", Toast.LENGTH_SHORT); // Set a local flag to prevent duplicate voting SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0); SharedPreferences.Editor editor = settings.edit(); editor.putLong(Const.LastVoteDate, Utils.GetDate()); editor.commit(); } else { // The user shouldn't see this. The above SharedPreferences code will be evaluated // when the user hits the Vote button. If the user gets sneaky and deletes local data though, // the server will catch the duplicate vote based on the user's email address and send back a '1'. Utils.PostToastMessageToHandler(handler, "Vote refused. You've probably already voted today.", Toast.LENGTH_LONG); } GetTopTen(activity, handler, true); // Catch blocks. Return a generic error if anything goes wrong. //TODO: implement some better/more appropriate error handling. } catch (URISyntaxException usex) { usex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "There was a problem submitting your vote. Poor signal? Please try again.", Toast.LENGTH_LONG); } catch (UnsupportedEncodingException ueex) { ueex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "There was a problem submitting your vote. Poor signal? Please try again.", Toast.LENGTH_LONG); } catch (ClientProtocolException cpex) { cpex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "There was a problem submitting your vote. Poor signal? Please try again.", Toast.LENGTH_LONG); } catch (IOException ioex) { ioex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "There was a problem submitting your vote. Poor signal? Please try again.", Toast.LENGTH_LONG); } catch (JSONException jex) { jex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "There was a problem submitting your vote. Poor signal? Please try again.", Toast.LENGTH_LONG); } } }.start(); }
From source file:com.thed.zapi.cloud.sample.CycleExecutionReportByVersion.java
private static JSONArray getExecutionsByCycleId(String uriStr, ZFJCloudRestClient client, String accessKey) throws URISyntaxException, JSONException { JSONArray IssuesArray = null;/*from www . j a va 2 s . c om*/ URI uri = new URI(uriStr); int expirationInSec = 360; JwtGenerator jwtGenerator = client.getJwtGenerator(); String jwt = jwtGenerator.generateJWT("GET", uri, expirationInSec); // System.out.println(uri.toString()); // System.out.println(jwt); HttpResponse response = null; HttpClient restClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Authorization", jwt); httpGet.setHeader("zapiAccessKey", accessKey); try { response = restClient.execute(httpGet); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); // System.out.println(statusCode); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity1 = response.getEntity(); String string1 = null; try { string1 = EntityUtils.toString(entity1); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // System.out.println(string1); JSONObject allIssues = new JSONObject(string1); IssuesArray = allIssues.getJSONArray("searchObjectList"); // System.out.println(IssuesArray.length()); } return IssuesArray; }
From source file:net.homelinux.penecoptero.android.citybikes.app.RESTHelper.java
public static final String restGET(String url, boolean authenticated, String username, String password) throws ClientProtocolException, IOException, HttpException { DefaultHttpClient httpclient = new DefaultHttpClient(); if (authenticated) { httpclient = setCredentials(httpclient, url, username, password); }/*from w w w.jav a2 s .co m*/ // Prepare a request object HttpGet httpmethod = new HttpGet(url); // Execute the request HttpResponse response; String result = null; try { response = httpclient.execute(httpmethod); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); instream.close(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
From source file:com.thed.zapi.cloud.sample.CycleExecutionReportByVersion.java
private static Map<String, String> getCyclesByProjectVersion(String getCyclesUri, ZFJCloudRestClient client, String accessKey) throws URISyntaxException, JSONException { // TODO Auto-generated method stub Map<String, String> cycleMap = new HashMap<String, String>(); URI uri = new URI(getCyclesUri); int expirationInSec = 360; JwtGenerator jwtGenerator = client.getJwtGenerator(); String jwt = jwtGenerator.generateJWT("GET", uri, expirationInSec); // System.out.println(uri.toString()); // System.out.println(jwt); HttpResponse response = null;/*from w w w . j a va 2s . c o m*/ HttpClient restClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Authorization", jwt); httpGet.setHeader("zapiAccessKey", accessKey); try { response = restClient.execute(httpGet); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); // System.out.println(statusCode); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity1 = response.getEntity(); String string1 = null; try { string1 = EntityUtils.toString(entity1); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // System.out.println(string1); JSONArray cyclesArray = new JSONArray(string1); for (int i = 0; i < cyclesArray.length(); i++) { JSONObject cycleObj = cyclesArray.getJSONObject(i); String cycleID = cycleObj.getString("id"); String cycleName = cycleObj.getString("name"); cycleMap.put(cycleID, cycleName); // System.out.println(IssuesArray.length()); } } return cycleMap; }