summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/binding-jsonrpc-runtime/src/main/java
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-07-17 00:36:25 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-07-17 00:36:25 +0000
commitd87b7a5e7430ab946c851208e45ddbf03330c98f (patch)
treea25d04d5dd5ba93de5b138164bb63a4528f07565 /java/sca/modules/binding-jsonrpc-runtime/src/main/java
parent3f56676b3bf9248726941f88018bf7b38db5e895 (diff)
TUSCANY-1961 - Properly reporting business and runtime exceptions to clients using jsonRPC binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@677479 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-jsonrpc-runtime/src/main/java')
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java31
1 files changed, 14 insertions, 17 deletions
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
index da4461c1cd..c0d0415f91 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
@@ -42,6 +42,7 @@ import org.json.JSONObject;
import org.osoa.sca.ServiceRuntimeException;
import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import com.metaparadigm.jsonrpc.JSONRPCResult;
import com.metaparadigm.jsonrpc.JSONRPCServlet;
/**
@@ -166,7 +167,6 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
response.setContentType("text/plain;charset=utf-8");
OutputStream out = response.getOutputStream();
byte[] bout = smd.getBytes("UTF-8");
-
out.write(bout);
out.flush();
out.close();
@@ -232,30 +232,27 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
RuntimeWire wire = componentService.getRuntimeWire(binding, serviceContract);
Operation jsonOperation = findOperation(method);
Object result = null;
- JSONObject jsonResponse = new JSONObject();
+
try {
- result = wire.invoke(jsonOperation, args);
- try {
+ JSONObject jsonResponse = new JSONObject();
+ result = wire.invoke(jsonOperation, args);
+
+ try {
jsonResponse.put("result", result);
jsonResponse.putOpt("id", id);
+ //get response to send to client
+ return jsonResponse.toString().getBytes("UTF-8");
} catch (Exception e) {
- throw new ServiceRuntimeException(e);
+ throw new ServiceRuntimeException("Unable to create JSON response", e);
}
} catch (InvocationTargetException e) {
- try {
- jsonResponse.put("error", e.getCause());
- jsonResponse.putOpt("id", id);
- } catch (Exception e1) {
- throw new ServiceRuntimeException(e);
- }
+ JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
+ return errorResult.toString().getBytes("UTF-8");
} catch(RuntimeException e) {
- e.printStackTrace();
- throw e;
+ JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
+ return errorResult.toString().getBytes("UTF-8");
}
-
- //get response to send to client
- return jsonResponse.toString().getBytes("UTF-8");
- }
+ }
/**
* Find the operation from the component service contract