List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:net.dahanne.gallery3.client.business.G3Client.java
public int createItem(Entity entity, File file) throws G3GalleryException { String resultUrl;/*from w w w . ja va2s . co m*/ NameValuePair nameValuePair; try { if (file == null) { nameValuePair = new BasicNameValuePair("entity", ItemUtils.convertAlbumEntityToJSON(entity)); } else { nameValuePair = new BasicNameValuePair("entity", ItemUtils.convertPhotoEntityToJSON(entity)); } List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(nameValuePair); resultUrl = sendHttpRequest(INDEX_PHP_REST_ITEM + entity.getParent(), nameValuePairs, POST, file); resultUrl = ItemUtils.convertJsonStringToUrl(resultUrl); } catch (JSONException e) { throw new G3GalleryException(e.getMessage()); } return ItemUtils.getItemIdFromUrl(resultUrl); }
From source file:net.dahanne.gallery3.client.business.G3Client.java
public void updateItem(Entity entity) throws G3GalleryException { NameValuePair nameValuePair;//from w w w.jav a2 s . c om try { nameValuePair = new BasicNameValuePair("entity", ItemUtils.convertAlbumEntityToJSON(entity)); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(nameValuePair); sendHttpRequest(INDEX_PHP_REST_ITEM + entity.getId(), nameValuePairs, PUT, null); } catch (JSONException e) { throw new G3GalleryException(e.getMessage()); } }
From source file:net.dahanne.gallery3.client.business.G3Client.java
private List<Item> getTree(int albumId, String type) throws G3GalleryException { logger.debug("getting tree for albumId : {}, type : {}", albumId, type); List<Item> items = new ArrayList<Item>(); String stringResult = sendHttpRequest(INDEX_PHP_REST_TREE + albumId + "?depth=1", new ArrayList<NameValuePair>(), GET, null); try {/*from ww w .j a v a 2 s.c om*/ JSONObject jsonResult = (JSONObject) new JSONTokener(stringResult).nextValue(); items = ItemUtils.parseJSONToMultipleItems(jsonResult); } catch (JSONException e) { throw new G3GalleryException(e.getMessage()); } catch (ClassCastException e) { throw new G3GalleryException( "The Gallery returned an unexpected result when trying to load albums/photos; please check for info on the ReGalAndroid project page" + e.getMessage()); } return items; }
From source file:com.chess.genesis.dialog.GamePoolDialog.java
public GamePoolDialog(final Context _context) { super(_context, BaseDialog.CANCEL); context = _context;/*from ww w . j av a 2s .co m*/ try { // Load pool info json array final JSONArray pool = new JSONArray(Pref.getString(context, R.array.pf_poolinfo)); data = new ArrayList<PoolDataItem>(pool.length()); for (int i = 0, len = pool.length(); i < len; i++) { final String type = pool.getJSONObject(i).getString("gametype"); final long time = pool.getJSONObject(i).getLong("added"); data.add(new PoolDataItem(type, time)); } } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.NetworkClient.java
private void newRequest(final String type, final int callbackId, final boolean requiresLogin) { fid = callbackId;// w w w . j av a 2s . c om loginRequired = requiresLogin; request = new JSONObject(); try { request.put(_REQUEST, type); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.NetworkClient.java
private <Type> void addValue(final String key, final Type value) { try {//from w w w. j a v a2 s . c om request.put(key, value); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.NetworkClient.java
private void login_setup() { final JSONObject json = new JSONObject(); try {// w w w. ja v a 2 s . c o m try { request.put(_PASSHASH, Crypto.LoginKey(socket, request.getString(_PASSHASH))); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } } catch (final SocketException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, CANT_CONTACT_MSG); socket.logError(context, e, request); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } catch (final IOException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, LOST_CONNECTION_MSG); socket.logError(context, e, request); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } if (error) callback.sendMessage(Message.obtain(callback, fid, json)); }
From source file:com.chess.genesis.net.NetworkClient.java
private JSONObject send_request(final JSONObject data) { JSONObject json = new JSONObject(); try {/*from ww w . j ava 2s . c o m*/ socket.write(data); } catch (final SocketException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, CANT_CONTACT_MSG); socket.logError(context, e, data); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } catch (final IOException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, LOST_CONNECTION_MSG); socket.logError(context, e, data); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } if (error) return json; try { json = socket.read(); } catch (final SocketException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, CANT_CONTACT_MSG); socket.logError(context, e, data); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } catch (final IOException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, LOST_CONNECTION_MSG); socket.logError(context, e, data); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } catch (final JSONException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, SERVER_ILLOGICAL_MSG); socket.logError(context, e, data); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } return json; }
From source file:com.chess.genesis.net.NetworkClient.java
private boolean relogin() { if (socket.getIsLoggedIn()) return true; final Pref pref = new Pref(context); final String username = pref.getString(R.array.pf_username); final String password = pref.getString(R.array.pf_passhash); JSONObject json = new JSONObject(); try {/* w w w. j a v a 2 s . co m*/ try { json.put(_REQUEST, _LOGIN); json.put(_USERNAME, username); json.put(_PASSHASH, Crypto.LoginKey(socket, password)); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } } catch (final SocketException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, CANT_CONTACT_MSG); socket.logError(context, e, json); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } catch (final IOException e) { try { json.put(_RESULT, _ERROR); json.put(_REASON, LOST_CONNECTION_MSG); socket.logError(context, e, request); } catch (final JSONException j) { throw new RuntimeException(j.getMessage(), j); } error = true; } if (error) { callback.sendMessage(Message.obtain(callback, fid, json)); return false; } // Send login request json = send_request(json); try { if (!json.getString(_RESULT).equals(_OK)) { callback.sendMessage(Message.obtain(callback, fid, json)); return false; } socket.setIsLoggedIn(true); return true; } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.owasp.goatdroid.fourgoats.rest.searchforfriends.SearchForFriendsResponse.java
static public ArrayList<HashMap<String, String>> parseSearchForFriendsResponse(String response) { JSONObject json;// w ww . j a v a 2s .c o m ArrayList<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>(); String errors = ""; try { json = new JSONObject(response); if (json.getString("success").equals("true")) { JSONArray friendArray = json.getJSONArray("users"); for (int count = 0; count < friendArray.length(); count++) { HashMap<String, String> resultsMap = new HashMap<String, String>(); resultsMap.put("success", "true"); HashMap<String, String> friend = new HashMap<String, String>(); if (friendArray.getJSONObject(count).has("userID")) friend.put("userID", (String) friendArray.getJSONObject(count).get("userID")); if (friendArray.getJSONObject(count).has("userName")) friend.put("userName", (String) friendArray.getJSONObject(count).get("userName")); if (friendArray.getJSONObject(count).has("firstName")) friend.put("firstName", (String) friendArray.getJSONObject(count).get("firstName")); if (friendArray.getJSONObject(count).has("lastName")) friend.put("lastName", (String) friendArray.getJSONObject(count).get("lastName")); results.add(resultsMap); if (friend.size() > 0) results.add(friend); } } else { HashMap<String, String> resultsMap = new HashMap<String, String>(); resultsMap.put("success", "false"); try { JSONArray errorArray = json.getJSONArray("errors"); for (int count = 0; count < errorArray.length(); count++) errors += errorArray.getString(count).toString() + "\n\n"; } catch (JSONException e) { errors += json.getString("errors"); } resultsMap.put("errors", errors); results.add(resultsMap); } } catch (JSONException e) { try { json = new JSONObject(response); HashMap<String, String> resultsMap = new HashMap<String, String>(); resultsMap.put("success", "true"); results.add(resultsMap); HashMap<String, String> friend = new HashMap<String, String>(); if (json.getJSONObject("users").has("userID")) friend.put("userID", (String) json.getJSONObject("users").get("userID")); if (json.getJSONObject("users").has("userName")) friend.put("userName", (String) json.getJSONObject("users").get("userName")); if (json.getJSONObject("users").has("firstName")) friend.put("firstName", (String) json.getJSONObject("users").get("firstName")); if (json.getJSONObject("users").has("lastName")) friend.put("lastName", (String) json.getJSONObject("users").get("lastName")); if (friend.size() > 0) results.add(friend); } catch (JSONException e1) { /* * We don't care if it falls through here. */ e1.getMessage(); } } return results; }