Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:IoTatWork.AuCapTreeResource.java

/**
 * /*from   www.  j  a va  2  s  . c om*/
 * @param auCapRid
 * @param depth 
 * @param jsonNodeTree 
 * @return
 */
private void getJsonNodeTree(Vertex auCapNode, JSONObject jsonNodeTree, int depth, boolean toRevoke,
        Object revokedSince) {

    //graph.getRawGraph();
    try {

        OGraphDatabase rawGraph = graph.getRawGraph();
        ODocument doc = rawGraph.load((ORID) auCapNode.getId());
        //System.out.println(doc.getClassName());
        if (doc.getClassName().equals(DataMapper.AUCAP_VERTEX)) {
            getJsonAuCapVertexData(auCapNode, jsonNodeTree);
            JSONObject jsonData = (JSONObject) jsonNodeTree.get("data");
            if (!toRevoke) {
                //controllo se lui o i figli sono sa revocare
                String status = (String) auCapNode.getProperty(DataMapper.STATUS);
                if (status.equals(Status.REVOKED)) {
                    String revocationScope = (String) auCapNode.getProperty(DataMapper.REVOCATION_SCOPE);
                    if (revocationScope.equals(RevocationScope.ALL)) {
                        jsonData.put(DataMapper.STATUS, Status.REVOKED);
                        jsonData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
                        toRevoke = true;
                        revokedSince = auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE);
                    } else if (revocationScope.equals(RevocationScope.THIS)) {
                        jsonData.put(DataMapper.STATUS, Status.REVOKED);
                        jsonData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
                    } else if (revocationScope.equals(RevocationScope.DESCENDANT)) {
                        jsonData.put(DataMapper.STATUS, Status.VALID);
                        toRevoke = true;
                        revokedSince = auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE);
                    }

                }

            } else {
                //metto lo status a Revoked e metto il campo revokedSince
                jsonData.put(DataMapper.REVOKED_SINCE, revokedSince);
                jsonData.put(DataMapper.STATUS, Status.REVOKED);
            }

            Iterable<Edge> dependentEdges = auCapNode.getEdges(Direction.OUT,
                    DataMapper.DEPENDENT_CAPABILIES_LABEL);
            JSONArray jsonArrayDependant = new JSONArray();
            depth++;
            for (Edge depend : dependentEdges) {

                if (depth <= this.depth) {
                    JSONObject jsonDependantNode = new JSONObject();
                    jsonArrayDependant.put(jsonDependantNode);
                    Vertex dependantVertex = depend.getVertex(Direction.IN);
                    getJsonNodeTree(dependantVertex, jsonDependantNode, depth, toRevoke, revokedSince);
                }

            }

            jsonNodeTree.put("children", jsonArrayDependant);

        } else {
            jsonNodeTree.put("id", auCapNode.getId().toString().substring(1));
            jsonNodeTree.put("name", auCapNode.getProperty("name").toString());

            Iterable<Edge> dependentEdges = auCapNode.getEdges(Direction.OUT);

            JSONObject jsonData = new JSONObject();
            String edgeLabel = dependentEdges.iterator().next().getLabel();
            jsonData.put("edgeLabel", edgeLabel);
            jsonNodeTree.put("data", jsonData);

            JSONArray jsonArrayDependant = new JSONArray();
            depth++;
            for (Edge depend : dependentEdges) {

                if (depth <= this.depth) {
                    JSONObject jsonDependantNode = new JSONObject();
                    jsonArrayDependant.put(jsonDependantNode);
                    Vertex dependantVertex = depend.getVertex(Direction.IN);
                    getJsonNodeTree(dependantVertex, jsonDependantNode, depth, false, null);
                }
            }

            jsonNodeTree.put("children", jsonArrayDependant);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:IoTatWork.AuCapTreeResource.java

/**
 * /*from   w ww.j a  va2s . co m*/
 * @param auCapNode
 * @param jsonNodeTree 
 * @return
 */
private void getJsonAuCapVertexData(Vertex auCapNode, JSONObject jsonNodeTree) {
    try {

        Vertex detailsVertex = auCapNode.getEdges(Direction.OUT, DataMapper.DETAILS_LABEL).iterator().next()
                .getVertex(Direction.IN);
        jsonNodeTree.put("id", auCapNode.getId().toString().substring(1));
        jsonNodeTree.put("name", detailsVertex.getProperty(DataMapper.SUBJECT_ID).toString());
        JSONObject jsonVertexData = new JSONObject();
        jsonVertexData.put("edgeLabel", DataMapper.DEPENDENT_CAPABILIES_LABEL);

        //AuCapVertex
        jsonVertexData.put(DataMapper.CAPABILITY_ID, auCapNode.getProperty(DataMapper.CAPABILITY_ID));
        jsonVertexData.put(DataMapper.CAPABILITY_ISSUER, auCapNode.getProperty(DataMapper.CAPABILITY_ISSUER));
        jsonVertexData.put(DataMapper.CAPABILITY_ISSUE_TIME,
                auCapNode.getProperty(DataMapper.CAPABILITY_ISSUE_TIME));

        String status = (String) auCapNode.getProperty(DataMapper.STATUS);
        jsonVertexData.put(DataMapper.STATUS, status);

        /*
        if(status.equals(Status.REVOKED)){
           String revocationScope = (String) auCapNode.getProperty(DataMapper.REVOCATION_SCOPE);
           jsonVertexData.put(DataMapper.REVOCATION_SCOPE, revocationScope);
           if(revocationScope.equals(RevocationScope.ALL)){
              jsonVertexData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
              jsonVertexData.put(DataMapper.DESCENDANT_REVOKED_SINCE, auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE));
           }else if(revocationScope.equals(RevocationScope.THIS)){
              jsonVertexData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
           }else if(revocationScope.equals(RevocationScope.DESCENDANT)){
              jsonVertexData.put(DataMapper.DESCENDANT_REVOKED_SINCE, auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE));
           }
                   
        }
        */

        jsonVertexData.put(DataMapper.VALIDITY_START_TIME,
                auCapNode.getProperty(DataMapper.VALIDITY_START_TIME));
        jsonVertexData.put(DataMapper.VALIDITY_END_TIME, auCapNode.getProperty(DataMapper.VALIDITY_END_TIME));

        //AuCapDetails
        jsonVertexData.put(DataMapper.SUBJECT_ID, detailsVertex.getProperty(DataMapper.SUBJECT_ID));
        jsonVertexData.put(DataMapper.RESOURCE_ID, detailsVertex.getProperty(DataMapper.RESOURCE_ID));
        jsonVertexData.put(DataMapper.REVOCATION_SERVICE_URLS,
                detailsVertex.getProperty(DataMapper.REVOCATION_SERVICE_URLS));

        if (!auCapNode.getEdges(Direction.OUT, DataMapper.DEPENDENT_CAPABILIES_LABEL).iterator().hasNext()) {
            jsonVertexData.put("leaf", "leaf");
        }
        //         for(String prop : auCapNode.getPropertyKeys()){
        //            jsonVertexData.put(prop, auCapNode.getProperty(prop));
        //         }
        //         for(String prop : detailsVertex.getPropertyKeys()){
        //            if(!prop.equals(DataMapper.CAPABILITY_TOKEN))
        //               jsonVertexData.put(prop, detailsVertex.getProperty(prop));
        //         }
        JSONArray jsonArrayAccessRights = new JSONArray();
        for (Edge accessRightEdge : detailsVertex.getEdges(Direction.OUT, DataMapper.ACCESS_RIGHTS_LABEL)) {
            Vertex accesRightVertex = accessRightEdge.getVertex(Direction.IN);
            JSONObject jsonAccessRight = new JSONObject();
            for (String prop : accesRightVertex.getPropertyKeys()) {
                jsonAccessRight.put(prop, accesRightVertex.getProperty(prop));
            }
            jsonArrayAccessRights.put(jsonAccessRight);
        }
        jsonVertexData.put(DataMapper.ACCESS_RIGHTS_LABEL, jsonArrayAccessRights);
        jsonNodeTree.put("data", jsonVertexData);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public JSONObject getCreateAction(int actionId) {
    JSONObject js = new JSONObject();

    try {/*from   w  ww . ja  v  a2  s  .c  o m*/
        // action_type
        js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);

        // action_id
        js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);

        // index
        js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));

        // entity_delta
        JSONObject entity = new JSONObject();
        entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
        entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
        entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_TASK);
        if (getNotes() != null) {
            entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
        }
        js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);

        // parent_id
        js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());

        // dest_parent_type
        js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP);

        // list_id
        js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());

        // prior_sibling_id
        if (mPriorSibling != null) {
            js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid());
        }

    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new ActionFailureException("fail to generate task-create jsonobject");
    }

    return js;
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public JSONObject getUpdateAction(int actionId) {
    JSONObject js = new JSONObject();

    try {/* ww w  .  j  a va 2  s .  c  o m*/
        // action_type
        js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);

        // action_id
        js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);

        // id
        js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());

        // entity_delta
        JSONObject entity = new JSONObject();
        entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
        if (getNotes() != null) {
            entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
        }
        entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
        js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);

    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new ActionFailureException("fail to generate task-update jsonobject");
    }

    return js;
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {/*from   ww w .j a v a2s. c  o  m*/
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

            // notes
            if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
                setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
            }

            // deleted
            if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
                setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
            }

            // completed
            if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
                setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get task content from jsonobject");
        }
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public void setContentByLocalJSON(JSONObject js) {
    if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
        Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
    }//from   w  w  w.j ava  2s.c o  m

    try {
        JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
        JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

        if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
            Log.e(TAG, "invalid type");
            return;
        }

        for (int i = 0; i < dataArray.length(); i++) {
            JSONObject data = dataArray.getJSONObject(i);
            if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                setName(data.getString(DataColumns.CONTENT));
                break;
            }
        }

    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public JSONObject getLocalJSONFromContent() {
    String name = getName();//  w w  w.  ja v a 2  s. com
    try {
        if (mMetaInfo == null) {
            // new task created from web
            if (name == null) {
                Log.w(TAG, "the note seems to be an empty one");
                return null;
            }

            JSONObject js = new JSONObject();
            JSONObject note = new JSONObject();
            JSONArray dataArray = new JSONArray();
            JSONObject data = new JSONObject();
            data.put(DataColumns.CONTENT, name);
            dataArray.put(data);
            js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            js.put(GTaskStringUtils.META_HEAD_NOTE, note);
            return js;
        } else {
            // synced task
            JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
            JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject data = dataArray.getJSONObject(i);
                if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                    data.put(DataColumns.CONTENT, getName());
                    break;
                }
            }

            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            return mMetaInfo;
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        return null;
    }
}

