tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1180795 - in /tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src: main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/ main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/ test/java/bean/ test/java/echo/ test/java/o...
Date Mon, 10 Oct 2011 07:07:31 GMT
Author: rfeng
Date: Mon Oct 10 07:07:31 2011
New Revision: 1180795

URL: http://svn.apache.org/viewvc?rev=1180795&view=rev
Log:
Fix the invoker to serialize the objects to json

Added:
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpcRequest.java
      - copied, changed from r1180782, tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
Mon Oct 10 07:07:31 2011
@@ -19,8 +19,14 @@
 
 package org.apache.tuscany.sca.binding.jsonrpc.protocol;
 
+import java.io.OutputStream;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import org.apache.tuscany.sca.databinding.json.jackson.JacksonHelper;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -35,21 +41,14 @@ import org.json.JSONObject;
  * <li>id - The request id. This can be of any type. It is used to match the response
with the request that it is replying to.
  * </ul> 
  */
-public class JsonRpc10Request {
-    private final String method;
-    private final Object id;
-    private final Object[] params;
+public class JsonRpc10Request extends JsonRpcRequest {
 
     public JsonRpc10Request(Object id, String method, Object[] params) {
-        super();
-        this.id = id;
-        this.method = method;
-        this.params = params;
+        super(id, method, params);
     }
 
     public JsonRpc10Request(JSONObject req) throws JSONException {
-        super();
-
+        super(req);
         method = req.getString("method");
         id = req.opt("id");
         Object args = req.opt("params");
@@ -65,34 +64,25 @@ public class JsonRpc10Request {
         } else {
             throw new IllegalArgumentException("Invalid request: params is not a JSON array
- " + args);
         }
-
     }
 
-    public JSONObject toJSONObject() throws JSONException {
-        JSONObject req = new JSONObject();
-        req.put("id", id);
-        req.put("method", method);
-        if (params != null) {
-            JSONArray args = new JSONArray(Arrays.asList(params));
-            req.put("params", args);
-        }
-        return req;
-    }
+    public void write(OutputStream os) throws Exception {
+        // Construct a map to hold JSON-RPC request
+        final Map<String, Object> map = new HashMap<String, Object>();
+        map.put("id", id);
+        map.put("method", method);
 
-    public boolean isNotification() {
-        return id == null || id == JSONObject.NULL;
-    }
+        List<Object> parameters = null;
 
-    public String getMethod() {
-        return method;
-    }
+        if (params != null) {
+            parameters = Arrays.asList(params);
+        } else {
+            parameters = Collections.emptyList();
+        }
 
-    public Object getId() {
-        return id;
-    }
+        map.put("params", parameters);
+        JacksonHelper.MAPPER.writeValue(os, map);
 
-    public Object[] getParams() {
-        return params;
     }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
Mon Oct 10 07:07:31 2011
@@ -19,54 +19,35 @@
 
 package org.apache.tuscany.sca.binding.jsonrpc.protocol;
 
+import java.io.OutputStream;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.tuscany.sca.databinding.json.jackson.JacksonHelper;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-public class JsonRpc20Request {
-    private final String method;
-    private final Object id;
-    private final Object[] params;
-    private final Map<String, Object> mappedParams;
+public class JsonRpc20Request extends JsonRpcRequest {
+
+    protected Map<String, Object> mappedParams;
 
     public JsonRpc20Request(Object id, String method, Object[] params) {
-        super();
-        this.id = id;
-        this.method = method;
-        this.params = params;
+        super(id, method, params);
         this.mappedParams = null;
     }
 
     public JsonRpc20Request(Object id, String method, Map<String, Object> mappedParams)
{
-        super();
-        this.id = id;
-        this.method = method;
-        this.params = null;
+        super(id, method, null);
         this.mappedParams = mappedParams;
     }
 
-    public JSONObject toJSONObject() throws JSONException {
-        JSONObject req = new JSONObject();
-        req.put("jsonrpc", "2.0");
-        req.put("id", id);
-        req.put("method", method);
-        if (params != null) {
-            JSONArray args = new JSONArray(Arrays.asList(params));
-            req.put("params", args);
-        } else {
-            JSONObject args = new JSONObject(mappedParams);
-            req.put("params", args);
-        }
-        return req;
-    }
-
     public JsonRpc20Request(JSONObject req) throws JSONException {
-        super();
+        super(req);
         if (req.has("jsonrpc") && "2.0".equals(req.getString("jsonrpc"))) {
             method = req.getString("method");
             id = req.opt("id");
@@ -100,20 +81,30 @@ public class JsonRpc20Request {
         }
     }
 
-    public boolean isNotification() {
-        return id == null || id == JSONObject.NULL;
-    }
+    public void write(OutputStream os) throws Exception {
+        // Construct a map to hold JSON-RPC request
+        final Map<String, Object> jsonRequest = new HashMap<String, Object>();
+        jsonRequest.put("jsonrpc", "2.0");
+        jsonRequest.put("id", id);
+        jsonRequest.put("method", method);
 
-    public String getMethod() {
-        return method;
-    }
+        if (mappedParams != null) {
+            jsonRequest.put("params", mappedParams);
+        }
 
-    public Object getId() {
-        return id;
-    }
+        else {
+            List<Object> parameters = null;
+
+            if (params != null) {
+                parameters = Arrays.asList(params);
+            } else {
+                parameters = Collections.emptyList();
+            }
+
+            jsonRequest.put("params", parameters);
+        }
+        JacksonHelper.MAPPER.writeValue(os, jsonRequest);
 
-    public Object[] getParams() {
-        return params;
     }
 
     public Map<String, Object> getMappedParams() {

Copied: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpcRequest.java
(from r1180782, tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java)
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpcRequest.java?p2=tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpcRequest.java&p1=tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java&r1=1180782&r2=1180795&rev=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpcRequest.java
Mon Oct 10 07:07:31 2011
@@ -19,10 +19,11 @@
 
 package org.apache.tuscany.sca.binding.jsonrpc.protocol;
 
-import java.util.Arrays;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
 
-import org.json.JSONArray;
-import org.json.JSONException;
+import org.apache.tuscany.sca.databinding.json.jackson.JacksonHelper;
 import org.json.JSONObject;
 
 /**
@@ -35,49 +36,38 @@ import org.json.JSONObject;
  * <li>id - The request id. This can be of any type. It is used to match the response
with the request that it is replying to.
  * </ul> 
  */
-public class JsonRpc10Request {
-    private final String method;
-    private final Object id;
-    private final Object[] params;
+public abstract class JsonRpcRequest {
+    protected String method;
+    protected Object id;
+    protected Object[] params;
 
-    public JsonRpc10Request(Object id, String method, Object[] params) {
+    protected JSONObject jsonObject;
+
+    public JsonRpcRequest(Object id, String method, Object[] params) {
         super();
         this.id = id;
         this.method = method;
         this.params = params;
     }
 
-    public JsonRpc10Request(JSONObject req) throws JSONException {
+    protected JsonRpcRequest(JSONObject jsonObject) {
         super();
+        this.jsonObject = jsonObject;
+    }
 
-        method = req.getString("method");
-        id = req.opt("id");
-        Object args = req.opt("params");
-        if (args instanceof JSONArray) {
-            // Positional parameters
-            JSONArray array = (JSONArray)args;
-            params = new Object[array.length()];
-            for (int i = 0; i < params.length; i++) {
-                params[i] = array.get(i);
-            }
-        } else if (args == null) {
-            params = new Object[0];
+    public JSONObject toJSONObject() throws Exception {
+        if (jsonObject != null) {
+            return jsonObject;
         } else {
-            throw new IllegalArgumentException("Invalid request: params is not a JSON array
- " + args);
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            write(bos);
+            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+            jsonObject = JacksonHelper.MAPPER.readValue(bis, JSONObject.class);
         }
-
+        return jsonObject;
     }
 
-    public JSONObject toJSONObject() throws JSONException {
-        JSONObject req = new JSONObject();
-        req.put("id", id);
-        req.put("method", method);
-        if (params != null) {
-            JSONArray args = new JSONArray(Arrays.asList(params));
-            req.put("params", args);
-        }
-        return req;
-    }
+    public abstract void write(OutputStream os) throws Exception;
 
     public boolean isNotification() {
         return id == null || id == JSONObject.NULL;

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcInvoker.java
Mon Oct 10 07:07:31 2011
@@ -40,6 +40,7 @@ import org.apache.tuscany.sca.assembly.E
 import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding;
 import org.apache.tuscany.sca.binding.jsonrpc.protocol.JsonRpc10Request;
 import org.apache.tuscany.sca.binding.jsonrpc.protocol.JsonRpc20Request;
+import org.apache.tuscany.sca.binding.jsonrpc.protocol.JsonRpcRequest;
 import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
 import org.apache.tuscany.sca.databinding.json.jackson.JacksonHelper;
 import org.apache.tuscany.sca.interfacedef.DataType;
@@ -92,21 +93,23 @@ public class JsonRpcInvoker implements I
                     params = (Object[])args;
                 }
 
-                JSONObject jsonReq = null;
+                JsonRpcRequest req = null;
                 if (JSONRPCBinding.VERSION_20.equals(((JSONRPCBinding)endpointReference.getBinding()).getVersion()))
{
-                    JsonRpc20Request req = new JsonRpc20Request(requestId, msg.getOperation().getName(),
params);
-                    jsonReq = req.toJSONObject();
+                    req = new JsonRpc20Request(requestId, msg.getOperation().getName(), params);
                 } else {
-                    JsonRpc10Request req = new JsonRpc10Request(requestId, msg.getOperation().getName(),
params);
-                    jsonReq = req.toJSONObject();
+                    req = new JsonRpc10Request(requestId, msg.getOperation().getName(), params);
                 }
-                final String json = jsonReq.toString(4);
+                final JsonRpcRequest json = req;
 
                 // Create content producer so that we can stream the json result out
                 ContentProducer cp = new ContentProducer() {
                     public void writeTo(OutputStream outstream) throws IOException {
                         // mapper.writeValue(outstream, req.toJSONObject().toString());
-                        outstream.write(json.getBytes("UTF-8"));
+                        try {
+                            json.write(outstream);
+                        } catch (Exception e) {
+                            throw new IOException(e);
+                        }
                     }
                 };
                 entity = new EntityTemplate(cp);

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
Mon Oct 10 07:07:31 2011
@@ -18,11 +18,14 @@
  */
 package bean;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class TestBean {
     private String testString;
-    private String[] testStringArray;
+    // private String[] testStringArray; // Jackson cannot deserilize String[]
+    private List<String> testStringArray = new ArrayList<String>();
     private int testInt;
-    
 
     public String getTestString() {
         return testString;
@@ -32,14 +35,14 @@ public class TestBean {
         this.testString = testString;
     }
 
-    public String[] getTestStringArray() {
-    	return testStringArray;
+    public List<String> getTestStringArray() {
+        return testStringArray;
     }
     
-    public void setStringArray(String[] stringArray) {
-    	this.testStringArray = stringArray;
+    public void setStringArray(List<String> stringArray) {
+        this.testStringArray = stringArray;
     }
-    
+
     public int getTestInt() {
         return testInt;
     }
@@ -48,4 +51,54 @@ public class TestBean {
         this.testInt = testInt;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + testInt;
+        result = prime * result + ((testString == null) ? 0 : testString.hashCode());
+        result = prime * result + ((testStringArray == null) ? 0 : testStringArray.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        TestBean other = (TestBean)obj;
+        if (testInt != other.testInt) {
+            return false;
+        }
+        if (testString == null) {
+            if (other.testString != null) {
+                return false;
+            }
+        } else if (!testString.equals(other.testString)) {
+            return false;
+        }
+        if (testStringArray == null) {
+            if (other.testStringArray != null) {
+                return false;
+            }
+        } else if (!testStringArray.equals(other.testStringArray)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("TestBean [testString=").append(testString).append(", testStringArray=").append(testStringArray)
+            .append(", testInt=").append(testInt).append("]");
+        return builder.toString();
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
Mon Oct 10 07:07:31 2011
@@ -27,71 +27,76 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.oasisopen.sca.annotation.AllowsPassByReference;
 import org.oasisopen.sca.annotation.Reference;
 
 import bean.TestBean;
 
+@AllowsPassByReference
 public class EchoClientImpl implements Echo {
     @Reference
+    @AllowsPassByReference
     protected Echo echoReference;
 
     public String echo(String msg) {
         return echoReference.echo(msg);
     }
-    
+
     public void echoVoid() {
         echoReference.echoVoid();
     }
 
-    public int[] echoArrayInt(int[] intArray) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public void echoRuntimeException() throws RuntimeException {
+        echoReference.echoRuntimeException();
     }
 
-    public String[] echoArrayString(String[] stringArray) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public void echoBusinessException() throws EchoBusinessException {
+        echoReference.echoBusinessException();
     }
 
-    public TestBean echoBean(TestBean testBean) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public int echoInt(int param) {
+        return echoReference.echoInt(param);
     }
 
-    public boolean echoBoolean(boolean param) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public double echoDouble(double param) {
+        return echoReference.echoDouble(param);
     }
 
-    public void echoBusinessException() throws EchoBusinessException {
-        echoReference.echoBusinessException();
+    public boolean echoBoolean(boolean param) {
+        return echoReference.echoBoolean(param);
     }
 
-    public int echoInt(int param) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public Map echoMap(HashMap map) {
+        return echoReference.echoMap(map);
     }
 
-    public double echoDouble(double param) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public TestBean echoBean(TestBean testBean) {
+        return echoReference.echoBean(testBean);
     }
 
     public List echoList(ArrayList list) {
-        throw new UnsupportedOperationException("UNsupported !");
+        return echoReference.echoList(list);
     }
 
-    public Map echoMap(HashMap map) {
-        throw new UnsupportedOperationException("UNsupported !");
+    public String[] echoArrayString(String[] stringArray) {
+        return echoReference.echoArrayString(stringArray);
     }
 
-    public void echoRuntimeException() throws RuntimeException {
-        echoReference.echoRuntimeException();
+    public int[] echoArrayInt(int[] intArray) {
+        return echoReference.echoArrayInt(intArray);
     }
 
     public Set echoSet(HashSet set) {
-        throw new UnsupportedOperationException("UNsupported !");
+        return echoReference.echoSet(set);
     }
 
     public void get\u03a9\u03bb\u03c0() {
-        throw new UnsupportedOperationException("UNsupported !");
+        echoReference.get\u03a9\u03bb\u03c0();
     }
 
     public BigDecimal echoBigDecimal(BigDecimal param) {
-        throw new UnsupportedOperationException("UNsupported !");
+        return echoReference.echoBigDecimal(param);
     }
+
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
Mon Oct 10 07:07:31 2011
@@ -27,6 +27,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.oasisopen.sca.annotation.AllowsPassByReference;
+
 import bean.TestBean;
 
 /**
@@ -34,6 +36,7 @@ import bean.TestBean;
  *
  * @version $Rev$ $Date$
  */
+@AllowsPassByReference
 public class EchoComponentImpl implements Echo {
 
     public String echo(String msg) {
@@ -80,6 +83,7 @@ public class EchoComponentImpl implement
         TestBean testBean = new TestBean();
         testBean.setTestString(testBean1.getTestString());
         testBean.setTestInt(testBean1.getTestInt());
+        testBean.setStringArray(testBean1.getTestStringArray());
         return testBean;
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java?rev=1180795&r1=1180794&r2=1180795&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
Mon Oct 10 07:07:31 2011
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.sca.binding.jsonrpc;
 
+import java.util.Arrays;
+
 import junit.framework.Assert;
 
 import org.apache.tuscany.sca.node.Contribution;
@@ -28,6 +30,7 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import bean.TestBean;
 import echo.Echo;
 
 public class JSONRPCReferenceTestCase {
@@ -38,13 +41,17 @@ public class JSONRPCReferenceTestCase {
     public static void setUp() throws Exception {
         try {
             String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class);
-            nodeServer = NodeFactory.newInstance().createNode("JSONRPCBinding.composite",
new Contribution("testServer", contribution));
+            nodeServer =
+                NodeFactory.newInstance().createNode("JSONRPCBinding.composite",
+                                                     new Contribution("testServer", contribution));
             nodeServer.start();
-            
+
             contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class);
-            node = NodeFactory.newInstance().createNode("JSONRPCReference.composite", new
Contribution("testClient", contribution));
+            node =
+                NodeFactory.newInstance().createNode("JSONRPCReference.composite",
+                                                     new Contribution("testClient", contribution));
             node.start();
-            
+
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -55,20 +62,31 @@ public class JSONRPCReferenceTestCase {
         nodeServer.stop();
         node.stop();
     }
-    
+
     @Test
     public void testInvokeReference() throws Exception {
-        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference");
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
         String result = echoComponent.echo("ABC");
         Assert.assertEquals("echo: ABC", result);
     }
 
     @Test
+    public void testInvokeBeanReference() throws Exception {
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
+        TestBean bean = new TestBean();
+        bean.setTestInt(1);
+        bean.setTestString("123");
+        bean.setStringArray(Arrays.asList("A", "B"));
+        TestBean result = echoComponent.echoBean(bean);
+        Assert.assertEquals(bean, result);
+    }
+
+    @Test
     public void testInvokeReferenceVoidOperation() throws Exception {
-        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference");
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
         echoComponent.echoVoid();
     }
-    
+
     @Test(expected = Exception.class)
     public void testInvokeReferenceException() throws Exception {
         Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
@@ -79,20 +97,20 @@ public class JSONRPCReferenceTestCase {
             throw e;
         }
     }
-    
+
     @Test
     public void testInvokeReference20() throws Exception {
-        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20");
         String result = echoComponent.echo("ABC");
         Assert.assertEquals("echo: ABC", result);
     }
 
     @Test
     public void testInvokeReferenceVoidOperation20() throws Exception {
-        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20");
         echoComponent.echoVoid();
     }
-    
+
     @Test(expected = Exception.class)
     public void testInvokeReferenceException20() throws Exception {
         Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20");



Mime
View raw message