summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-09-08 11:30:41 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-09-08 11:30:41 +0000
commit86f8397dbc7f8c5da94ef4f06019420953100c5c (patch)
tree4a0f5a5aeca89fd768cbd1f70939d0606e510d96 /sca-java-2.x/trunk/modules/binding-jsonrpc-runtime
parent5a7306e0e7873abb952cf38ef4f6bb93d5e6409a (diff)
TUSCANY-3668 - support BigDecimal in JSON format and JSONRPC binding. BigDecimal is detected in an interface as a Java simple type but you have to manage it explicitly when converting from primitive types.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@994995 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jsonrpc-runtime')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCDatabindingHelper.java7
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java4
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java2
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java5
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java6
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java17
6 files changed, 37 insertions, 4 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCDatabindingHelper.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCDatabindingHelper.java
index 3cdcb32830..f9b37f30b2 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCDatabindingHelper.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCDatabindingHelper.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.binding.jsonrpc.provider;
+import java.math.BigDecimal;
import java.util.List;
import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
@@ -45,14 +46,16 @@ public class JSONRPCDatabindingHelper {
if (inputType != null) {
List<DataType> logical = inputType.getLogical();
for (DataType inArg : logical) {
- if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) {
+ if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding()) ||
+ inArg.getPhysical() == BigDecimal.class) {
inArg.setDataBinding(JSONDataBinding.NAME);
}
}
}
DataType outputType = operation.getOutputType();
if (outputType != null) {
- if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) {
+ if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding()) ||
+ outputType.getPhysical() == BigDecimal.class ) {
outputType.setDataBinding(JSONDataBinding.NAME);
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
index 10e9368936..39881ce68d 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding;
+import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
import org.apache.tuscany.sca.host.http.ServletHost;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
@@ -80,7 +81,8 @@ public class JSONRPCServiceBindingProvider implements ServiceBindingProvider {
public void start() {
// Set default databinding to json
- // serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME);
+ // replaced by JSONRPCDatabindingHelper.setDataBinding(serviceContract.getInterface()); above
+ //serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME);
// Determine the service business interface
Class<?> serviceInterface = getTargetJavaClass(serviceContract.getInterface());
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java
index 322008de1f..91efccc4e5 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java
@@ -18,6 +18,7 @@
*/
package echo;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -61,4 +62,5 @@ public interface Echo {
void get\u03a9\u03bb\u03c0();
+ BigDecimal echoBigDecimal(BigDecimal param);
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
index f76ec74b16..4163f86313 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
@@ -19,6 +19,7 @@
package echo;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -81,5 +82,9 @@ public class EchoClientImpl implements Echo {
public void get\u03a9\u03bb\u03c0() {
throw new UnsupportedOperationException("UNsupported !");
}
+
+ public BigDecimal echoBigDecimal(BigDecimal param) {
+ throw new UnsupportedOperationException("UNsupported !");
+ }
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
index 08ccb6e6d5..0a34404281 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
@@ -18,6 +18,7 @@
*/
package echo;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -96,8 +97,11 @@ public class EchoComponentImpl implements Echo {
}
-
public void get\u03a9\u03bb\u03c0() {
}
+
+ public BigDecimal echoBigDecimal(BigDecimal param) {
+ return param;
+ }
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
index 0fd622d29b..d09bce6365 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
@@ -199,4 +199,21 @@ public class JSONRPCDataTypeTestCase {
Assert.assertEquals("red", jsonResp.getJSONArray("result").get(0));
}
+
+ @Test
+ public void testBigDecimal() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoBigDecimal\", \"params\": [\"12345.67\"], \"id\": 4}");
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ JSONObject jsonResp = new JSONObject(response.getText());
+
+ Assert.assertEquals("12345.67", jsonResp.get("result"));
+ }
} \ No newline at end of file