List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:at.alladin.rmbt.db.QoSTestObjective.java
@SuppressWarnings("unchecked") public String toHtml() { StringBuilder sb = new StringBuilder(); sb.append("<h3>QoS-Test (uid: " + getUid() + ", test_class: " + getTestClass() + ")</h3>"); if (getObjective() != null) { try {/*from w w w .j a va 2s . co m*/ JSONObject objectives = new JSONObject(getObjective()); Iterator<String> keys = objectives.keys(); sb.append("<b>Test objectives (as plain text):</b> <ul>"); while (keys.hasNext()) { String key = keys.next(); sb.append("<li><i>" + key + "</i>: " + objectives.optString(key) + "</li>"); } sb.append("</ul>"); sb.append("<b>Test objectives (as hstore representation):</b> " + Helperfunctions.json2hstore(objectives, null) + "<br><br>"); if (testSummary != null) { sb.append("<b>Test summary (test_summary):</b> <a href=\"#" + testSummary.replaceAll("[\\-\\+\\.\\^:,]", "_") + "\">" + testSummary + "</a><br><br>"); } else { sb.append("<b>Test summary (test_summary):</b> <i>NULL</i><br><br>"); } if (testDescription != null) { sb.append("<b>Test description (test_desc):</b> <a href=\"#" + testDescription.replaceAll("[\\-\\+\\.\\^:,]", "_") + "\">" + testDescription + "</a><br><br>"); } else { sb.append("<b>Test description (test_desc):</b> <i>NULL</i><br><br>"); } } catch (JSONException e) { sb.append( "<b><i>incorrect test objectives format:</i></b><ul><li>" + getObjective() + "</li></ul>"); e.printStackTrace(); } } else { sb.append("<b><i>no objectives set for this test</i></b>"); } sb.append("<b>Expected test results (as hstore representation):</b><ul>"); if (getResults() != null) { JSONArray resultsJson; try { resultsJson = new JSONArray(getResults()); for (int i = 0; i < resultsJson.length(); i++) { try { final JSONObject expected = resultsJson.getJSONObject(i); sb.append("<li>" + Helperfunctions.json2htmlWithLinks(expected) + "</li>"); } catch (Exception e) { e.printStackTrace(); sb.append("<li>incorrect expected test result format</li>"); } } } catch (JSONException e1) { sb.append("<li>incorrect expected test result format</li>"); } } else { sb.append("<li><i>No expected results set for this test</i></li>"); } sb.append("</ul>"); return sb.toString(); }
From source file:at.zone.madeleine.ir.PixlinqSearch.java
private String parsePixlinqResponse(String response) { JSONObject responseObject;/*from w w w . j a va 2 s . c om*/ String result = null; if (response != null) { try { responseObject = (JSONObject) new JSONTokener(response).nextValue(); JSONArray matches = responseObject.getJSONArray("matches"); JSONArray errors = responseObject.getJSONArray("errors"); if (matches.length() > 0) { JSONObject match = matches.getJSONObject(0); String title = match.getString("title"); String message = match.getString("message"); String sanatizedMessage = message.split("\\.")[0]; result = sanatizedMessage; } } catch (JSONException e) { e.printStackTrace(); } } else { result = null; } return result; }
From source file:app.nichepro.fragmenttab.account.AbstractGetNameTask.java
@Override protected void onPostExecute(String result) { super.onPostExecute(result); if (null != dialog && dialog.isShowing()) { dialog.cancel();/*from w w w . j a v a 2 s . c om*/ } try { if (result != null) { mActivity.googleLoginSuccess(result); } else { mActivity.googleLoginUnSuccess(error); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.tugraz.ist.catroid.web.ServerCalls.java
public String uploadProject(String projectName, String projectDescription, String zipFileString, String userEmail, String language, String token) throws WebconnectionException { if (emailForUiTests != null) { userEmail = emailForUiTests;// w w w . j a v a 2 s . c o m } try { String md5Checksum = Utils.md5Checksum(new File(zipFileString)); HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put(PROJECT_NAME_TAG, projectName); postValues.put(PROJECT_DESCRIPTION_TAG, projectDescription); postValues.put(USER_EMAIL, userEmail); postValues.put(PROJECT_CHECKSUM_TAG, md5Checksum.toLowerCase()); postValues.put(Constants.TOKEN, token); if (language != null) { postValues.put(USER_LANGUAGE, language); } String serverUrl = useTestUrl ? TEST_FILE_UPLOAD_URL : FILE_UPLOAD_URL; Log.v(TAG, "url to upload: " + serverUrl); resultString = connection.doHttpPostFileUpload(serverUrl, postValues, FILE_UPLOAD_TAG, zipFileString); JSONObject jsonObject = null; int statusCode = 0; Log.v(TAG, "result string: " + resultString); jsonObject = new JSONObject(resultString); statusCode = jsonObject.getInt("statusCode"); String serverAnswer = jsonObject.getString("answer"); if (statusCode == 200) { return serverAnswer; } else { throw new WebconnectionException(statusCode, serverAnswer); } } catch (JSONException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_JSON); } catch (IOException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_NETWORK); } }
From source file:at.tugraz.ist.catroid.web.ServerCalls.java
public boolean checkToken(String token) throws WebconnectionException { try {//from www.ja v a2 s . co m HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put(Constants.TOKEN, token); String serverUrl = useTestUrl ? TEST_CHECK_TOKEN_URL : CHECK_TOKEN_URL; Log.v(TAG, "url to upload: " + serverUrl); resultString = connection.doHttpPost(serverUrl, postValues); JSONObject jsonObject = null; int statusCode = 0; Log.v(TAG, "result string: " + resultString); jsonObject = new JSONObject(resultString); statusCode = jsonObject.getInt("statusCode"); String serverAnswer = jsonObject.optString("answer"); if (statusCode == SERVER_RESPONSE_TOKEN_OK) { return true; } else { throw new WebconnectionException(statusCode, serverAnswer); } } catch (JSONException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_JSON); } catch (IOException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_NETWORK); } }
From source file:at.tugraz.ist.catroid.web.ServerCalls.java
public boolean registerOrCheckToken(String username, String password, String userEmail, String language, String country, String token) throws WebconnectionException { if (emailForUiTests != null) { userEmail = emailForUiTests;/*from w w w .j av a 2s. c o m*/ } try { HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put(REG_USER_NAME, username); postValues.put(REG_USER_PASSWORD, password); postValues.put(REG_USER_EMAIL, userEmail); postValues.put(Constants.TOKEN, token); if (country != null) { postValues.put(REG_USER_COUNTRY, country); } if (language != null) { postValues.put(REG_USER_LANGUAGE, language); } String serverUrl = useTestUrl ? TEST_REGISTRATION_URL : REGISTRATION_URL; Log.v(TAG, "url to use: " + serverUrl); resultString = connection.doHttpPost(serverUrl, postValues); JSONObject jsonObject = null; int statusCode = 0; Log.v(TAG, "result string: " + resultString); jsonObject = new JSONObject(resultString); statusCode = jsonObject.getInt("statusCode"); String serverAnswer = jsonObject.optString("answer"); boolean registered; if (statusCode == SERVER_RESPONSE_TOKEN_OK) { registered = false; } else if (statusCode == SERVER_RESPONSE_REGISTER_OK) { registered = true; } else { throw new WebconnectionException(statusCode, serverAnswer); } return registered; } catch (JSONException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_JSON); } catch (IOException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_NETWORK); } }
From source file:at.alladin.rmbt.util.tools.InformationCollectorTool.java
/** * /*from ww w .ja v a 2 s . c o m*/ * @param clean * @param relativeTimeStamp * @return */ public JSONObject getJsonObject(final boolean clean, long relativeTimeStamp) { try { JSONObject json = new JSONObject(); for (CollectorHolder c : collectorList) { synchronized (c.collector) { json.put(c.collector.getJsonKey(), c.collector.getJsonResult(clean, relativeTimeStamp, deltaTimeUnit)); } } return json; } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:com.google.cast.samples.tictactoe.GameChannel.java
/** * Processes all Text messages received from the receiver device and performs the appropriate * action for the message. Recognizable messages are of the form: * * <ul>/*from w w w . j a va 2 s . com*/ * <li> KEY_JOINED: a player joined the current game * <li> KEY_MOVED: a player made a move * <li> KEY_ENDGAME: the game has ended in one of the END_STATE_* states * <li> KEY_ERROR: a game error has occurred * <li> KEY_BOARD_LAYOUT_RESPONSE: the board has been laid out in some new configuration * </ul> * * <p>No other messages are recognized. */ @Override public void onMessageReceived(CastDevice castDevice, String namespace, String message) { try { Log.d(TAG, "onTextMessageReceived: " + message); JSONObject payload = new JSONObject(message); Log.d(TAG, "payload: " + payload); if (payload.has(KEY_EVENT)) { String event = payload.getString(KEY_EVENT); if (KEY_JOINED.equals(event)) { Log.d(TAG, "JOINED"); try { String player = payload.getString(KEY_PLAYER); String opponentName = payload.getString(KEY_OPPONENT); onGameJoined(player, opponentName); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_MOVED.equals(event)) { Log.d(TAG, "MOVED"); try { String player = payload.getString(KEY_PLAYER); int row = payload.getInt(KEY_ROW); int column = payload.getInt(KEY_COLUMN); boolean isGameOver = payload.getBoolean(KEY_GAME_OVER); onGameMove(player, row, column, isGameOver); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ENDGAME.equals(event)) { Log.d(TAG, "ENDGAME"); try { String endState = payload.getString(KEY_END_STATE); int winningLocation = -1; if (END_STATE_ABANDONED.equals(endState) == false) { winningLocation = payload.getInt(KEY_WINNING_LOCATION); } onGameEnd(endState, winningLocation); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ERROR.equals(event)) { Log.d(TAG, "ERROR"); try { String errorMessage = payload.getString(KEY_MESSAGE); onGameError(errorMessage); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_BOARD_LAYOUT_RESPONSE.equals(event)) { Log.d(TAG, "Board Layout"); int[][] boardLayout = new int[3][3]; try { JSONArray boardJSONArray = payload.getJSONArray(KEY_BOARD); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { boardLayout[i][j] = boardJSONArray.getInt(i * 3 + j); } } onGameBoardLayout(boardLayout); } catch (JSONException e) { e.printStackTrace(); } } } else { Log.w(TAG, "Unknown payload: " + payload); } } catch (JSONException e) { Log.w(TAG, "Message doesn't contain an expected key.", e); } }
From source file:com.example.cuisoap.agrimac.machineRegister.containerActivity.java
@Override public void onButtonClicked(JSONObject data, int from) { System.out.println(data.toString()); switch (from) { case 1:/*from ww w . j a v a 2 s .c o m*/ try { send_data.put("drive_type", data.getString("drive_type")); send_data.put("driver_name", data.getString("driver_name")); send_data.put("driver_age", data.getString("driver_age")); send_data.put("driver_gender", data.getString("driver_gender")); send_data.put("driver_license_type", data.getString("license_type")); //send_data.put("driver_license",data.getString("license_path")); filelist.put("driver_license", data.getString("license_path")); } catch (JSONException e) { e.printStackTrace(); } mPager.setCurrentItem(1); break; case 2: try { send_data.put("machine_type", data.getString("machine_type")); send_data.put("machine_name", data.getString("machine_name")); send_data.put("machine_power", data.getString("machine_power")); send_data.put("passenger_num", data.getString("passenger_num")); send_data.put("machine_wheeldistance", data.getString("wheel_distance")); send_data.put("machine_checktime", data.getString("check_time")); send_data.put("machine_paytype", data.getString("pay_type")); send_data.put("machine_powertype", data.getString("power")); // send_data.put("machine_license1",data.getString("license_path1")); // send_data.put("machine_license2",data.getString("license_path2")); filelist.put("machine_license1", data.getString("license_path1")); filelist.put("machine_license2", data.getString("license_path2")); } catch (JSONException e) { e.printStackTrace(); } mPager.setCurrentItem(2); break; case 3: try { send_data.put("lease_month", data.getString("lease_month")); send_data.put("lease_time", data.getString("lease_time")); send_data.put("work_condition", data.getString("work_condition")); send_data.put("need_type", data.getString("need_type")); if (data.getString("need_type").equals("2")) send_data.put("need_item", data.getString("needItem")); send_data.put("house_type", data.getString("house_type")); } catch (JSONException e) { e.printStackTrace(); } /* Message e=Message.obtain(); JSONObject o=new JSONObject(); try { o.put("status","0"); o.put("id","1"); e.obj=o.toString(); e.setTarget(h); e.sendToTarget(); } catch (JSONException e1) { e1.printStackTrace(); }*/ new Thread(send).start(); //TODO ? } }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/add", method = RequestMethod.GET) public @ResponseBody String addCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { // String jstr = "{\"cartId\":-1, \"productId\":2, \"attributeId\":1, \"quantity\":2}"; // String jstr = "{\"cartId\":1, \"productId\":3, \"attributeId\":1, \"quantity\":2}"; int cartId = -1; int productId = -1; int attributeId = -1; int quantity = -1; try {/* w w w . jav a2 s . c o m*/ cartId = jsonParams.getInt("cartId"); productId = jsonParams.getInt("productId"); attributeId = jsonParams.getInt("attributeId"); quantity = jsonParams.getInt("quantity"); } catch (JSONException e) { e.printStackTrace(); } // cartId = 1; // productId = 2; // attributeId = 1; // quantity = 2; CheckoutAddToCart checkoutAddToCart = new CheckoutAddToCart(); checkoutAddToCart.setCartId(cartId); checkoutAddToCart.setProductId(productId); checkoutAddToCart.setAttributeId(attributeId); checkoutAddToCart.setQuantity(quantity); //Making entry to CheckoutQuote CheckoutQuote checkoutQuote = new CheckoutQuote(); checkoutQuote.setId(checkoutAddToCart.getCartId()); int insertedCartId = -1; if (checkoutQuote.getId() == -1) { System.out.println("Setting create id"); checkoutQuote.setId(0); checkoutQuote.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuote.setBaseGrandTotal(0); checkoutQuote.setBaseSubtotal(0); checkoutQuote.setGrandTotal(0); checkoutQuote.setSubtotal(0); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); } else { checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); // checkoutQuote.setCreatedAt(this.checkoutQuoteService.getCheckoutQuoteById(checkoutQuote.getId()).getCreatedAt()); } insertedCartId = checkoutQuote.getId(); System.out.println("CheckoutQuote ID: insertedCartId : " + insertedCartId); //Making entry to CheckoutQuoteItem ProductsMaster productItem = getJVoidProduct(checkoutAddToCart.getProductId()); CheckoutQuoteItem checkoutQuoteItem = this.checkoutQuoteItemService.getCheckoutQuoteItem(cartId, productId); int addingNew = 0; if (checkoutQuoteItem == null) { addingNew = 1; checkoutQuoteItem = new CheckoutQuoteItem(); checkoutQuote.setItemsCount(checkoutQuote.getItemsCount() + 1); checkoutQuoteItem.setCreatedAt(Utilities.getCurrentDateTime()); } checkoutQuoteItem.setWeight(productItem.getWeight()); checkoutQuoteItem.setQuantity(checkoutQuoteItem.getQuantity() + checkoutAddToCart.getQuantity()); checkoutQuoteItem.setSku(productItem.getSku()); checkoutQuoteItem.setPrice(productItem.getPrice()); checkoutQuoteItem.setBasePrice(productItem.getPrice()); checkoutQuoteItem.setDescription(productItem.getDescription()); checkoutQuoteItem.setName(productItem.getName()); checkoutQuoteItem.setProductId(productItem.getId()); checkoutQuoteItem.setQuoteId(insertedCartId); // if (checkoutAddToCart.getCartId() == -1) { checkoutQuote.setItemsQuantity(checkoutQuote.getItemsQuantity() + checkoutAddToCart.getQuantity()); // } // else { // checkoutQuoteItem.setCreatedAt(this.checkoutQuoteItemService.getCheckoutQuoteItemById(checkoutQuoteItem.getId()).getCreatedAt()); // } checkoutQuoteItem.setRowTotal(checkoutQuoteItem.getPrice() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setBaseRowTotal(checkoutQuoteItem.getBasePrice() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setRowWeight(checkoutQuoteItem.getWeight() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteItemService.addCheckoutQuoteItem(checkoutQuoteItem); int insertedProductId = checkoutQuoteItem.getId(); System.out.println("CheckoutItem ID: insertedProductId : " + insertedProductId); System.out.println("Abhi checkoutquote b4 = " + checkoutQuote.toString()); if (addingNew == 0) { checkoutQuote.setBaseSubtotal(checkoutQuote.getBaseSubtotal() + checkoutQuoteItem.getBasePrice() * checkoutAddToCart.getQuantity()); checkoutQuote.setSubtotal( checkoutQuote.getSubtotal() + checkoutQuoteItem.getPrice() * checkoutAddToCart.getQuantity()); } else { checkoutQuote.setBaseSubtotal(checkoutQuote.getBaseSubtotal() + checkoutQuoteItem.getBaseRowTotal()); checkoutQuote.setSubtotal(checkoutQuote.getSubtotal() + checkoutQuoteItem.getRowTotal()); } checkoutQuote.setBaseGrandTotal(checkoutQuote.getBaseSubtotal() + 50); checkoutQuote.setGrandTotal(checkoutQuote.getSubtotal() + 50); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); System.out.println("Abhi checkoutquote after = " + checkoutQuote.toString()); // } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", insertedCartId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }