summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 07:27:31 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 07:27:31 +0000
commitae2a7812558a649861233ef945f5ea29953ba26a (patch)
treef219fab0fe406facdb8ef899209bbcebe487a759 /branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime
parent5d332e4c8b79c9374a48444a299ec3e3e4c25714 (diff)
TUSCANY-2968 - Setting JSON dataBinding on service interface contract
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@771605 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime')
-rw-r--r--branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java3
-rw-r--r--branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java43
2 files changed, 46 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
index 80277c0e95..756f90eca4 100644
--- a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
+++ b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatInterceptor.java
@@ -64,6 +64,9 @@ public class JSONRPCWireFormatInterceptor implements Interceptor {
// Configure JSON Databding
setDataBinding(runtimeWire.getTarget().getInterfaceContract().getInterface());
+ // Set default databinding to json
+ runtimeWire.getTarget().getInterfaceContract().getInterface().resetDataBinding(JSONDataBinding.NAME);
+
JSONObject jsonReq = (JSONObject) msg.getBody();
String method = null;
Object[] args = null;
diff --git a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
index 2d5d00eba8..8522d00f73 100644
--- a/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
+++ b/branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/jsonrpc/provider/JSONRPCWireFormatServiceProvider.java
@@ -19,13 +19,20 @@
package org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.provider;
+import java.util.List;
+
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.BindingRRB;
import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.binding.http.HTTPBinding;
import org.apache.tuscany.sca.binding.http.wireformat.jsonrpc.JSONRPCWireFormat;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Phase;
import org.apache.tuscany.sca.provider.WireFormatProvider;
@@ -52,6 +59,19 @@ public class JSONRPCWireFormatServiceProvider implements WireFormatProvider {
}
public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
+ InterfaceContract configuredContract = null;
+ //clone the service contract to avoid databinding issues
+ try {
+ configuredContract = (InterfaceContract) interfaceContract.clone();
+ } catch(CloneNotSupportedException e) {
+ configuredContract = interfaceContract;
+ }
+
+ setDataBinding(configuredContract.getInterface());
+
+ // Set default databinding to json
+ configuredContract.getInterface().resetDataBinding(JSONDataBinding.NAME);
+
return interfaceContract;
}
@@ -70,5 +90,28 @@ public class JSONRPCWireFormatServiceProvider implements WireFormatProvider {
public String getPhase() {
return Phase.SERVICE_BINDING_WIREFORMAT;
}
+
+
+ private void setDataBinding(Interface interfaze) {
+ List<Operation> operations = interfaze.getOperations();
+ for (Operation operation : operations) {
+ operation.setDataBinding(JSONDataBinding.NAME);
+ DataType<List<DataType>> inputType = operation.getInputType();
+ if (inputType != null) {
+ List<DataType> logical = inputType.getLogical();
+ for (DataType inArg : logical) {
+ if (!SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) {
+ inArg.setDataBinding(JSONDataBinding.NAME);
+ }
+ }
+ }
+ DataType outputType = operation.getOutputType();
+ if (outputType != null) {
+ if (!SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) {
+ outputType.setDataBinding(JSONDataBinding.NAME);
+ }
+ }
+ }
+ }
}