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.jabsorb.ng.serializer.impl.ArraySerializer.java

@Override
public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException {

    try {/*  w  w  w  .  j a  v a 2s  .c o  m*/
        final JSONArray arr = new JSONArray();
        if (o instanceof int[]) {
            final int a[] = (int[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof long[]) {
            final long a[] = (long[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof short[]) {
            final short a[] = (short[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof byte[]) {
            final byte a[] = (byte[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof float[]) {
            final float a[] = (float[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof double[]) {
            final double a[] = (double[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof char[]) {
            final char a[] = (char[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof boolean[]) {
            final boolean a[] = (boolean[]) o;
            for (int i = 0; i < a.length; i++) {
                arr.put(a[i]);
            }
        } else if (o instanceof Object[]) {
            final Object a[] = (Object[]) o;
            for (int i = 0; i < a.length; i++) {
                final Object json = ser.marshall(state, o, a[i], new Integer(i));
                if (JSONSerializer.CIRC_REF_OR_DUPLICATE == json) {
                    // if dup or circ ref found, put a null slot in
                    // the array to maintain the array numbering for the
                    // fixups
                    arr.put(JSONObject.NULL);
                } else {
                    arr.put(json);
                }
            }
        }
        return arr;

    } catch (final JSONException e) {
        throw new MarshallException(e.getMessage() + " threw json exception", e);
    }

}

From source file:com.composum.osgi.core.test.httpinterface.TestExecutorServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from ww  w  . j a  va 2s . co m
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final List<Result> runTests = this.testExecutorService.runTests();
    final JSONWriter jsonWriter = new org.json.JSONWriter(resp.getWriter());
    try {
        JSONWriter tests = jsonWriter.object().key("tests").array();
        for (final Result result : runTests) {
            final String name = result.getDescription().getDisplayName();
            final boolean success = result.isSuccess();
            final Failure failure = result.getFailure();
            final String message = success ? "ok" : failure.getMessage();
            final String trace = success ? "" : failure.getTrace();
            tests = tests.object().key("name").value(name).key("success").value(success).key("message")
                    .value(message).key("trace").value(trace).endObject();
        }
        tests.endArray().endObject();
    } catch (final JSONException e) {
        throw new ServletException("error writing JSON response: " + e.getMessage(), e);
    }
}

From source file:com.blockwithme.longdb.test.BETableJUnit.java

/** Validate all test rows. */
private void validateAllTestRows() {

    try {/*from  www  .ja  va  2s.c o  m*/
        final LongArrayList rowIDs = J_UTIL.getRowIDs();

        for (final LongCursor rowCursor : rowIDs) {
            final LongObjectOpenHashMap<Bytes> jColumnsData = J_UTIL.getColumnData(rowCursor.value);
            final Columns dbColumns = table.get(rowCursor.value);
            assertNotNull("No Columns found for row ID:" + rowCursor.value, dbColumns);
            for (final LongHolder longHolder : dbColumns) {
                final long colkey = longHolder.value();
                assertTrue(colkey + " Not present in row " + rowCursor.value, dbColumns.containsColumn(colkey));
                final Bytes dbBytes = dbColumns.getBytes(colkey);
                assertNotNull("data not present for column id " + colkey + " row id " + rowCursor.value,
                        dbBytes);
                final Bytes jBytes = jColumnsData.get(colkey);
                assertEquals("Assertion failure for row : " + rowCursor.value + " column ID :" + colkey,
                        dbBytes, jBytes);
            }
        }
    } catch (final JSONException exp) {
        fail(exp.getMessage());
    } catch (final UnsupportedEncodingException e) {
        fail(e.getMessage());
    }
}

From source file:com.browseengine.bobo.servlet.BrowseServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    SolrParams params = new BoboHttpRequestParam(req);
    String qstring = params.get(CommonParams.Q);
    String df = params.get(CommonParams.DF);
    String sortString = params.get(CommonParams.SORT);
    BoboDefaultQueryBuilder qbuilder = new BoboDefaultQueryBuilder();
    Query query = qbuilder.parseQuery(qstring, df);
    Sort sort = qbuilder.parseSort(sortString);
    BrowseRequest br = null;/* ww w .j a va  2 s.c o  m*/
    try {
        br = BoboRequestBuilder.buildRequest(params, query, sort);
        logger.info("REQ: " + BrowseProtobufConverter.toProtoBufString(br));
        BrowseResult result = _svc.browse(br);
        res.setCharacterEncoding("UTF-8");
        Writer writer = res.getWriter();

        String outputFormat = req.getParameter("output");
        if ("json".equals(outputFormat)) {
            try {
                String val = BrowseJSONSerializer.serialize(result);
                writer.write(val);
            } catch (JSONException je) {
                throw new IOException(je.getMessage());
            }
        } else {
            XStream xstream = XStreamDispenser.getXMLXStream();
            writer.write(xstream.toXML(result));
        }

    } catch (BrowseException e) {
        throw new ServletException(e.getMessage(), e);
    }
}

From source file:org.loklak.android.tools.JsonIO.java

public static JSONObject loadJson(String url) {
    StringBuilder sb = loadString(url);
    if (sb == null || sb.length() == 0)
        return new JSONObject();
    JSONObject json = null;/*from  w  ww.  j  a va 2  s  . c  om*/
    try {
        json = new JSONObject(sb.toString());
    } catch (JSONException e) {
        Log.e("loadJson", e.getMessage(), e);
        e.printStackTrace();
        return new JSONObject();
    }
    return json;
}

From source file:org.loklak.android.tools.JsonIO.java

public static JSONObject pushJson(String requestURL, String jsonDataName, JSONObject json) {
    try {/*from  w  ww . jav  a2s  .c o m*/
        String boundary = "===" + System.currentTimeMillis() + "===";

        URL url = new URL(requestURL);
        //HttpURLConnection con = (HttpURLConnection) url.openConnection();
        URLConnection uc = (url).openConnection();
        HttpURLConnection con = requestURL.startsWith("https") ? (HttpsURLConnection) uc
                : (HttpURLConnection) uc;
        con.setUseCaches(false);
        con.setDoOutput(true);
        con.setDoInput(true);
        con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
        con.setRequestProperty("User-Agent", USER_AGENT);
        OutputStream outputStream = con.getOutputStream();
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), true);

        writer.append("--" + boundary).append(CRLF);
        writer.append("Content-Disposition: form-data; name=\"" + "data" + "\"").append(CRLF);
        writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
        writer.append(CRLF);
        writer.append(json.toString()).append(CRLF);
        writer.flush();

        writer.append(CRLF).flush();
        writer.append("--" + boundary + "--").append(CRLF);
        writer.close();
        int status = con.getResponseCode();
        if (status == HttpURLConnection.HTTP_OK) {
            StringBuilder sb = load(con);
            try {
                json = new JSONObject(sb.toString());
                return json;
            } catch (JSONException e) {
                Log.e("loadJson", e.getMessage(), e);
                e.printStackTrace();
                return new JSONObject();
            }
        } else {
            throw new IOException("Server returned non-OK status: " + status);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new JSONObject();
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static void handleJSONException(final JSONException e) throws ApiException {
    if (AppContext.DEBUG) {
        Log.e(ApiParser.TAG, e.getMessage());
    }//from   w  w w. j a v a  2 s. c o  m
    throw new ApiException(ResponseCode.ERROR_JSON_EXCEPTION, e.getMessage(), e.getCause());
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static Search savedSearch(final JSONObject o) throws IOException {
    try {/*  w w  w.  j a  v  a  2s. co  m*/
        final Search s = new Search();
        s.name = o.getString(ApiParser.NAME);
        s.query = o.getString(ApiParser.QUERY);
        return s;
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }
    return null;
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static Search savedSearch(final String content) throws IOException {
    try {/*from   w ww  . ja  v  a2  s .co  m*/
        final JSONObject o = new JSONObject(content);
        return ApiParser.savedSearch(o);
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }
    return null;
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static ArrayList<Search> savedSearches(final JSONArray a) throws IOException {
    try {/*w  w w. j  a  v a2s. c o  m*/
        final ArrayList<Search> ss = new ArrayList<Search>();
        for (int i = 0; i < a.length(); i++) {
            final JSONObject o = a.getJSONObject(i);
            final Search s = ApiParser.savedSearch(o);
            ss.add(s);
        }
        return ss;
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }
    return new ArrayList<Search>();
}