diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-13 09:12:08 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-13 09:12:08 +0000 |
commit | 47f6879e357c5f878e3e43164e243cd41e056df0 (patch) | |
tree | e3328adfcd5a92c5103d112c0b1e73925719311b /sca-java-2.x/trunk/modules/core | |
parent | 6aeeb05d754515b86100efe8e2efc397556076ee (diff) |
TUSCANY-3616 - Add code to check that that interface contracts a reference and reference binding and at service and service binding match. Motivated by BWS_2007. TO do this properly we have to test that the interfaces are described using the same IDL and if not convert to WSDL1.1 are required by the SCA specifications. There are a lot of changes here as doing this upset quite a few tests. Further work is required to look at the details of our WSDL generation process which looks a little suspect around wrapper namespaces.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@963624 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
6 files changed, 209 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java index 6712b71efd..928880214d 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java @@ -58,10 +58,34 @@ public interface RuntimeEndpoint extends Endpoint, Invocable, Serializable { */ InterfaceContract getComponentTypeServiceInterfaceContract(); + + /** + * Check that endpoint has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + */ + void validateServiceInterfaceCompatibility(); + /** * Get the composite context for the composite that contains this endpoint. This * is useful for accessing various composite level objects from within the * runtime code */ CompositeContext getCompositeContext(); + + /** + * to allow for remote interface comparison we convert a Endpoint's Java interface + * to WSDL at build time. + * + * @param wsdlContract + */ +// void setGeneratedWSDLContract(InterfaceContract wsdlContract); + + /** + * to allow for remote interface comparison we convert a Endpoint's Java interface + * to WSDL at build time. + * + * @preturn wsdlContract + */ +// InterfaceContract getGeneratedWSDLContract(); + } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java index e852a47cf8..fb9b9992c6 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java @@ -49,6 +49,7 @@ public interface RuntimeEndpointReference extends EndpointReference, Invocable, */ InterfaceContract getBindingInterfaceContract(); + /** * Get the interface contract of the reference of the source component type, i.e., the * componentType.reference.interfaceContract. This represents the data types that the @@ -57,6 +58,30 @@ public interface RuntimeEndpointReference extends EndpointReference, Invocable, */ InterfaceContract getComponentTypeReferenceInterfaceContract(); + /** + * Check that endpoint reference has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + * There is checking in the activator but of course endpoint references may not have a binding assigned + * until final resolution. + */ + public void validateReferenceInterfaceCompatibility(); + + /** + * to allow for remote interface comparison we convert a Endpoint Reference's Java interface + * to WSDL at build time. + * + * @param wsdlContract + */ +// void setGeneratedWSDLContract(InterfaceContract wsdlContract); + + /** + * to allow for remote interface comparison we convert a Endpoint Reference's Java interface + * to WSDL at build time. + * + * @preturn wsdlContract + */ +// InterfaceContract getGeneratedWSDLContract(); + boolean isOutOfDate(); void rebuild(); boolean isStarted(); diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java index afd62edb8b..db345826d1 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java @@ -247,6 +247,10 @@ public class CompositeActivatorImpl implements CompositeActivator { public void activate(CompositeContext compositeContext, RuntimeEndpoint ep) { ep.bind(compositeContext); + + // Check that the service binding interface is compatible with the + // service interface + ep.validateServiceInterfaceCompatibility(); } public void deactivate(RuntimeComponent component, RuntimeComponentService service) { @@ -309,6 +313,13 @@ public class CompositeActivatorImpl implements CompositeActivator { } // endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false)); + + // if the reference already has a binding we can check the reference binding interface + // and reference interfaces for compatibility. If we can't check now compatibility + // will be checked when the endpoint reference is resolved. + if (epr.getStatus() == EndpointReference.Status.RESOLVED_BINDING){ + epr.validateReferenceInterfaceCompatibility(); + } } public void deactivate(RuntimeEndpointReference endpointReference) { diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java index eeadfef9c1..4809241432 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java @@ -187,6 +187,8 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint this.phaseManager = utilities.getUtility(PhaseManager.class); this.serializer = utilities.getUtility(EndpointSerializer.class); this.providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); + this.contractBuilder = builders.getContractBuilder(); } public void unbind() { @@ -224,7 +226,11 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint for (InvocationChain chain : getInvocationChains()) { Operation op = chain.getTargetOperation(); - if (interfaceContractMapper.isCompatible(operation, op, Compatibility.SUBSET)) { + // We used to check compatibility here but this is now validated when the + // chain is created. As the chain operations are the real interface types + // they may be incompatible just because they are described in different + // IDLs + if (operation.getName().equals(op.getName())) { invocationChainMap.put(operation, chain); return chain; } @@ -304,6 +310,7 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint // TODO - EPR - why is this looking at the component types. The endpoint should have the right interface contract by this time InterfaceContract targetContract = getComponentTypeServiceInterfaceContract(); // setInterfaceContract(targetContract); + validateServiceInterfaceCompatibility(); for (Operation operation : sourceContract.getInterface().getOperations()) { Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); if (targetOperation == null) { @@ -463,6 +470,47 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); return (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); } // end method RuntimeAssemblyFactory + + /** + * Check that endpoint has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + */ + public void validateServiceInterfaceCompatibility() { + + InterfaceContract serviceContract = getComponentServiceInterfaceContract(); + InterfaceContract bindingContract = getBindingInterfaceContract(); + + if ((serviceContract != null) && + (bindingContract != null)){ + try { + if ((serviceContract.getClass() != bindingContract.getClass()) && + (serviceContract instanceof JavaInterfaceContract)) { + interfaceContractMapper.checkCompatibility(getGeneratedWSDLContract(serviceContract), + bindingContract, + Compatibility.SUBSET, + true, // we ignore callbacks as binding iface won't have one + false); + } else { + interfaceContractMapper.checkCompatibility(serviceContract, + bindingContract, + Compatibility.SUBSET, + true, // we ignore callbacks as binding iface won't have one + false); + } + } catch (Exception ex){ + throw new ServiceRuntimeException("Component " + + this.getComponent().getName() + + " Service " + + getService().getName() + + " interface is incompatible with the interface of the reference binding - " + + getBinding().getName() + + " - " + + ex.getMessage() + + " - [" + this.toString() + "]"); + } + } + + } private void initServiceBindingInvocationChains() { @@ -744,5 +792,17 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint } } } + public InterfaceContract getGeneratedWSDLContract(InterfaceContract interfaceContract) { + if ( interfaceContract.getNormalizedWSDLContract() == null){ + if (getComponentServiceInterfaceContract() instanceof JavaInterfaceContract){ + if (contractBuilder == null){ + throw new ServiceRuntimeException("Contract builder not found while calculating WSDL contract for " + this.toString()); + } + contractBuilder.build(getComponentServiceInterfaceContract(), null); + } + } + + return interfaceContract.getNormalizedWSDLContract(); + } } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java index 9ef0d8e728..531e4634e1 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java @@ -37,6 +37,8 @@ import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.ContractBuilder; import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -51,12 +53,15 @@ import org.apache.tuscany.sca.interfacedef.Compatibility; 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.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.EndpointReferenceProvider; import org.apache.tuscany.sca.provider.PolicyProvider; @@ -99,6 +104,9 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen protected InterfaceContract bindingInterfaceContract; protected InterfaceContract referenceInterfaceContract; + + //protected InterfaceContract generatedReferenceWSDLInterfaceContract; + private String xml; private boolean started; @@ -169,6 +177,9 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen this.phaseManager = utilities.getUtility(PhaseManager.class); this.serializer = utilities.getUtility(EndpointSerializer.class); this.providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + + this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); + this.contractBuilder = builders.getContractBuilder(); } public synchronized List<InvocationChain> getInvocationChains() { @@ -191,7 +202,12 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen if (cached == null) { for (InvocationChain chain : getInvocationChains()) { Operation op = chain.getSourceOperation(); - if (interfaceContractMapper.isCompatible(operation, op, Compatibility.SUBSET)) { + + // We used to check compatibility here but this is now validated when the + // chain is created. As the chain operations are the real interface types + // they may be incompatible just because they are described in different + // IDLs + if (operation.getName().equals(op.getName())) { invocationChainMap.put(operation, chain); return chain; } @@ -266,6 +282,8 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen throw new IllegalStateException(e); } } + + validateReferenceInterfaceCompatibility(); List<InvocationChain> chainList = new ArrayList<InvocationChain>(); if(sourceContract != null && targetContract != null) { @@ -293,6 +311,51 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen chains = chainList; wireProcessor.process(this); } + + /** + * Check that endpoint reference has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + * There is checking in the activator but of course endpoint references may not have a binding assigned + * until final resolution. + */ + public void validateReferenceInterfaceCompatibility() { + + InterfaceContract referenceContract = getComponentReferenceInterfaceContract(); + InterfaceContract bindingContract = getBindingInterfaceContract(); + + if ((referenceContract != null) && + (bindingContract != null)){ + + try { + + if ((referenceContract.getClass() != bindingContract.getClass()) && + (referenceContract instanceof JavaInterfaceContract)) { + interfaceContractMapper.checkCompatibility(getGeneratedWSDLContract(referenceContract), + bindingContract, + Compatibility.SUBSET, + true, // we ignore callbacks as binding iface won't have one + false); + } else { + interfaceContractMapper.checkCompatibility(referenceContract, + bindingContract, + Compatibility.SUBSET, + true, // we ignore callbacks as binding iface won't have one + false); + } + + } catch (Exception ex){ + throw new ServiceRuntimeException("Component " + + this.getComponent().getName() + + " Reference " + + getReference().getName() + + " interface is incompatible with the interface of the reference binding " + + getBinding().getName() + + " - " + + ex.getMessage() + + " - [" + this.toString() + "]"); + } + } + } /** * This code used to be in the activator but has moved here as @@ -535,5 +598,18 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen public boolean isStarted() { return started; } + + public InterfaceContract getGeneratedWSDLContract(InterfaceContract interfaceContract) { + if ( interfaceContract.getNormalizedWSDLContract() == null){ + if (getComponentReferenceInterfaceContract() instanceof JavaInterfaceContract){ + if (contractBuilder == null){ + throw new ServiceRuntimeException("Contract builder not found while calculating WSDL contract for " + this.toString()); + } + contractBuilder.build(getComponentReferenceInterfaceContract(), null); + } + } + + return interfaceContract.getNormalizedWSDLContract(); + } } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index 7e49d45fe3..3349456044 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -29,21 +29,26 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.Messages; import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl; import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.interfacedef.Compatibility; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; @@ -56,6 +61,7 @@ import org.apache.tuscany.sca.runtime.CompositeActivator; import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.oasisopen.sca.ServiceRuntimeException; /** @@ -292,7 +298,11 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { throw new ServiceRuntimeException("Unable to bind " + monitor.getLastProblem().toString()); } - } + + // Now the endpoint reference is resolved check that the binding interfaces contract + // and the reference contract are compatible + ((RuntimeEndpointReference)endpointReference).validateReferenceInterfaceCompatibility(); + } /** * Returns true if the reference has a callback |