summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk')
-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
-rw-r--r--sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java8
7 files changed, 44 insertions, 5 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
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java
index f405d2b687..d543d0554a 100644
--- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java
+++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/Object2JSON.java
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.databinding.json.jackson;
+import java.math.BigDecimal;
+
import org.apache.tuscany.sca.databinding.PullTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
import org.apache.tuscany.sca.databinding.TransformationException;
@@ -57,8 +59,12 @@ public class Object2JSON implements PullTransformer<Object, Object> {
return source;
}
String value = mapper.writeValueAsString(source);
- if (targetType == String.class || targetType == Object.class || targetType.isPrimitive()) {
+ if (targetType == String.class ||
+ targetType == Object.class ||
+ targetType.isPrimitive()) {
return value;
+ } else if (targetType == BigDecimal.class){
+ return value.toString();
} else if (JsonNode.class.isAssignableFrom(targetType)) {
return JacksonHelper.createJsonParser(value).readValueAsTree();
}