diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-http-new-jsonrpc-runtime/src/main/java/org')
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); + } + } + } + } } |