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:org.collectionspace.chain.csp.webui.record.RecordSearchList.java

private void advancedSearch(Storage storage, UIRequest ui, String path, JSONObject params) throws UIException {

    try {//w  w  w.j a va 2s.co  m

        JSONObject results = new JSONObject();
        JSONObject restrictedkey = GenericSearch.setRestricted(ui, null, null, null, true, this.r);
        JSONObject restriction = restrictedkey.getJSONObject("restriction");
        String key = restrictedkey.getString("key");
        GenericSearch.buildQuery(this.r, params, restriction);

        key = "results";

        results = getJSON(storage, restriction, key, base);

        //cache for record traverser
        if (results.has("pagination") && results.getJSONObject("pagination").has("separatelists")) {
            GenericSearch.createTraverser(ui, this.r.getID(), "", results, restriction, key, 1);
        }
        ui.sendJSONResponse(results);
    } catch (JSONException e) {
        throw new UIException("JSONException during advancedSearch " + e.getMessage(), e);
    } catch (ExistException e) {
        throw new UIException("ExistException during search_or_list", e);
    } catch (UnimplementedException e) {
        throw new UIException("UnimplementedException during search_or_list", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        ui.sendJSONResponse(uiexception.getJSON());
    }
}

From source file:com.dedipower.portal.android.ViewTicket.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewticket);
    list = (ListView) findViewById(R.id.TicketUpdatesList);

    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);//ww  w. j  a va2  s  . c o  m
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(ViewTicket.this, listOfUpdates,
                        API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID"));
                Success = TicketAPI.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured. Error Code: 1";
                Log.e("APIFuncs", e.getMessage());
            }

            if (Success == "false") {
                try {
                    Log.i("APIFuncs", TicketAPI.toString(3));
                    ErrorMessage = TicketAPI.getString("msg");
                } catch (JSONException e) {
                    Log.e("APIFuncs", e.getMessage());
                }
            } else {
                Log.i("APIFuncs", TicketAPI.toString());
                try {
                    Updates = TicketAPI.getJSONArray("updates");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There are no updates for this ticket. (Strange!)";
                }

                int TicketCount = Updates.length();

                if (TicketCount == 0) {
                    ErrorMessage = "There are no updates for this ticket.";
                    return;
                }

                for (int i = 0; i < TicketCount; i++) {
                    try {
                        CurrentTicket = Updates.getJSONObject(i);

                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }

                    if (CurrentTicket != null) {
                        listOfUpdates.add(new TicketUpdates(GetString("type"), GetString("name"),
                                GetInt("time"), GetString("content")));
                    }
                }
                handler.sendEmptyMessage(0);
            }

        }
    };

    dataPreload.start();

    Button AddReply = (Button) findViewById(R.id.AddReplyButton);
    AddReply.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent CreateTicketReplyIntent = new Intent(ViewTicket.this, AddTicketReply.class);
            CreateTicketReplyIntent.putExtra("sessionid", API.SessionID);
            CreateTicketReplyIntent.putExtra("ticketid", getIntent().getStringExtra("ticketID"));
            ViewTicket.this.startActivity(CreateTicketReplyIntent);
        }
    });

    /*
    try 
    {
       TicketAPI = API.PortalQuery("updates", getIntent().getStringExtra("ticketID"));
      Success = TicketAPI.getString("success");   
    } 
    catch (JSONException e) 
    {
       UpdateErrorMessage("An unrecoverable JSON Exception occured. Error Code: 1");
       Log.e("APIFuncs",e.getMessage());
       //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show();
    }
            
    if(Success == "false")
    {
       try 
       {
     Log.i("APIFuncs",TicketAPI.toString(3));
    UpdateErrorMessage(TicketAPI.getString("msg"));
      } 
       catch (JSONException e) 
       {
     Log.e("APIFuncs",e.getMessage());
     UpdateErrorMessage("An unrecoverable JSON Exception occured.  Error Code: 2");
      }
    }
    else
    {
       Log.i("APIFuncs",TicketAPI.toString());
       try
        {
     Updates = TicketAPI.getJSONArray("updates");
      UpdateErrorMessage("");
        }
        catch (JSONException e) 
        {
      UpdateErrorMessage("There are no updates for this ticket. (Strange!)");
        }
                
        //OK lets actually do something useful
        List<TicketUpdates> listOfUpdates = new ArrayList<TicketUpdates>();
        int TicketCount = Updates.length();
                
        if(TicketCount == 0)
        {
      UpdateErrorMessage("There are no updates for this ticket.");
      return;
        }
                
        for(int i = 0; i < TicketCount; i++)
        {
    try 
    {
       CurrentTicket = Updates.getJSONObject(i);
            
    } 
    catch (JSONException e1) 
    {
       Log.e("APIFuncs",e1.getMessage());
    }
            
    if(CurrentTicket != null)
    {
       listOfUpdates.add(new TicketUpdates(GetString("type"),
            GetString("name"), 
            GetInt("time"), 
            GetString("content")));
    }
        }
        TicketUpdatesAdaptor adapter = new TicketUpdatesAdaptor(this, listOfUpdates, API.SessionID);
                
        list.setAdapter(adapter);
    }*/
}

