From b5e7ca05ae7d544f60f91ed2972f8cdd9c89036a Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 6 Oct 2009 04:35:07 +0000 Subject: 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 --- .../provider/JSONRPCReferenceBindingProvider.java | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'java/sca/modules/binding-jsonrpc-runtime/src/main') 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 operations = interfaze.getOperations(); + for (Operation operation : operations) { + operation.setDataBinding(JSONDataBinding.NAME); + DataType> inputType = operation.getInputType(); + if (inputType != null) { + List 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); + } + } + } + } } -- cgit v1.2.3