Permalink
Browse files

TUSCANY-3894. Refactor local sca binding so that the exact details of…

… the data copy can be plugged in via the BindingProviderFactory extension point, while keeping a core, base portion of the binding to do things like calculate whether to do the pass-by-reference optimization and establish other aspects of the invoker/interceptor chain. The data handling is factored into a BindingSCATransformer class. The default impl will continue to use MediatorImpl.copyXXX methods, and will use Java-serialization first then XML/JAXB-serialization. The second impl included uses XML serialization and calculates a WSDL interfaceContract.

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk@1151632 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 8508a39 commit 952f46c5c70da58ff8317fd86b554471b1f2351d Scott Kurz committed Jul 27, 2011
@@ -19,9 +19,11 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.core.invocation;version="2.0.0",
org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.databinding.xml;version="2.0.0",
org.apache.tuscany.sca.definitions;version="2.0.0",
org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.wsdl;version="2.0.0",
org.apache.tuscany.sca.invocation;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.policy;version="2.0.0",
@@ -46,6 +46,13 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws-wsdlgen</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-core-spi</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
@@ -22,56 +22,104 @@
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.binding.local.LocalSCABindingInvoker;
+import org.apache.tuscany.sca.binding.sca.transform.BindingSCATransformer;
+import org.apache.tuscany.sca.binding.sca.transform.DefaultBindingSCATransformer;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
import org.apache.tuscany.sca.interfacedef.Compatibility;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
import org.apache.tuscany.sca.invocation.InvocationChain;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.provider.EndpointReferenceAsyncProvider;
import org.apache.tuscany.sca.provider.SCABindingMapper;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.oasisopen.sca.ServiceRuntimeException;
import org.oasisopen.sca.ServiceUnavailableException;
-public class LocalSCAReferenceBindingProvider implements EndpointReferenceAsyncProvider {
+public class DefaultLocalSCAReferenceBindingProvider implements EndpointReferenceAsyncProvider {
private RuntimeEndpointReference endpointReference;
- private InterfaceContractMapper interfaceContractMapper;
- private ExtensionPointRegistry extensionPoints;
- private Mediator mediator;
+ protected InterfaceContractMapper interfaceContractMapper;
+ protected ExtensionPointRegistry extensionPoints;
+ protected Mediator mediator;
+ protected InterfaceContract wsdlBindingInterfaceContract;
- public LocalSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpointReference endpointReference, SCABindingMapper mapper) {
+ public DefaultLocalSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpointReference endpointReference, SCABindingMapper mapper) {
this.extensionPoints = extensionPoints;
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
this.mediator = utilities.getUtility(Mediator.class);
this.endpointReference = endpointReference;
}
+
+ protected String getDataBinding() {
+ return DOMDataBinding.NAME;
+ }
+
+ private InterfaceContract getWSDLInterfaceContract(InterfaceContract interfaceContract) {
+ InterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)endpointReference.getGeneratedWSDLContract(interfaceContract);
+
+ // Validation may be unnecessary. This check may already be guaranteed at this point, not sure.
+ Endpoint target = endpointReference.getTargetEndpoint();
+ InterfaceContract targetInterfaceContract = target.getComponentServiceInterfaceContract();
+ try {
+ interfaceContractMapper.checkCompatibility(wsdlInterfaceContract, targetInterfaceContract,
+ Compatibility.SUBSET, true, false);
+ } catch (IncompatibleInterfaceContractException exc) {
+ throw new ServiceRuntimeException(exc);
+ }
+
+ String dataBinding = getDataBinding();
+
+ // Clone
+ try {
+ wsdlInterfaceContract = (WSDLInterfaceContract)wsdlInterfaceContract.clone();
+ } catch (CloneNotSupportedException exc) {
+ throw new ServiceRuntimeException(exc);
+ }
+
+ if (wsdlInterfaceContract.getInterface() != null) {
+ wsdlInterfaceContract.getInterface().resetDataBinding(dataBinding);
+ }
+ if (wsdlInterfaceContract.getCallbackInterface() != null) {
+ wsdlInterfaceContract.getCallbackInterface().resetDataBinding(dataBinding);
+ }
+ return wsdlInterfaceContract;
+
+ }
@Override
public InterfaceContract getBindingInterfaceContract() {
- RuntimeEndpoint endpoint = (RuntimeEndpoint) endpointReference.getTargetEndpoint();
- if (endpoint != null) {
- return endpoint.getComponentTypeServiceInterfaceContract();
- } else {
- return endpointReference.getComponentTypeReferenceInterfaceContract();
+ InterfaceContract componentTypeRefIC = endpointReference.getComponentTypeReferenceInterfaceContract();
+ if (componentTypeRefIC.getInterface().isRemotable()) {
+ this.wsdlBindingInterfaceContract = getWSDLInterfaceContract(componentTypeRefIC);
}
+
+ // Since we want to disable DataTransformationInterceptor and handle copy in the binding
+ return componentTypeRefIC;
}
+
+
@Override
public Invoker createInvoker(Operation operation) {
Invoker result = null;
-
+ BindingSCATransformer bindingTransformer = null;
+
Endpoint target = endpointReference.getTargetEndpoint();
if (target != null) {
RuntimeComponentService service = (RuntimeComponentService) target.getService();
if (service != null) { // not a callback wire
+
InvocationChain chain = ((RuntimeEndpoint) target).getInvocationChain(operation);
boolean passByValue = false;
@@ -90,15 +138,19 @@ public Invoker createInvoker(Operation operation) {
passByValue = false;
} else if (interfaceContractMapper.isCompatibleWithoutUnwrapByValue(operation, targetOp, Compatibility.SUBSET)) {
passByValue = true;
+ } else {
+ throw new IllegalStateException();
}
+ bindingTransformer = getBindingTransformer(operation, chain);
}
+
// it turns out that the chain source and target operations are
// the same, and are the operation
// from the target, not sure if thats by design or a bug. The
// SCA binding invoker needs to know
// the source and target class loaders so pass in the real
// source operation in the constructor
- result = chain == null ? null : new LocalSCABindingInvoker(chain, operation, mediator, passByValue, endpointReference, extensionPoints);
+ result = chain == null ? null : new LocalSCABindingInvoker(chain, operation, passByValue, endpointReference, extensionPoints, bindingTransformer);
}
}
@@ -109,6 +161,10 @@ public Invoker createInvoker(Operation operation) {
return result;
}
+
+ protected BindingSCATransformer getBindingTransformer(Operation operation, InvocationChain chain) {
+ return new DefaultBindingSCATransformer(mediator, operation, chain);
+ }
@Override
public boolean supportsOneWayInvocation() {
@@ -143,4 +199,6 @@ public void stop() {
public void setEndpointReference(RuntimeEndpointReference endpointReference){
this.endpointReference = endpointReference;
}
+
+
}
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.binding.local;
+import org.apache.tuscany.sca.binding.sca.transform.BindingSCATransformer;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker;
@@ -41,28 +42,26 @@
*/
public class LocalSCABindingInvoker extends InterceptorAsyncImpl {
private InvocationChain chain;
- private Mediator mediator;
- private Operation sourceOperation;
- private Operation targetOperation;
private boolean passByValue;
private RuntimeEndpointReference epr;
private RuntimeEndpoint ep;
private ExtensionPointRegistry registry;
+ private BindingSCATransformer bindingSCATransformer;
/**
* Construct a SCABindingInvoker that delegates to the service invocation chain
*/
- public LocalSCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator,
- boolean passByValue, RuntimeEndpointReference epr, ExtensionPointRegistry registry) {
+ public LocalSCABindingInvoker(InvocationChain chain, Operation sourceOperation,
+ boolean passByValue, RuntimeEndpointReference epr, ExtensionPointRegistry registry,
+ BindingSCATransformer bindingSCATransformer) {
super();
this.chain = chain;
- this.mediator = mediator;
- this.sourceOperation = sourceOperation;
- this.targetOperation = chain.getTargetOperation();
+
this.passByValue = passByValue;
this.epr = epr;
this.ep = (RuntimeEndpoint)epr.getTargetEndpoint();
this.registry = registry;
+ this.bindingSCATransformer = bindingSCATransformer;
}
/**
@@ -78,90 +77,91 @@ public Invoker getNext() {
public void setNext(Invoker next) {
// NOOP
}
-
+
public Message processRequest(Message msg){
if (passByValue) {
- msg.setBody(mediator.copyInput(msg.getBody(), sourceOperation, targetOperation));
+ Object transformedBody = bindingSCATransformer.transformInput(msg.getBody());
+ msg.setBody(transformedBody);
} // end if
-
+
ep.getInvocationChains();
if ( !ep.getCallbackEndpointReferences().isEmpty() ) {
RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) ep.getCallbackEndpointReferences().get(0);
// Place a link to the callback EPR into the message headers...
msg.getHeaders().put("ASYNC_CALLBACK", asyncEPR );
} // end if
-
+
if( ep.isAsyncInvocation() ) {
// Get the message ID
String msgID = (String)msg.getHeaders().get("MESSAGE_ID");
-
+
String operationName = msg.getOperation().getName();
-
+
// Create a response invoker and add it to the message headers
AsyncResponseInvoker<RuntimeEndpointReference> respInvoker =
- new AsyncResponseInvoker<RuntimeEndpointReference>(ep, null, epr, msgID, operationName, getMessageFactory());
+ new AsyncResponseInvoker<RuntimeEndpointReference>(ep, null, epr, msgID, operationName, getMessageFactory());
respInvoker.setBindingType("SCA_LOCAL");
msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker);
} // end if
-
+
return msg;
} // end method processRequest
-
+
/**
* Regular (sync) processing of response message
*/
public Message processResponse(Message msg){
if (passByValue) {
// Note source and target operation swapped so result is in source class loader
if (msg.isFault()) {
- msg.setFaultBody(mediator.copyFault(msg.getBody(), sourceOperation, targetOperation));
+ Object transformedFault = bindingSCATransformer.transformFault(msg.getBody());
+ msg.setFaultBody(transformedFault);
} else {
- if (sourceOperation.getOutputType() != null) {
- msg.setBody(mediator.copyOutput(msg.getBody(), sourceOperation, targetOperation));
- } // end if
+ Object transformedOutput = bindingSCATransformer.transformOutput(msg.getBody());
+ msg.setBody(transformedOutput);
} // end if
} // end if
-
+
return msg;
} // end method processResponse
-
+
public void invokeAsyncRequest(Message msg) throws Throwable {
- try{
- msg = processRequest(msg);
- InvokerAsyncRequest theNext = (InvokerAsyncRequest)getNext();
- if( theNext != null ) theNext.invokeAsyncRequest(msg);
- postProcessRequest(msg);
- } catch (Throwable e) {
- postProcessRequest(msg, e);
- } // end try
+ try{
+ msg = processRequest(msg);
+ InvokerAsyncRequest theNext = (InvokerAsyncRequest)getNext();
+ if( theNext != null ) theNext.invokeAsyncRequest(msg);
+ postProcessRequest(msg);
+ } catch (Throwable e) {
+ postProcessRequest(msg, e);
+ } // end try
} // end method invokeAsyncRequest
-
+
public void invokeAsyncResponse(Message msg) {
msg = processResponse(msg);
-
+
// Handle async response Relates_To message ID value
@SuppressWarnings("unchecked")
- AsyncResponseInvoker<RuntimeEndpointReference> respInvoker =
- (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
+ AsyncResponseInvoker<RuntimeEndpointReference> respInvoker =
+ (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
// TODO - this deals with the Local case only - not distributed
if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) {
- RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress();
- msg.setFrom(responseEPR);
- String msgID = respInvoker.getRelatesToMsgID();
- msg.getHeaders().put("RELATES_TO", msgID);
+ RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress();
+ msg.setFrom(responseEPR);
+ String msgID = respInvoker.getRelatesToMsgID();
+ msg.getHeaders().put("RELATES_TO", msgID);
} // end if
-
+
InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious();
if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg);
} // end method invokeAsyncResponse
-
+
public boolean isLocalSCABIndingInvoker() {
return true;
}
-
- private MessageFactory getMessageFactory() {
- FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
- return modelFactories.getFactory(MessageFactory.class);
- } // end method getMessageFactory
+
+ private MessageFactory getMessageFactory() {
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ return modelFactories.getFactory(MessageFactory.class);
+ } // end method getMessageFactory
}
@@ -40,7 +40,7 @@ public LocalSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) {
@Override
public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) {
- return new LocalSCAReferenceBindingProvider(extensionPoints, endpointReference, scaBindingMapper);
+ return new DefaultLocalSCAReferenceBindingProvider(extensionPoints, endpointReference, scaBindingMapper);
}
@Override
Oops, something went wrong.

0 comments on commit 952f46c

Please sign in to comment.