Search in sources :

Example 6 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class ServiceManagementServlet method healthCheck.

/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
private Result healthCheck(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String json = Utils.readInputStream(request.getInputStream(), FormConstants.CHAR_ENC_DEFAULT);
    Result result = null;
    try {
        ClusterNodeRequest nodeRequest = (ClusterNodeRequest) new JSONObjectBuilder().fromJSON(new JSONObject(json), new ClusterNodeRequest());
        Map<String, String> properties = (Map<String, String>) context.getBean("openmeapServicesWebPropertiesMap");
        synchronized (properties) {
            properties.put("clusterNodeUrlPrefix", nodeRequest.getClusterNode().getServiceWebUrlPrefix());
            properties.put("fileSystemStoragePathPrefix", nodeRequest.getClusterNode().getFileSystemStoragePathPrefix());
        }
        result = new Result(Result.Status.SUCCESS);
    } catch (JSONException e) {
        result = new Result();
        result.setStatus(Result.Status.FAILURE);
        String msg = "Failed to parse health status check JSON - " + json;
        logger.error(msg);
        result.setMessage(msg);
    }
    return result;
}
Also used : JSONObjectBuilder(com.openmeap.json.JSONObjectBuilder) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) ClusterNodeRequest(com.openmeap.cluster.dto.ClusterNodeRequest) Map(java.util.Map) Result(com.openmeap.services.dto.Result)

Example 7 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class ServiceManagementServlet method sendResult.

private void sendResult(HttpServletResponse response, PrintWriter os, Result result) throws IOException {
    try {
        if (result.getStatus() != Result.Status.SUCCESS) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        }
        JSONObject jsonResult = new JSONObjectBuilder().toJSON(result);
        String stringResult = jsonResult.toString(3);
        logger.debug("returning json result: {}", stringResult);
        os.print(jsonResult);
    } catch (JSONException jse) {
        throw new IOException(jse);
    }
    os.flush();
    os.close();
}
Also used : JSONObjectBuilder(com.openmeap.json.JSONObjectBuilder) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) IOException(java.io.IOException)

Example 8 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class JsError method toJSONObject.

public JSONObject toJSONObject() {
    JSONObject err = new JSONObject();
    try {
        err.put("type", type);
        err.put("message", message);
    } catch (JSONException e) {
        throw new GenericRuntimeException(e);
    }
    return err;
}
Also used : JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) GenericRuntimeException(com.openmeap.util.GenericRuntimeException)

Example 9 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class JSONArray method write.

/**
     * Write the contents of the JSONArray as JSON text to a writer.
     * For compactness, no whitespace is added.
     * <p>
     * Warning: This method assumes that the data structure is acyclical.
     *
     * @return The writer.
     * @throws JSONException
     */
public Writer write(Writer writer) throws JSONException {
    try {
        boolean b = false;
        int len = length();
        writer.write('[');
        for (int i = 0; i < len; i += 1) {
            if (b) {
                writer.write(',');
            }
            Object v = this.myArrayList.elementAt(i);
            if (v instanceof JSONObject) {
                ((JSONObject) v).write(writer);
            } else if (v instanceof JSONArray) {
                ((JSONArray) v).write(writer);
            } else {
                writer.write(JSONObject.valueToString(v));
            }
            b = true;
        }
        writer.write(']');
        return writer;
    } catch (IOException e) {
        throw new JSONException(e);
    }
}
Also used : JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JSONArray(com.openmeap.thirdparty.org.json.me.JSONArray) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) IOException(java.io.IOException)

Example 10 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class JSONObject method write.

/**
      * Write the contents of the JSONObject as JSON text to a writer.
      * For compactness, no whitespace is added.
      * <p>
      * Warning: This method assumes that the data structure is acyclical.
      *
      * @return The writer.
      * @throws JSONException
      */
public Writer write(Writer writer) throws JSONException {
    try {
        boolean b = false;
        Enumeration keys = keys();
        writer.write('{');
        while (keys.hasMoreElements()) {
            if (b) {
                writer.write(',');
            }
            Object k = keys.nextElement();
            writer.write(quote(k.toString()));
            writer.write(':');
            Object v = this.myHashMap.get(k);
            if (v instanceof JSONObject) {
                ((JSONObject) v).write(writer);
            } else if (v instanceof JSONArray) {
                ((JSONArray) v).write(writer);
            } else {
                writer.write(valueToString(v));
            }
            b = true;
        }
        writer.write('}');
        return writer;
    } catch (IOException e) {
        throw new JSONException(e);
    }
}
Also used : Enumeration(java.util.Enumeration) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JSONArray(com.openmeap.thirdparty.org.json.me.JSONArray) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) IOException(java.io.IOException)

Aggregations

JSONException (com.openmeap.thirdparty.org.json.me.JSONException)12 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)10 IOException (java.io.IOException)6 JSONObjectBuilder (com.openmeap.json.JSONObjectBuilder)4 JSONArray (com.openmeap.thirdparty.org.json.me.JSONArray)4 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)3 Enumeration (java.util.Enumeration)3 Hashtable (java.util.Hashtable)3 HasJSONProperties (com.openmeap.json.HasJSONProperties)2 Result (com.openmeap.protocol.dto.Result)2 Vector (java.util.Vector)2 ClusterNodeRequest (com.openmeap.cluster.dto.ClusterNodeRequest)1 HttpRequestException (com.openmeap.http.HttpRequestException)1 HttpResponse (com.openmeap.http.HttpResponse)1 Enum (com.openmeap.json.Enum)1 WebServiceException (com.openmeap.protocol.WebServiceException)1 ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)1 Error (com.openmeap.protocol.dto.Error)1 UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)1 JsError (com.openmeap.protocol.json.JsError)1