List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:com.example.hbranciforte.trafficclient.DataTraffic.java
private JSONObject getZoneInfo() { JSONObject zone = new JSONObject(); try {//from w ww . j a v a 2 s . co m zone.put("name", zone_info.get("name")); zone.put("number", zone_info.get("number")); } catch (JSONException e) { Log.e("JSON ERROR", e.getMessage()); } return zone; }
From source file:com.example.hbranciforte.trafficclient.DataTraffic.java
private JSONObject getDeviceinfo() { JSONObject device = new JSONObject(); try {/* w ww. j a va 2s .c o m*/ TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String token = telephonyManager.getDeviceId().toString(); device.put("notification_token", token); device.put("user_agent", System.getProperty("http.agent").toString()); } catch (JSONException e) { Log.e("Json error", e.getMessage()); } return device; }
From source file:com.example.hbranciforte.trafficclient.DataTraffic.java
private JSONObject getCarInfo() { JSONObject car = new JSONObject(); EditText licenseLetters = (EditText) findViewById(R.id.license_letters); EditText licenseNumbers = (EditText) findViewById(R.id.license_numbers); try {//ww w . j a va2 s . c o m car.put("license_plate", licenseLetters.getText().toString().toUpperCase().concat(licenseNumbers.getText().toString())); } catch (JSONException e) { Log.e("JSON error", e.getMessage()); } return car; }
From source file:com.polyvi.xface.extension.advancedfiletransfer.AdvancedFileTransfer.java
/** * FileTransferError// w ww . j a v a 2s .co m * * @param errorCode * ? * @return JSONObject ?JSON */ private JSONObject createFileTransferError(int errorCode, String source, String target) { JSONObject error = null; try { error = new JSONObject(); error.put("code", errorCode); error.put("source", source); error.put("target", target); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage(), e); } return error; }
From source file:com.phonegap.FileTransfer.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { String file = null;/*from ww w . j a va2 s.com*/ String server = null; try { file = args.getString(0); server = args.getString(1); } catch (JSONException e) { Log.d(LOG_TAG, "Missing filename or server name"); return new PluginResult(PluginResult.Status.JSON_EXCEPTION, "Missing filename or server name"); } // Setup the options String fileKey = null; String fileName = null; String mimeType = null; fileKey = getArgument(args, 2, "file"); fileName = getArgument(args, 3, "image.jpg"); mimeType = getArgument(args, 4, "image/jpeg"); try { JSONObject params = args.optJSONObject(5); boolean trustEveryone = args.optBoolean(6); if (action.equals("upload")) { FileUploadResult r = upload(file, server, fileKey, fileName, mimeType, params, trustEveryone); Log.d(LOG_TAG, "****** About to return a result from upload"); return new PluginResult(PluginResult.Status.OK, r.toJSONObject()); } else { return new PluginResult(PluginResult.Status.INVALID_ACTION); } } catch (FileNotFoundException e) { Log.e(LOG_TAG, e.getMessage(), e); JSONObject error = createFileUploadError(FILE_NOT_FOUND_ERR); return new PluginResult(PluginResult.Status.IO_EXCEPTION, error); } catch (IllegalArgumentException e) { Log.e(LOG_TAG, e.getMessage(), e); JSONObject error = createFileUploadError(INVALID_URL_ERR); return new PluginResult(PluginResult.Status.IO_EXCEPTION, error); } catch (SSLException e) { Log.e(LOG_TAG, e.getMessage(), e); Log.d(LOG_TAG, "Got my ssl exception!!!"); JSONObject error = createFileUploadError(CONNECTION_ERR); return new PluginResult(PluginResult.Status.IO_EXCEPTION, error); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); JSONObject error = createFileUploadError(CONNECTION_ERR); return new PluginResult(PluginResult.Status.IO_EXCEPTION, error); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.phonegap.FileTransfer.java
/** * Create an error object based on the passed in errorCode * @param errorCode the error // w ww .j ava2s. co m * @return JSONObject containing the error */ private JSONObject createFileUploadError(int errorCode) { JSONObject error = null; try { error = new JSONObject(); error.put("code", errorCode); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return error; }
From source file:com.phonegap.FileTransfer.java
/** * Uploads the specified file to the server URL provided using an HTTP * multipart request. //from www . j a v a 2s .c o m * @param file Full path of the file on the file system * @param server URL of the server to receive the file * @param fileKey Name of file request parameter * @param fileName File name to be used on server * @param mimeType Describes file content type * @param params key:value pairs of user-defined parameters * @return FileUploadResult containing result of upload request */ public FileUploadResult upload(String file, String server, final String fileKey, final String fileName, final String mimeType, JSONObject params, boolean trustEveryone) throws IOException, SSLException { // Create return object FileUploadResult result = new FileUploadResult(); // Get a input stream of the file on the phone InputStream fileInputStream = getPathFromUri(file); HttpURLConnection conn = null; DataOutputStream dos = null; int bytesRead, bytesAvailable, bufferSize; long totalBytes; byte[] buffer; int maxBufferSize = 8096; //------------------ CLIENT REQUEST // open a URL connection to the server URL url = new URL(server); // Open a HTTP connection to the URL based on protocol if (url.getProtocol().toLowerCase().equals("https")) { // Using standard HTTPS connection. Will not allow self signed certificate if (!trustEveryone) { conn = (HttpsURLConnection) url.openConnection(); } // Use our HTTPS connection that blindly trusts everyone. // This should only be used in debug environments else { // Setup the HTTPS connection class to trust everyone trustAllHosts(); HttpsURLConnection https = (HttpsURLConnection) url.openConnection(); // Save the current hostnameVerifier defaultHostnameVerifier = https.getHostnameVerifier(); // Setup the connection not to verify hostnames https.setHostnameVerifier(DO_NOT_VERIFY); conn = https; } } // Return a standard HTTP conneciton else { conn = (HttpURLConnection) url.openConnection(); } // Allow Inputs conn.setDoInput(true); // Allow Outputs conn.setDoOutput(true); // Don't use a cached copy. conn.setUseCaches(false); // Use a post method. conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDRY); // Set the cookies on the response String cookie = CookieManager.getInstance().getCookie(server); if (cookie != null) { conn.setRequestProperty("Cookie", cookie); } dos = new DataOutputStream(conn.getOutputStream()); // Send any extra parameters try { for (Iterator iter = params.keys(); iter.hasNext();) { Object key = iter.next(); dos.writeBytes(LINE_START + BOUNDRY + LINE_END); dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\"; "); dos.writeBytes(LINE_END + LINE_END); dos.writeBytes(params.getString(key.toString())); dos.writeBytes(LINE_END); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } dos.writeBytes(LINE_START + BOUNDRY + LINE_END); dos.writeBytes("Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"" + fileName + "\"" + LINE_END); dos.writeBytes("Content-Type: " + mimeType + LINE_END); dos.writeBytes(LINE_END); // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); totalBytes = 0; while (bytesRead > 0) { totalBytes += bytesRead; result.setBytesSent(totalBytes); dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(LINE_END); dos.writeBytes(LINE_START + BOUNDRY + LINE_START + LINE_END); // close streams fileInputStream.close(); dos.flush(); dos.close(); //------------------ read the SERVER RESPONSE StringBuffer responseString = new StringBuffer(""); DataInputStream inStream = new DataInputStream(conn.getInputStream()); String line; while ((line = inStream.readLine()) != null) { responseString.append(line); } Log.d(LOG_TAG, "got response from server"); Log.d(LOG_TAG, responseString.toString()); // send request and retrieve response result.setResponseCode(conn.getResponseCode()); result.setResponse(responseString.toString()); inStream.close(); conn.disconnect(); // Revert back to the proper verifier and socket factories if (trustEveryone && url.getProtocol().toLowerCase().equals("https")) { ((HttpsURLConnection) conn).setHostnameVerifier(defaultHostnameVerifier); HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory); } return result; }
From source file:face4j.response.RemoveTagResponseImpl.java
public RemoveTagResponseImpl(String json) throws FaceClientException { super(json);//from w ww . ja v a2 s.c om try { removedTags = toRemovedTagList(response.getJSONArray("removed_tags")); } catch (JSONException jex) { logger.error("Error geting removed_tags: " + jex.getMessage(), jex); throw new FaceClientException(jex); } }
From source file:org.wso2.carbon.dataservices.core.description.query.MongoQuery.java
/** * This method convert Mongo json output to DataEntry object to support out mappings. * * @param jsonString Json String//from w ww . java2 s . c o m * @return DataEntry * @throws DataServiceFault */ private DataEntry wrapMongoRow(String jsonString, List<String> keyList) throws DataServiceFault { DataEntry dataEntry = new DataEntry(); try { JSONObject jsonObject = new JSONObject(jsonString); for (String key : keyList) { dataEntry.addValue(key, new ParamValue(getElementValueFromJson(jsonString, jsonObject, key))); } } catch (JSONException e) { // Normally there can't be any JSON Exception because Mongo send a proper json text for find queries. // but it send String for count queries. try { if (Integer.parseInt(jsonString) >= 0) { dataEntry.addValue(DBConstants.MongoDB.RESULT_COLUMN_NAME.toLowerCase(), new ParamValue(jsonString)); } } catch (NumberFormatException e1) { throw new DataServiceFault("Error occurred when retrieving data. :" + e.getMessage()); } } return dataEntry; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { try {//from ww w .ja v a 2 s.c om String packageName = obj.getString(PACKAGE_NAME); String feedName = obj.getString("sharedFeedName"); JSONArray ids = obj.getJSONArray(PARTICIPANTS); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra("type", "invite_app_feed"); launch.putExtra("creator", false); launch.putExtra("sender", from.id); launch.putExtra("sharedFeedName", feedName); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long[] idArray = new long[ids.length()]; for (int i = 0; i < ids.length(); i++) { idArray[i] = ids.getLong(i); } launch.putExtra("participants", idArray); launch.setPackage(packageName); final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show(); return; } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name, "Invitation received from " + from.name, "Click to launch application: " + packageName, contentIntent); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } }