diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-19 06:57:43 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-19 06:57:43 +0000 |
commit | 2ee32aca8bbc75f468ef8a466a937ec4296e5660 (patch) | |
tree | 445d9bf6235b42712a60407b0f17d082edd118f4 /branches | |
parent | 5b7b979193bfeb3d195dc91feab74eb75126da55 (diff) |
Properly handling business/runtime exception with new invocation method
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java index 85bae9085d..f260fe4a38 100644 --- a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java +++ b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; import java.util.List; import javax.servlet.ServletConfig; @@ -252,9 +251,8 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { //result = wire.invoke(jsonOperation, args); Message responseMessage = wire.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage); - if (responseMessage.isFault()) { - throw new RuntimeException((Throwable)responseMessage.getBody()); - } else { + if (!responseMessage.isFault()) { + //successful execution of the invocation try { result = responseMessage.getBody(); JSONObject jsonResponse = new JSONObject(); @@ -265,14 +263,15 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { } catch (Exception e) { throw new ServiceRuntimeException("Unable to create JSON response", e); } + } else { + //exception thrown while executing the invocation + Throwable exception = (Throwable)responseMessage.getBody(); + JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception ); + return errorResult.toString().getBytes("UTF-8"); } - - - }/* catch (InvocationTargetException e) { - JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() ); - return errorResult.toString().getBytes("UTF-8"); - }*/ catch(RuntimeException e) { - JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause()); + } catch(RuntimeException e) { + //some other exception + JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e); return errorResult.toString().getBytes("UTF-8"); } } |