Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

In this page you can find the example usage for org.json JSONException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:app.nichepro.fragmenttab.account.AbstractGetNameTask.java

@Override
protected String doInBackground(Hashtable<String, String>... params) {
    String json = null;//from  w  w  w .  j  a  va  2 s.  c  om
    try {
        json = fetchNameFromProfileServer();
    } catch (IOException ex) {
        //         onError("Following Error occured, please try again. "
        //               + ex.getMessage(), ex);
        error = "Following Error occured, please try again. " + ex.getMessage();
    } catch (JSONException e) {
        //onError("Bad response: " + e.getMessage(), e);
        error = "Bad response: " + e.getMessage();

    }
    return json;
}

From source file:com.commontime.plugin.LocationManager.java

private void getMonitoredRegions(CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override/*from   www .  j  a  v  a2s.  com*/
        public PluginResult run() {
            try {
                Collection<Region> regions = iBeaconManager.getMonitoredRegions();
                JSONArray regionArray = new JSONArray();
                for (Region region : regions) {
                    regionArray.put(mapOfRegion(region));
                }

                return new PluginResult(PluginResult.Status.OK, regionArray);
            } catch (JSONException e) {
                debugWarn("'getMonitoredRegions' exception: " + e.getMessage());
                return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
            }
        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

private void getRangedRegions(CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override/*  w ww . java2s  . c  om*/
        public PluginResult run() {
            try {
                Collection<Region> regions = iBeaconManager.getRangedRegions();
                JSONArray regionArray = new JSONArray();
                for (Region region : regions) {
                    regionArray.put(mapOfRegion(region));
                }

                return new PluginResult(PluginResult.Status.OK, regionArray);
            } catch (JSONException e) {
                debugWarn("'getRangedRegions' exception: " + e.getMessage());
                return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
            }
        }
    });
}

From source file:gmc.hotplate.util.JsonParser.java

public List<Recipe> parseMessage(JSONObject obj) {
    List<Recipe> recipes = new ArrayList<Recipe>();
    try {/* w  w w  .j  ava2  s.c  om*/
        JSONArray jsonRecipes = obj.getJSONArray(TAG_RECIPES);
        for (int i = 0; i < jsonRecipes.length(); i++) {
            Recipe recipe = parseRecipeObject(jsonRecipes.getJSONObject(i));
            if (recipe != null) {
                recipes.add(recipe);
            }
        }
    } catch (JSONException e) {
        Log.w(LOG_TAG, "ParseMessage() error: " + e.getMessage());
    }
    return recipes;
}

From source file:gmc.hotplate.util.JsonParser.java

public Recipe parseRecipeObject(JSONObject obj) {
    Recipe recipe = null;//from w ww.j a v a2s . c o  m
    try {
        int recipeId = obj.getInt(TAG_RECIPE_ID);
        String recipeName = obj.getString(TAG_RECIPE_NAME);
        String recipeDescription = obj.getString(TAG_RECIPE_DESCRIPTION);
        int personCount = obj.getInt(TAG_RECIPE_PERSON);
        JSONArray jsonSteps = obj.getJSONArray(TAG_RECIPE_STEPS);
        List<Step> steps = new ArrayList<Step>();
        for (int i = 0; i < jsonSteps.length(); i++) {
            Step step = parseStepObject(jsonSteps.getJSONObject(i));
            if (step != null) {
                steps.add(step);
            }
        }

        List<Ingredient> ingredients = new ArrayList<Ingredient>();
        JSONArray jsonIngredients = obj.getJSONArray(TAG_RECIPE_INGREDIENTS);
        for (int i = 0; i < jsonIngredients.length(); i++) {
            Ingredient ingredient = parseIngredientObject(jsonIngredients.getJSONObject(i));
            if (ingredient != null) {
                ingredients.add(ingredient);
            }
        }

        List<String> categories = new ArrayList<String>();
        if (obj.has(TAG_RECIPE_CATEGORIES)) {
            JSONArray jsonCategories = obj.getJSONArray(TAG_RECIPE_CATEGORIES);
            for (int i = 0; i < jsonCategories.length(); i++) {
                String tag = jsonCategories.getString(i);
                categories.add(tag);
            }
        }
        recipe = new Recipe(recipeId, recipeName, recipeDescription, personCount, steps);
        recipe.setIngredients(ingredients);
        recipe.setCategories(categories);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "ParseRecipe() error: " + e.getMessage());
    }

    return recipe;
}

From source file:gmc.hotplate.util.JsonParser.java

public Step parseStepObject(JSONObject obj) {
    Step step = null;//from   www .  j a v  a  2s  .  c  o  m
    try {
        int stepId = obj.getInt(TAG_STEP_ID);
        String stepDescription = obj.getString(TAG_STEP_DESCRIPTION);
        int seconds = obj.getInt(TAG_STEP_TIME);
        step = new Step(stepId, stepDescription, seconds);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "ParseStep() error: " + e.getMessage());
    }
    return step;
}

