Author: slaws
Date: Thu Jun 17 10:43:48 2010
New Revision: 955544

URL: http://svn.apache.org/viewvc?rev=955544&view=rev
Log:
TUSCANY-2593 - Create an endpoint on the fly at the point a reference target is 
resolved in order to handle callbacks. This investigation has raised some 
questions that OASIS needs to answer, e.g. how to handle policy in this late 
bound scenario. Also this code change turns off generated WSDL caching and also 
relies on the SCA binding being attached to the callback service to carry the 
binding URI but this causes problems if you explicitly specify binding.sca. So 
more work to do but the basic test passes now. 

Modified:
    
tuscany/sca-java-2.x/trunk/itest/callback-basic-ws/src/test/java/org/apache/tuscany/sca/test/CallBackBasicTestCase.java
    
tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
    
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java
    
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java

Modified: 
tuscany/sca-java-2.x/trunk/itest/callback-basic-ws/src/test/java/org/apache/tuscany/sca/test/CallBackBasicTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/callback-basic-ws/src/test/java/org/apache/tuscany/sca/test/CallBackBasicTestCase.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/itest/callback-basic-ws/src/test/java/org/apache/tuscany/sca/test/CallBackBasicTestCase.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/itest/callback-basic-ws/src/test/java/org/apache/tuscany/sca/test/CallBackBasicTestCase.java
 Thu Jun 17 10:43:48 2010
@@ -40,7 +40,7 @@ public class CallBackBasicTestCase {
     }
 
     @Test
