From 108d50f90c7437b414b7d980899e144d072e46d2 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 19 Jul 2010 06:12:16 +0000 Subject: Tweak the JSON-RPC binding to work without Java interfaces and recognize dynamic interfaces bound to the JSON databinding. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@965361 13f79535-47bb-0310-9956-ffa450edef68 --- .../jsonrpc/provider/JSONRPCServiceServlet.java | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'sandbox/sebastien/java/dynamic/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java') diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/sandbox/sebastien/java/dynamic/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java index 742a27e2ce..c24d90e2d0 100644 --- a/sandbox/sebastien/java/dynamic/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java +++ b/sandbox/sebastien/java/dynamic/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java @@ -37,6 +37,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.databinding.json.JSONDataBinding; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -99,6 +100,8 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { if (re.getCause() instanceof javax.security.auth.login.LoginException) { response.setHeader("WWW-Authenticate", "BASIC realm=\"" + "ldap-realm" + "\""); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } else { + re.printStackTrace(); } } finally { HttpSession session = request.getSession(false); @@ -299,7 +302,10 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { requestMessage.getHeaders().put("RequestMessage", request); - requestMessage.setBody(args); + if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) + requestMessage.setBody(new Object[]{jsonReq.toString()}); + else + requestMessage.setBody(args); //result = wire.invoke(jsonOperation, args); Message responseMessage = null; @@ -317,15 +323,20 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { if (!responseMessage.isFault()) { //successful execution of the invocation - try { + if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) { result = responseMessage.getBody(); - JSONObject jsonResponse = new JSONObject(); - 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("Unable to create JSON response", e); + return result.toString().getBytes("UTF-8"); + } else { + try { + result = responseMessage.getBody(); + JSONObject jsonResponse = new JSONObject(); + 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("Unable to create JSON response", e); + } } } else { //exception thrown while executing the invocation @@ -354,6 +365,8 @@ public class JSONRPCServiceServlet extends JSONRPCServlet { Operation result = null; for (Operation o : operations) { + if (o.isDynamic()) + return o; if (o.getName().equalsIgnoreCase(method)) { result = o; break; -- cgit v1.2.3