From source file:org.restcomm.app.utillib.Reporters.WebReporter.WebReporter.java

public static String geocode(Context context, double latitude, double longitude) {
    String addressString = String.format("%.4f, %.4f", latitude, longitude);
    try {/*from  w w  w.  j av a2  s. c  o  m*/
        String apiKey = Global.getApiKey(context);
        String server = Global.getApiUrl(context);
        String url = server + "/api/osm/location?apiKey=" + apiKey + "&location=" + latitude + "&location="
                + longitude;
        String response = WebReporter.getHttpURLResponse(url, false);

        JSONObject json = null;
        JSONArray jsonArray = null;

        if (response == null)
            return addressString;

        try {
            jsonArray = new JSONArray(response);
        } catch (JSONException e) {
            return addressString;
        }
        try {
            for (int i = 0; i < jsonArray.length(); i++) {
                json = jsonArray.getJSONObject(i);
                if (json.has("error")) {
                    String error = json.getString("error");
                    return null;
                } else {
                    addressString = "";
                    json = json.getJSONObject("address");
                    String number = "";
                    if (json.has("house_number")) {
                        number = json.getString("house_number");
                        addressString += number + " ";
                    }
                    String road = json.getString("road");
                    addressString += road;// + suburb;
                    return addressString;
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
    }

    return addressString;
}

From source file:com.jaspersoft.jasperserver.ps.OAuth.JSONUtils.java

public static Map<String, String> getJSONasMap(JSONObject js) {
    Map<String, String> out = new HashMap<String, String>();

    try {/*from  ww w .  j  a  va 2s  . c om*/
        parse(js, out);
        return out;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:com.jaspersoft.jasperserver.ps.OAuth.JSONUtils.java

public static JSONObject getClaimsInformationFromAccessTokenAsJsonNode(String tokenString) {
    String[] pieces = splitTokenString(tokenString);
    String jwtHeaderSegment = pieces[0];
    String jwtPayloadSegment = pieces[1];
    byte[] signature = Base64.decodeBase64(pieces[2]);
    ObjectMapper mapper = new ObjectMapper();

    JSONObject myobj;//from  w ww . j  a v  a2 s  .  co  m
    try {
        myobj = new JSONObject(new String(Base64.decodeBase64(jwtPayloadSegment)));
        return myobj;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;

}