-    @Ignore("TUSCANY-3593")
+    //@Ignore("TUSCANY-3593")
     public void testCallBackBasic1() {
         CallBackBasicClient aCallBackClient = 
node.getService(CallBackBasicClient.class, "CallBackBasicClient1");
         aCallBackClient.run();

Modified: 
tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java
 Thu Jun 17 10:43:48 2010
@@ -45,6 +45,7 @@ public class WebServiceBindingBuilder im
      * Create a calculated WSDL document and save it in the Web Service 
binding. 
      */
     public void build(Component component, Contract contract, 
WebServiceBinding binding, BuilderContext context) {
+        binding.setWSDLDocument(null);
         BindingWSDLGenerator.generateWSDL(component, contract, binding, 
extensionPoints, context.getMonitor());
     }
 

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java
 Thu Jun 17 10:43:48 2010
@@ -1095,14 +1095,14 @@ public class ComponentBuilderImpl {
     private void createCallbackService(Component component, ComponentReference 
reference) {
         if (reference.getInterfaceContract() != null && // can be null in unit 
tests
             reference.getInterfaceContract().getCallbackInterface() != null) {
-            ComponentService componentService = 
assemblyFactory.createComponentService();
-            componentService.setForCallback(true);
-            componentService.setName(reference.getName());
+            ComponentService callbackService = 
assemblyFactory.createComponentService();
+            callbackService.setForCallback(true);
+            callbackService.setName(reference.getName());
             try {
                 InterfaceContract contract = 
(InterfaceContract)reference.getInterfaceContract().clone();
                 contract.setInterface(contract.getCallbackInterface());
                 contract.setCallbackInterface(null);
-                componentService.setInterfaceContract(contract);
+                callbackService.setInterfaceContract(contract);
             } catch (CloneNotSupportedException e) {
                 // will not happen
             }
@@ -1151,16 +1151,16 @@ public class ComponentBuilderImpl {
                 } catch (CloneNotSupportedException e) {
                     // will not happen
                 }
-                componentService.setService(implService);
+                callbackService.setService(implService);
             }
-            component.getServices().add(componentService);
+            component.getServices().add(callbackService);
 
             // configure bindings for the callback service
-            if (componentService.getBindings().isEmpty()) {
+            if (callbackService.getBindings().isEmpty()) {
                 if (reference.getCallback() != null && 
reference.getCallback().getBindings().size() > 0) {
                     // set bindings of the callback service based on the 
information provided in 
                     // SCDL reference callback element
-                    
componentService.getBindings().addAll(reference.getCallback().getBindings());
+                    
callbackService.getBindings().addAll(reference.getCallback().getBindings());
                 } else if (reference.getBindings().size() > 0) {
                     // use any bindings explicitly declared on the forward 
reference
                     for (Binding binding : reference.getBindings()) {
@@ -1168,19 +1168,24 @@ public class ComponentBuilderImpl {
                             Binding clonedBinding = (Binding)binding.clone();
                             // binding uri will be calculated during runtime 
build
                             clonedBinding.setURI(null);
-                            componentService.getBindings().add(clonedBinding);
+                            callbackService.getBindings().add(clonedBinding);
                         } catch (CloneNotSupportedException ex) {
 
                         }
                     }
                 } else {
-                    // create a default binding
-                    // TODO - need to mark the binding as needing resolution
-                    createSCABinding(componentService, null);
+                    // create a default binding which will have the correct 
policy 
+                    // and URI added. We check later to see if a new binding 
is required
+                    // based on the forward binding but can then copy policy 
and URI
+                    // details from here. 
+                    // TODO - there is a hole here. If the user explicitly 
specified an
+                    //        SCA callback binding that is different from the 
forward 
+                    //        binding type then we're in trouble
+                    createSCABinding(callbackService, null);
                 }
             }
 
-            reference.setCallbackService(componentService);
+            reference.setCallbackService(callbackService);
         }
     }
 

Modified: 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java
 Thu Jun 17 10:43:48 2010
@@ -111,6 +111,8 @@ public class EndpointBuilderImpl impleme
                         // to the services they promote. This is not actually 
done
                         // until the wire is created though in order that the 
                         // uri is calculated correctly
+                        // Callback endpoints may not be added here in the 
case that the
+                        // forward reference is not yet resolved. 
                         for (Binding binding : service.getBindings()) {
                             Endpoint endpoint = 
assemblyFactory.createEndpoint();
                             endpoint.setComponent(component);

Modified: 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java
 Thu Jun 17 10:43:48 2010
@@ -41,6 +41,7 @@ public interface RuntimeEndpointReferenc
      * @return The binding provider
      */
     ReferenceBindingProvider getBindingProvider();
+    
     /**
      * Get the interface contract for the binding. This represents the data 
types that the binding
      * protocol stack can process.
@@ -54,7 +55,8 @@ public interface RuntimeEndpointReferenc
      * implementation code uses to make the outbound call.
      * @return The source component type reference interface contract
      */
-    InterfaceContract getComponentTypeReferenceInterfaceContract();    
+    InterfaceContract getComponentTypeReferenceInterfaceContract();   
+    
     boolean isOutOfDate();
     void rebuild();
     boolean isStarted();

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java?rev=955544&r1=955543&r2=955544&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
 Thu Jun 17 10:43:48 2010
@@ -30,9 +30,11 @@ 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.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
 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.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;
@@ -40,6 +42,7 @@ import org.apache.tuscany.sca.assembly.b
 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.InterfaceContractMapper;
 import org.apache.tuscany.sca.monitor.Monitor;
@@ -49,6 +52,7 @@ import org.apache.tuscany.sca.policy.Int
 import org.apache.tuscany.sca.policy.IntentMap;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.Qualifier;
+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;
@@ -71,7 +75,8 @@ public class EndpointReferenceBinderImpl
     protected AssemblyFactory assemblyFactory;
     protected InterfaceContractMapper interfaceContractMapper;
     protected BuilderExtensionPoint builders;
-    private Monitor monitor;
+    protected CompositeActivator compositeActivator;
+    protected Monitor monitor;
 
 
     public EndpointReferenceBinderImpl(ExtensionPointRegistry extensionPoints) 
{
@@ -87,6 +92,7 @@ public class EndpointReferenceBinderImpl
         monitor = monitorFactory.createMonitor();
         
         this.builders = 
extensionPoints.getExtensionPoint(BuilderExtensionPoint.class);
+        this.compositeActivator = 
extensionPoints.getExtensionPoint(CompositeActivator.class);
     }
     
     /**
@@ -97,7 +103,7 @@ public class EndpointReferenceBinderImpl
      * @param endpointReference
      */
     public void bindBuildTime(EndpointRegistry endpointRegistry, 
-                                 EndpointReference endpointReference) {
+                              EndpointReference endpointReference) {
        bind(endpointRegistry, endpointReference, false);
     }
     
@@ -109,7 +115,7 @@ public class EndpointReferenceBinderImpl
      * @param endpointReference
      */
     public void bindRunTime(EndpointRegistry endpointRegistry,
-                               EndpointReference endpointReference) {
+                            EndpointReference endpointReference) {
         bind(endpointRegistry, endpointReference, true);
     }
     
@@ -121,8 +127,8 @@ public class EndpointReferenceBinderImpl
      * @param runtime set true if called from the runtime 
      */
     public void bind(EndpointRegistry endpointRegistry,  
-                        EndpointReference endpointReference,
-                        boolean runtime){
+                     EndpointReference endpointReference,
+                     boolean runtime){
         
         logger.fine("Binding " + endpointReference.toString());
         
@@ -205,7 +211,7 @@ public class EndpointReferenceBinderImpl
                 (endpointReference.getCallbackEndpoint() == null 
                     || 
endpointReference.getCallbackEndpoint().isUnresolved())) {
                 selectCallbackEndpoint(endpointReference,
-                                       
endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       
endpointReference.getReference().getCallbackService(),
                                        matchAudit);
             } 
         } else if (endpointReference.getStatus() == 
EndpointReference.Status.WIRED_TARGET_FOUND_READY_FOR_MATCHING ){
@@ -220,7 +226,7 @@ public class EndpointReferenceBinderImpl
 
             if (hasCallback(endpointReference)){
                 selectCallbackEndpoint(endpointReference,
-                                       
endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       
endpointReference.getReference().getCallbackService(),
                                        matchAudit);
             }             
         } else if (endpointReference.getStatus() == 
EndpointReference.Status.WIRED_TARGET_IN_BINDING_URI ||
@@ -258,7 +264,7 @@ public class EndpointReferenceBinderImpl
 
             if (hasCallback(endpointReference)){
                 selectCallbackEndpoint(endpointReference,
-                                       
endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       
endpointReference.getReference().getCallbackService(),
                                        matchAudit);
             }             
         } 
@@ -353,28 +359,89 @@ public class EndpointReferenceBinderImpl
      * @param endpointReference
      * @param endpoints
      */
-    private void selectCallbackEndpoint(EndpointReference endpointReference, 
List<Endpoint> endpoints, StringBuffer matchAudit) {
+    private void selectCallbackEndpoint(EndpointReference endpointReference, 
ComponentService callbackService, StringBuffer matchAudit) {
       
         // find the first callback endpoint that matches a callback endpoint 
reference
         // at the service
-        Endpoint matchedEndpoint = null;
+        RuntimeEndpoint matchedEndpoint = null;
         match:
         for ( EndpointReference callbackEndpointReference : 
endpointReference.getTargetEndpoint().getCallbackEndpointReferences()){
-            for (Endpoint endpoint : endpoints){
+            for (Endpoint endpoint : callbackService.getEndpoints()){
                 if (haveMatchingPolicy(callbackEndpointReference, endpoint, 
matchAudit) &&
                     haveMatchingInterfaceContracts(callbackEndpointReference, 
endpoint, matchAudit)){
-                    matchedEndpoint = endpoint;
+                    matchedEndpoint = (RuntimeEndpoint)endpoint;
                     break match;
                 }
             }
         }
         
-        if (matchedEndpoint == null){
-            return;
-        } else {
-            endpointReference.setCallbackEndpoint(matchedEndpoint);
-        }
+        // if no callback endpoint was found or if the binding is the SCA 
binding and it doesn't match 
+        // the forward binding then create a new callback endpoint
+        // TODO - there is a hole here in that the user may explicitly specify 
an SCA binding for the
+        //        callback that is different from the forward binding. Waiting 
for feedback form OASIS
+        //        before doing more drastic surgery to fix this corner case as 
there are other things
+        //        wrong with the default case, such as what to do about policy
+        if (matchedEndpoint == null ||
+            (matchedEndpoint.getBinding().getType().equals(SCABinding.TYPE) &&
+             
!endpointReference.getBinding().getType().equals(SCABinding.TYPE))){
+            // no endpoint in place so we need to create one 
+            matchedEndpoint = 
(RuntimeEndpoint)assemblyFactory.createEndpoint();
+            matchedEndpoint.setComponent(endpointReference.getComponent());
+            matchedEndpoint.setService(callbackService);
+            
+            Binding forwardBinding = endpointReference.getBinding();
+            Binding callbackBinding = null;
+            for (EndpointReference callbackEPR : 
endpointReference.getTargetEndpoint().getCallbackEndpointReferences()){
+                if 
(callbackEPR.getBinding().getType().equals(forwardBinding.getType())){
+                    try {
+                        callbackBinding = 
(Binding)callbackEPR.getBinding().clone();
+                    } catch (CloneNotSupportedException ex){
+                        
+                    }  
+                    break;
+                }
+            }
+            
+            // get the callback binding URI by looking at the SCA binding 
+            // that will have been added at build time
+            callbackBinding.setURI(null);
+            for (Endpoint endpoint : callbackService.getEndpoints()){
+                if (endpoint.getBinding().getType().equals(SCABinding.TYPE)){
+                    callbackBinding.setURI(endpoint.getBinding().getURI());
+                }
+            }
+            
+            matchedEndpoint.setBinding(callbackBinding);
+            callbackService.getBindings().add(callbackBinding);
+            
+            matchedEndpoint.setUnresolved(false);
+            callbackService.getEndpoints().add(matchedEndpoint);
+            
+            // build it
+            build(matchedEndpoint);
+            
+            // activate it
+            
compositeActivator.activate(((RuntimeEndpointReferenceImpl)endpointReference).getCompositeContext(),
 
+                                        matchedEndpoint);
+            
+            // start it
+            
compositeActivator.start(((RuntimeEndpointReferenceImpl)endpointReference).getCompositeContext(),
 
+                                     matchedEndpoint);  
+        } 
+        
+        endpointReference.setCallbackEndpoint(matchedEndpoint);
     }
+    
+    private void build(Endpoint endpoint) {
+        
+        BindingBuilder builder = 
builders.getBindingBuilder(endpoint.getBinding().getType());
+        if (builder != null) {
+            builder.build(endpoint.getComponent(),
+                          endpoint.getService(),
+                          endpoint.getBinding(),
+                          new BuilderContext(extensionPoints));
+        }
+    }    
 
     /**
      * Determine if endpoint reference and endpoint policies match. We know by 
this stage


Reply via email to