summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-06 04:35:07 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-06 04:35:07 +0000
commitb5e7ca05ae7d544f60f91ed2972f8cdd9c89036a (patch)
tree3c3fc1a1cb68ca1a2ff5f80c73d9500e6bef1f05
parent49e4bbe92962788eb4b3bcf05ad87440c71a8085 (diff)
Adding code to set JSON Databinding on JSON-RPC reference contract
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@822119 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java41
1 files changed, 40 insertions, 1 deletions
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
index 3ed27df3be..b0da1ff5cf 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCReferenceBindingProvider.java
@@ -19,10 +19,16 @@
package org.apache.tuscany.sca.binding.jsonrpc.provider;
+import java.util.List;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.tuscany.sca.assembly.EndpointReference;
+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.Invoker;
@@ -38,6 +44,8 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider
private EndpointReference endpointReference;
private RuntimeComponentReference reference;
+ private InterfaceContract referenceContract;
+
private HttpClient httpClient;
public JSONRPCReferenceBindingProvider(EndpointReference endpointReference) {
@@ -45,6 +53,15 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider
this.endpointReference = endpointReference;
this.reference = (RuntimeComponentReference) endpointReference.getReference();
+ //clone the service contract to avoid databinding issues
+ try {
+ this.referenceContract = (InterfaceContract)reference.getInterfaceContract().clone();
+ } catch(CloneNotSupportedException e) {
+ this.referenceContract = reference.getInterfaceContract();
+ }
+
+ setDataBinding(referenceContract.getInterface());
+
// Create an HTTP client
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(10);
@@ -53,7 +70,7 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider
}
public InterfaceContract getBindingInterfaceContract() {
- return reference.getInterfaceContract();
+ return referenceContract;
}
public Invoker createInvoker(Operation operation) {
@@ -71,5 +88,27 @@ public class JSONRPCReferenceBindingProvider implements ReferenceBindingProvider
public boolean supportsOneWayInvocation() {
return false;
}
+
+ 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);
+ }
+ }
+ }
+ }
}