summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java34
1 files changed, 33 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java
index 1a37104d6b..7facd2588a 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Response.java
@@ -37,9 +37,17 @@ import org.json.JSONObject;
* </ul>
*/
public class JsonRpc10Response {
+ public static final int REMOTE_EXCEPTION = 490;
private Object id;
private Object result;
private Object error;
+
+ private volatile JSONObject response;
+
+ public JsonRpc10Response(JSONObject response) {
+ super();
+ this.response = response;
+ }
public JsonRpc10Response(Object id, Object result, Object error) {
super();
@@ -51,8 +59,32 @@ public class JsonRpc10Response {
}
}
+ public JsonRpc10Response(Object id, Throwable t) {
+ super();
+ this.id = id;
+ this.result = null;
+ try {
+ JSONObject obj = new JSONObject();
+ // obj.put("msg", t.getMessage());
+ obj.put("code", REMOTE_EXCEPTION);
+ obj.put("message", t.getMessage());
+ JSONObject exception = new JSONObject();
+ exception.put("class", t.getClass().getName());
+ exception.put("message", t.getMessage());
+ exception.put("stackTrace", JsonRpc20Error.stackTrace(t));
+ obj.put("data", exception);
+ this.error = obj;
+ } catch (JSONException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ }
+
public JSONObject toJSONObject() throws JSONException {
- JSONObject response = new JSONObject();
+ if (response != null) {
+ return response;
+ }
+ response = new JSONObject();
response.put("id", id);
if (result != null) {
response.put("result", result);