From source file:gmc.hotplate.util.JsonParser.java

public Ingredient parseIngredientObject(JSONObject obj) {
    Ingredient ingredient = null;//from  w w  w . j  a v  a 2 s .c o m
    try {
        String name = obj.getString(TAG_INGREDIENTS_NAME);
        double amount = obj.getDouble(TAG_INGREDIENTS_AMOUNT);
        String type = obj.getString(TAG_INGREDIENTS_TYPE);
        ingredient = new Ingredient(name, amount, type);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "ParseIngredient() error: " + e.getMessage());
    }
    return ingredient;
}

From source file:org.entrystore.ldcache.LDCache.java

private boolean isProxyEnabled() {
    try {//from   ww  w  . j  a v a 2 s  .c  om
        if (config != null) {
            return config.getJSONObject("proxy").getBoolean("enabled");
        }
    } catch (JSONException e) {
        log.error(e.getMessage());
    }
    return false;
}

From source file:org.collectionspace.chain.csp.webui.record.RecordCreateUpdate.java

private void store_set(Storage storage, UIRequest request, String path) throws UIException {
    try {// www  .j  a v a  2  s . c  o  m
        JSONObject restrictions = new JSONObject();
        JSONObject data = request.getJSONBody();

        if (this.base.equals("role")) {
            JSONObject fields = data.optJSONObject("fields");
            if ((fields.optString("roleName") == null || fields.optString("roleName").equals(""))
                    && fields.optString("displayName") != null) {
                String test = fields.optString("displayName");
                test = test.toUpperCase();
                test.replaceAll("\\W", "_");
                fields.put("roleName", "ROLE_" + test);
                data.put("fields", fields);
            }
            // If we are updating a role, then we need to clear the userperms cache
            // Note that creating a role does not impact things until we assign it
            if (!create) {
                ResponseCache.clearCache(ResponseCache.USER_PERMS_CACHE);
            }
        }

        if (this.record.getID().equals("media")) {
            JSONObject fields = data.optJSONObject("fields");
            // Handle linked media references
            if (!fields.has("blobCsid") || StringUtils.isEmpty(fields.getString("blobCsid"))) { // If has blobCsid, already has media link so do nothing more
                // No media, so consider the source
                // "sourceUrl" is not a declared field in the app layer config, but the UI passes it in
                // Can consider mapping srcUri to this if want to clean that up
                if (fields.has("sourceUrl")) {
                    // We have a source - see where it is from
                    String uri = fields.getString("sourceUrl");
                    if (uri.contains(BLOBS_SERVICE_URL_PATTERN)) {
                        // This is an uploaded blob, so just pull the csid and set into blobCsid
                        String[] parts = uri.split(BLOBS_SERVICE_URL_PATTERN); // Split to get CSID
                        String[] bits = parts[1].split("/"); // Strip off anything trailing the CSID
                        fields.put("blobCsid", bits[0]);
                    } else { // This must be an external Url source
                        // External Source is handled as params to the CREATE/UPDATE of the media record
                        restrictions.put(Record.BLOB_SOURCE_URL, uri);
                        // Tell the Services to delete the original after creating derivatives
                        restrictions.put(Record.BLOB_PURGE_ORIGINAL, Boolean.toString(true));
                    }
                    fields.remove("sourceUrl");
                    data.put("fields", fields);
                }
            }
        }

        if (this.record.getID().equals("output")) {
            //
            // Invoke a report
            //
            ReportUtils.invokeReport(this, storage, request, path);
        } else if (this.record.getID().equals("batchoutput")) {
            //do a read instead of a create as reports are special and evil

            JSONObject fields = data.optJSONObject("fields");
            JSONObject payload = new JSONObject();
            payload.put("mode", "single");

            if (fields.has("mode")) {
                payload.put("mode", fields.getString("mode"));
            }
            if (fields.has("docType")) {
                String type = spec.getRecordByWebUrl(fields.getString("docType")).getServicesTenantSg();
                payload.put("docType", type);
            }
            if (fields.has("singleCSID")) {
                payload.put("singleCSID", fields.getString("singleCSID"));
            } else if (fields.has("groupCSID")) {
                payload.put("singleCSID", fields.getString("csid"));
            }

            JSONObject out = storage.retrieveJSON(base + "/" + path, payload);

            byte[] data_array = (byte[]) out.get("getByteBody");
            String contentDisp = out.has("contentdisposition") ? out.getString("contentdisposition") : null;
            request.sendUnknown(data_array, out.getString("contenttype"), contentDisp);
            request.setCacheMaxAgeSeconds(0); // Ensure we do not cache report output.
            //request.sendJSONResponse(out);
            request.setOperationPerformed(create ? Operation.CREATE : Operation.UPDATE);
        } else {
            //
            // <Please document this clause.>
            //
            FieldSet displayNameFS = this.record.getDisplayNameField();
            String displayNameFieldName = (displayNameFS != null) ? displayNameFS.getID() : null;
            boolean remapDisplayName = false;
            String remapDisplayNameValue = null;
            boolean quickie = false;
            if (create) {
                quickie = (data.has("_view") && data.getString("_view").equals("autocomplete"));
                remapDisplayName = quickie && !"displayName".equals(displayNameFieldName);
                // Check to see if displayName field needs remapping from UI
                if (remapDisplayName) {
                    // Need to map the field for displayName, and put it into a proper structure
                    JSONObject fields = data.getJSONObject("fields");
                    remapDisplayNameValue = fields.getString("displayName");
                    if (remapDisplayNameValue != null) {
                        // This needs generalizing, in case the remapped name is nested
                        /*
                         * From vocab handling where we know where the termDisplayName is
                        FieldSet parentTermGroup = (FieldSet)displayNameFS.getParent();
                        JSONArray parentTermInfoArray = new JSONArray();
                        JSONObject termInfo = new JSONObject();
                        termInfo.put(displayNameFieldName, remapDisplayNameValue);
                        parentTermInfoArray.put(termInfo);
                        */
                        fields.put(displayNameFieldName, remapDisplayNameValue);
                        fields.remove("displayName");
                    }
                }
                path = sendJSON(storage, null, data, restrictions); // REM - We needed a way to send query params, so I'm adding "restrictions" here
                data.put("csid", path);
                data.getJSONObject("fields").put("csid", path);
                // Is this needed???
                /*
                String refName = data.getJSONObject("fields").getString("refName");
                data.put("urn", refName);
                data.getJSONObject("fields").put("urn", refName);
                // This seems wrong - especially when we create from existing.
                if(remapDisplayName){
                   JSONObject newdata = new JSONObject();
                   newdata.put("urn", refName);
                   newdata.put("displayName",quickieDisplayName);
                   data = newdata;
                }
                 */
            } else {
                path = sendJSON(storage, path, data, restrictions);
            }

            if (path == null) {
                throw new UIException("Insufficient data for create (no fields?)");
            }

            if (this.base.equals("role")) {
                assignPermissions(storage, path, data);
            }
            if (this.base.equals("termlist")) {
                assignTerms(storage, path, data);
            }

            data = reader.getJSON(storage, path); // We do a GET now to read back what we created.
            if (quickie) {
                JSONObject newdata = new JSONObject();
                JSONObject fields = data.getJSONObject("fields");
                String displayName = fields.getString(remapDisplayName ? displayNameFieldName : "displayName");
                newdata.put("displayName", remapDisplayNameValue);
                String refName = fields.getString("refName");
                newdata.put("urn", refName);
                data = newdata;
            }

            request.sendJSONResponse(data);
            request.setOperationPerformed(create ? Operation.CREATE : Operation.UPDATE);
            if (create)
                request.setSecondaryRedirectPath(new String[] { url_base, path });
        }
    } catch (JSONException x) {
        throw new UIException("Failed to parse JSON: " + x, x);
    } catch (ExistException x) {
        UIException uiexception = new UIException(x.getMessage(), 0, "", x);
        request.sendJSONResponse(uiexception.getJSON());
    } catch (UnimplementedException x) {
        throw new UIException("Unimplemented exception: " + x, x);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.setStatus(x.getStatus());
        request.setFailure(true, uiexception);
        request.sendJSONResponse(uiexception.getJSON());
    } catch (Exception x) {
        throw new UIException(x);
    }

}

From source file:com.mobiperf_library.util.MeasurementJsonConvertor.java

public static MeasurementTask makeMeasurementTaskFromJson(JSONObject json) throws IllegalArgumentException {
    try {//from www  . jav  a2  s  .co  m
        String type = String.valueOf(json.getString("type"));
        Class taskClass = MeasurementTask.getTaskClassForMeasurement(type);
        Method getDescMethod = taskClass.getMethod("getDescClass");
        // The getDescClassForMeasurement() is static and takes no arguments
        Class descClass = (Class) getDescMethod.invoke(null, (Object[]) null);
        MeasurementDesc measurementDesc = (MeasurementDesc) gson.fromJson(json.toString(), descClass);

        Object cstParam = measurementDesc;
        Constructor<MeasurementTask> constructor = taskClass.getConstructor(MeasurementDesc.class);
        return constructor.newInstance(cstParam);
    } catch (JSONException e) {
        throw new IllegalArgumentException(e);
    } catch (SecurityException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (NoSuchMethodException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (IllegalArgumentException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (InstantiationException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (InvocationTargetException e) {
        Logger.w(e.toString());
        throw new IllegalArgumentException(e);
    }
}