From source file:org.entrystore.ldcache.util.JsonUtil.java

public static Set<Value> jsonArrayToValueSet(JSONArray array) {
    Set<Value> result = new HashSet<Value>();
    for (int i = 0; i < array.length(); i++) {
        String uri = null;//from w  w w. j ava  2 s  . com
        try {
            uri = array.getString(i);
        } catch (JSONException e) {
            log.warn(e.getMessage());
            continue;
        }
        if (uri != null) {
            result.add(new URIImpl(NS.expandNS(uri)));
        }
    }
    return result;
}

From source file:org.entrystore.ldcache.util.JsonUtil.java

public static Set<String> jsonArrayToStringSet(JSONArray array) {
    Set<String> result = new HashSet();
    for (int i = 0; i < array.length(); i++) {
        String uri = null;//from   www  . java  2 s .c o m
        try {
            uri = array.getString(i);
        } catch (JSONException e) {
            log.warn(e.getMessage());
            continue;
        }
        if (uri != null) {
            result.add(NS.expandNS(uri));
        }
    }
    return result;
}

From source file:org.entrystore.ldcache.util.JsonUtil.java

public static Map<Value, Value> jsonArrayToMap(JSONArray array) {
    Map<Value, Value> result = new HashMap<>();
    for (int i = 0; i < array.length(); i++) {
        try {/*from  ww  w  .  java  2 s.c  o m*/
            JSONObject obj = array.getJSONObject(i);
            if (obj.keys().hasNext()) {
                String key = (String) obj.keys().next();
                String value = obj.getString(key);
                if (key != null && value != null) {
                    result.put(new URIImpl(NS.expandNS(key)), new URIImpl(NS.expandNS(value)));
                }
            }
        } catch (JSONException e) {
            log.warn(e.getMessage());
            continue;
        }
    }
    return result;
}

From source file:org.entrystore.ldcache.util.JsonUtil.java

public static Map<Value, Value> jsonObjectToMap(JSONObject object) {
    Map<Value, Value> result = new HashMap<>();
    Iterator it = object.keys();/* w w  w.  jav a  2 s.  c  o m*/
    while (it.hasNext()) {
        String key = (String) it.next();
        try {
            String value = object.getString(key);
            if (key != null && value != null) {
                result.put(new URIImpl(NS.expandNS(key)), new URIImpl(NS.expandNS(value)));
            }
        } catch (JSONException e) {
            log.warn(e.getMessage());
            continue;
        }
    }
    return result;
}

From source file:org.mapfish.print.map.readers.WMSMapReader.java

public void render(Transformer transformer, ParallelMapTileLoader parallelMapTileLoader, String srs,
        boolean first) {
    PJsonObject customParams = params.optJSONObject("customParams");

    // store the rotation to not change for other layers
    double oldAngle = transformer.getRotation();

    // native WMS rotation - only works in singleTile mode
    if (customParams != null && customParams.optString("angle") != null) { // For GeoServer
        transformer.setRotation(0);/*from w  w w.j a v  a  2  s .c  o m*/
    }
    if (params.optBool("useNativeAngle", false)) {
        String angle = String.valueOf(-Math.toDegrees(transformer.getRotation()));
        try {
            if (customParams != null) {
                customParams.getInternalObj().put("angle", angle); // For GeoServer
                customParams.getInternalObj().put("map_angle", angle); // For MapServer
            } else {
                Map<String, String> customMap = new HashMap<String, String>();
                customMap.put("angle", angle); // For GeoServer
                customMap.put("map_angle", angle); // For MapServer
                params.getInternalObj().put("customParams", customMap);
            }
            transformer.setRotation(0);
        } catch (org.json.JSONException e) {
            LOGGER.error("Unable to set angle: " + e.getClass().getName() + " - " + e.getMessage());
        }
    }
    super.render(transformer, parallelMapTileLoader, srs, first);
    // restore the rotation for other layers
    transformer.setRotation(oldAngle);
}

From source file:uk.ac.imperial.presage2.web.export.DataExportServlet.java

/**
 * Takes a POST request with <code>query</code> parameter being a JSON table
 * specification and writes the resulting table back as the response. By
 * default we return a CSV file with the {@link CSVTableExporter}. Alternate
 * {@link TableExporter}s can be specified with the <code>format</code>
 * parameter.//from ww  w. j  av  a  2 s.  co  m
 * 
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    logRequest(req);
    JSONObject query = null;
    try {
        query = new JSONObject(new JSONTokener(req.getParameter("query")));
        logger.info(query.toString());
    } catch (JSONException e) {
        logger.warn("Failed to parse postdata", e);
        resp.sendError(400, "Failed to parse postdata: " + e.getMessage());
        return;
    }
    try {
        Iterable<Iterable<String>> table = processRequest(query);
        TableExporter exporter = new CSVTableExporter();
        exporter.httpExportTable(table, resp);
    } catch (JSONException e) {
        logger.warn("Failed to process request", e);
        resp.sendError(400, "Failed to process request");
    }
}

From source file:de.hackerspacebremen.format.JSONFormatter.java

@Override
public T reformat(final String object, final Class<T> entityClass) throws FormatException {
    T result = null;/*from   w  w w  .ja  v a 2 s.c o  m*/
    final Map<String, Field> fieldMap = new HashMap<String, Field>();
    if (entityClass.isAnnotationPresent(Entity.class)) {
        final Field[] fields = entityClass.getDeclaredFields();
        for (final Field field : fields) {
            if (field.isAnnotationPresent(FormatPart.class)) {
                fieldMap.put(field.getAnnotation(FormatPart.class).key(), field);
            }
        }
        try {
            final JSONObject json = new JSONObject(object);
            result = entityClass.newInstance();
            for (final String key : fieldMap.keySet()) {
                if (json.has(key)) {
                    final Field field = fieldMap.get(key);
                    final Method method = entityClass.getMethod(this.getSetter(field.getName()),
                            new Class<?>[] { field.getType() });

                    final String type = field.getType().toString();
                    if (type.equals("class com.google.appengine.api.datastore.Key")) {
                        method.invoke(result, KeyFactory.stringToKey(json.getString(key)));
                    } else if (type.equals("class com.google.appengine.api.datastore.Text")) {
                        method.invoke(result, new Text(json.getString(key)));
                    } else if (type.equals("boolean")) {
                        method.invoke(result, json.getBoolean(key));
                    } else if (type.equals("long")) {
                        method.invoke(result, json.getLong(key));
                    } else if (type.equals("int")) {
                        method.invoke(result, json.getInt(key));
                    } else {
                        method.invoke(result, json.get(key));
                    }
                }
            }
        } catch (JSONException e) {
            logger.warning("JSONException occured: " + e.getMessage());
            throw new FormatException();
        } catch (NoSuchMethodException e) {
            logger.warning("NoSuchMethodException occured: " + e.getMessage());
            throw new FormatException();
        } catch (SecurityException e) {
            logger.warning("SecurityException occured: " + e.getMessage());
            throw new FormatException();
        } catch (IllegalAccessException e) {
            logger.warning("IllegalAccessException occured: " + e.getMessage());
            throw new FormatException();
        } catch (IllegalArgumentException e) {
            logger.warning("IllegalArgumentException occured: " + e.getMessage());
            throw new FormatException();
        } catch (InvocationTargetException e) {
            logger.warning("InvocationTargetException occured: " + e.getMessage());
            throw new FormatException();
        } catch (InstantiationException e) {
            logger.warning("InstantiationException occured: " + e.getMessage());
            throw new FormatException();
        }
    }
    return result;
}

From source file:nl.cup_a_sep.ovalarm.plugin.StatusBarNotification.java

/**
 *    Executes the request and returns PluginResult
 *
 *    @param action      Action to execute
 *    @param data         JSONArray of arguments to the plugin
 *  @param callbackContext   The callback context used when calling back into JavaScript.
 *
 *  @return            A PluginRequest object with a status
 * *//*from  w  w w  . ja  va 2 s  .  co  m*/
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
    boolean actionValid = true;
    if (NOTIFY.equals(action)) {
        try {
            String tag = data.getString(0);
            String title = data.getString(1);
            String body = data.getString(2);
            String flag = data.getString(3);
            int notificationFlag = getFlagValue(flag);
            Log.d("NotificationPlugin",
                    "Notification: " + tag + ", " + title + ", " + body + ", " + notificationFlag);
            showNotification(tag, title, body, notificationFlag);
        } catch (JSONException jsonEx) {
            Log.d("NotificationPlugin", "Got JSON Exception " + jsonEx.getMessage());
            actionValid = false;
        }
    } else if (CLEAR.equals(action)) {
        try {
            String tag = data.getString(0);
            Log.d("NotificationPlugin", "Notification cancel: " + tag);
            clearNotification(tag);
        } catch (JSONException jsonEx) {
            Log.d("NotificationPlugin", "Got JSON Exception " + jsonEx.getMessage());
            actionValid = false;
        }
    } else {
        actionValid = false;
        Log.d("NotificationPlugin", "Invalid action : " + action + " passed");
    }
    return actionValid;
}