You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/01/25 15:03:24 UTC

svn commit: r902811 - in /tuscany/sca-java-2.x/trunk/modules/core/src/main: java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java resources/endpoint-validation-messages.properties

Author: slaws
Date: Mon Jan 25 14:03:24 2010
New Revision: 902811

URL: http://svn.apache.org/viewvc?rev=902811&view=rev
Log:
Some tidying of error handling and add ability to print out reason match failed in error case

Modified:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties

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=902811&r1=902810&r2=902811&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 Mon Jan 25 14:03:24 2010
@@ -120,7 +120,7 @@
         
         logger.fine("Binding " + endpointReference.toString());
         
-        Problem problem = null;
+        StringBuffer matchAudit = new StringBuffer();
              
         // This logic does post build autowire matching but isn't actually used at the moment
         // as problems with dependencies mean we still do this during build
@@ -143,8 +143,8 @@
                         continue;
                     }
                     
-                    if (haveMatchingPolicy(endpointReference, endpoint) &&
-                        haveMatchingInterfaceContracts(endpointReference, endpoint)){
+                    if (haveMatchingPolicy(endpointReference, endpoint, matchAudit) &&
+                        haveMatchingInterfaceContracts(endpointReference, endpoint, matchAudit)){
                         // matching service so find if this reference already has 
                         // an endpoint reference for this endpoint
                         Endpoint autowireEndpoint = null;
@@ -181,6 +181,7 @@
                                   "endpoint-validation-messages",
                                   "NoComponentReferenceTarget",
                                   endpointReference.getReference().getName());
+                    return false;
                 }
             }
             
@@ -196,8 +197,9 @@
             if (hasCallback(endpointReference) &&
                 endpointReference.getCallbackEndpoint() != null &&
                 endpointReference.getCallbackEndpoint().isUnresolved() == true ){
-                problem = selectCallbackEndpoint(endpointReference,
-                                                 endpointReference.getReference().getCallbackService().getEndpoints());
+                selectCallbackEndpoint(endpointReference,
+                                       endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       matchAudit);
             } 
         } else if (endpointReference.getStatus() == EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING ){
             // The endpoint reference is already resolved to either
@@ -205,12 +207,14 @@
             // target URL and/or the policies have yet to be matched.
             // TODO - is this really required now
             
-            problem = selectForwardEndpoint(endpointReference,
-                                            endpointReference.getTargetEndpoint().getService().getEndpoints());
+            selectForwardEndpoint(endpointReference,
+                                  endpointReference.getTargetEndpoint().getService().getEndpoints(),
+                                  matchAudit);
 
-            if (problem == null && hasCallback(endpointReference)){
-                problem = selectCallbackEndpoint(endpointReference,
-                                                 endpointReference.getReference().getCallbackService().getEndpoints());
+            if (hasCallback(endpointReference)){
+                selectCallbackEndpoint(endpointReference,
+                                       endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       matchAudit);
             }             
         } else if (endpointReference.getStatus() == EndpointReference.WIRED_TARGET_IN_BINDING_URI ||
                    endpointReference.getStatus() == EndpointReference.WIRED_TARGET_NOT_FOUND ||
@@ -232,50 +236,46 @@
                     endpointReference.setRemote(true);
                     endpointReference.setStatus(EndpointReference.RESOLVED_BINDING);
                 } else {
-                    problem = monitor.createProblem(this.getClass().getName(), 
-                                                    "endpoint-validation-messages", 
-                                                    Problem.Severity.ERROR, 
-                                                    this, 
-                                                    "NoEndpointsFound", 
-                                                    endpointReference.toString());
+                    Monitor.error(monitor, 
+                                  this, 
+                                  "endpoint-validation-messages", 
+                                  "NoEndpointsFound", 
+                                  endpointReference.toString()); 
+                    return false;
                 }
             }            
 
-            problem = selectForwardEndpoint(endpointReference,
-                                            endpoints);
+            selectForwardEndpoint(endpointReference,
+                                  endpoints,
+                                  matchAudit);
 
-            if (problem == null && hasCallback(endpointReference)){
-                problem = selectCallbackEndpoint(endpointReference,
-                                                 endpointReference.getReference().getCallbackService().getEndpoints());
+            if (hasCallback(endpointReference)){
+                selectCallbackEndpoint(endpointReference,
+                                       endpointReference.getReference().getCallbackService().getEndpoints(),
+                                       matchAudit);
             }             
         } 
         
-        if (problem != null){
-            monitor.problem(problem);
-            return false;
-        }
+        logger.fine(matchAudit.toString());
 
         if (endpointReference.getStatus() != EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED &&
             endpointReference.getStatus() != EndpointReference.RESOLVED_BINDING){
             
             if (runtime){
-                problem = monitor.createProblem(this.getClass().getName(), 
-                                                "endpoint-validation-messages", 
-                                                Problem.Severity.ERROR, 
-                                                this, 
-                                                "EndpointReferenceCantBeMatched", 
-                                                endpointReference.toString());
+                Monitor.error(monitor, 
+                              this, 
+                              "endpoint-validation-messages", 
+                              "EndpointReferenceCantBeMatched", 
+                              endpointReference.toString(),
+                              matchAudit);
             } else {
-                problem = monitor.createProblem(this.getClass().getName(), 
-                                                "endpoint-validation-messages", 
-                                                Problem.Severity.WARNING, 
-                                                this, 
-                                                "ComponentReferenceTargetNotFound",
-                                                "NEED COMPOSITE NAME",
-                                                endpointReference.toString());
+                Monitor.warning(monitor, 
+                                this, 
+                                "endpoint-validation-messages", 
+                                "ComponentReferenceTargetNotFound", 
+                                endpointReference.toString());
             }
-            
-            monitor.problem(problem);
+               
             return false;
         }
        
@@ -301,7 +301,7 @@
      * @param endpointReference
      * @param endpoints
      */
-    private Problem selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints) {    
+    private void selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints, StringBuffer matchAudit) {    
              
         Endpoint matchedEndpoint = null;
         
@@ -311,8 +311,8 @@
         } else {
             // find the first endpoint that matches this endpoint reference
             for (Endpoint endpoint : endpoints){
-                if (haveMatchingPolicy(endpointReference, endpoint) &&
-                    haveMatchingInterfaceContracts(endpointReference, endpoint)){
+                if (haveMatchingPolicy(endpointReference, endpoint, matchAudit) &&
+                    haveMatchingInterfaceContracts(endpointReference, endpoint, matchAudit)){
                     matchedEndpoint = endpoint;
                     break;
                 }
@@ -320,15 +320,13 @@
         }
         
         if (matchedEndpoint == null){
-            return null;
+            return;
+        } else {
+            endpointReference.setTargetEndpoint(matchedEndpoint);
+            endpointReference.setBinding(endpointReference.getTargetEndpoint().getBinding());
+            endpointReference.setStatus(EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED);
+            endpointReference.setUnresolved(false);
         }
-        
-        endpointReference.setTargetEndpoint(matchedEndpoint);
-        endpointReference.setBinding(endpointReference.getTargetEndpoint().getBinding());
-        endpointReference.setStatus(EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED);
-        endpointReference.setUnresolved(false);
-        
-        return null;
     }
 
     /**
@@ -337,18 +335,16 @@
      * @param endpointReference
      * @param endpoints
      */
-    private Problem selectCallbackEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints) {
-
-        Problem problem = null;
-        
+    private void selectCallbackEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints, StringBuffer matchAudit) {
+      
         // find the first callback endpoint that matches a callback endpoint reference
         // at the service
         Endpoint matchedEndpoint = null;
         match:
         for ( EndpointReference callbackEndpointReference : endpointReference.getTargetEndpoint().getCallbackEndpointReferences()){
             for (Endpoint endpoint : endpoints){
-                if (haveMatchingPolicy(callbackEndpointReference, endpoint) &&
-                    haveMatchingInterfaceContracts(callbackEndpointReference, endpoint)){
+                if (haveMatchingPolicy(callbackEndpointReference, endpoint, matchAudit) &&
+                    haveMatchingInterfaceContracts(callbackEndpointReference, endpoint, matchAudit)){
                     matchedEndpoint = endpoint;
                     break match;
                 }
@@ -356,12 +352,10 @@
         }
         
         if (matchedEndpoint == null){
-            return null;
+            return;
+        } else {
+            endpointReference.setCallbackEndpoint(matchedEndpoint);
         }
-        
-        endpointReference.setCallbackEndpoint(matchedEndpoint);
-        
-        return problem;
     }
 
     /**
@@ -373,8 +367,8 @@
      *     
      * TODO - narative of matching algorithm
      */
-    private boolean haveMatchingPolicy(EndpointReference endpointReference, Endpoint endpoint){
-        logger.fine("Match policy of " + endpointReference.toString() + " to " + endpoint.toString());
+    private boolean haveMatchingPolicy(EndpointReference endpointReference, Endpoint endpoint, StringBuffer matchAudit){
+        matchAudit.append("Match policy of " + endpointReference.toString() + " to " + endpoint.toString() + " ");
         
         List<PolicySet> referencePolicySets = new ArrayList<PolicySet>();
         Binding binding = null;
@@ -391,10 +385,11 @@
             for (Intent epIntent : endpoint.getRequiredIntents()){ 
                 if (eprIntent.getExcludedIntents().contains(epIntent) ||
                     epIntent.getExcludedIntents().contains(eprIntent)){
-                    logger.fine("No match because the following intents are mutually exclusive " + 
-                                eprIntent.toString() +
-                                " " +
-                                epIntent.toString());
+                    matchAudit.append("No match because the following intents are mutually exclusive " + 
+                                      eprIntent.toString() +
+                                      " " +
+                                      epIntent.toString() +
+                                      " ");
                     return false;
                 }
             }
@@ -447,7 +442,7 @@
             (endpoint.getRequiredIntents().size() == 0) &&
             (noEndpointReferencePolicies) &&
             (noEndpointPolicies)) {
-            logger.fine("Match because there are no intents or policy sets");
+            matchAudit.append("Match because there are no intents or policy sets ");
             return true;
         }        
         
@@ -486,26 +481,26 @@
         
         // if there are unresolved intents the service and reference don't match
         if (eprIntents.size() > 0){
-            logger.fine("No match because there are unresolved intents " + eprIntents.toString());
+            matchAudit.append("No match because there are unresolved intents " + eprIntents.toString() + " ");
             return false;
         }   
         
         // if there are no policy sets on epr or ep side then 
         // they match
         if (noEndpointPolicies && noEndpointReferencePolicies){
-            logger.fine("Match because the intents are resolved and there are no policy sets");
+            matchAudit.append("Match because the intents are resolved and there are no policy sets ");
             return true;
         }
         
         // if there are some policies on one side and not the other then 
         // the don't match
         if (noEndpointPolicies && !noEndpointReferencePolicies) {
-            logger.fine("No match because there are policy sets at the endpoint reference but not at the endpoint");
+            matchAudit.append("No match because there are policy sets at the endpoint reference but not at the endpoint ");
             return false;
         }
         
         if (!noEndpointPolicies && noEndpointReferencePolicies){
-            logger.fine("No match because there are policy sets at the endpoint but not at the endpoint reference");
+            matchAudit.append("No match because there are policy sets at the endpoint but not at the endpoint reference ");
             return false;
         }
         
@@ -514,7 +509,7 @@
         Set<PolicySet> referencePolicySet = new HashSet<PolicySet>(referencePolicySets);
         Set<PolicySet> servicePolicySet = new HashSet<PolicySet>(endpoint.getPolicySets());
         if(referencePolicySet.equals(servicePolicySet)){
-            logger.fine("Match because the policy sets on both sides are eactly the same");
+            matchAudit.append("Match because the policy sets on both sides are eactly the same ");
             return true;
         }
         
@@ -542,10 +537,11 @@
         }
         
         if(!eprLanguage.equals(epLanguage)){
-            logger.fine("No match because the policy sets on either side have policies in differnt languages " + 
-                        eprLanguage + 
-                        " and " +
-                        epLanguage );
+            matchAudit.append("No match because the policy sets on either side have policies in differnt languages " + 
+                              eprLanguage + 
+                              " and " +
+                              epLanguage +
+                              " ");
             return false;
         }
         
@@ -567,11 +563,11 @@
         } 
                 
         if (!match){
-            logger.fine("No match because the language specific matching failed");
+            matchAudit.append("No match because the language specific matching failed ");
             endpointReference.getPolicySets().clear();
             endpointReference.getPolicySets().addAll(originalPolicySets);
         } else {
-            logger.fine("Match because the language specific matching succeeded");
+            matchAudit.append("Match because the language specific matching succeeded ");
         }
         
         return match;
@@ -580,11 +576,11 @@
     /**
      * Determine if endpoint reference and endpoint interface contracts match 
      */
-    private boolean haveMatchingInterfaceContracts(EndpointReference endpointReference, Endpoint endpoint){
-        logger.fine("Match interface of " + endpointReference.toString() + " to " + endpoint.toString());
+    private boolean haveMatchingInterfaceContracts(EndpointReference endpointReference, Endpoint endpoint, StringBuffer matchAudit){
+        matchAudit.append("Match interface of " + endpointReference.toString() + " to " + endpoint.toString() + " ");
         
         if (endpointReference.getReference().getInterfaceContract() == null){
-            logger.fine("Match because there is no interface contract on the reference");
+            matchAudit.append("Match because there is no interface contract on the reference ");
             return true;
         }
         
@@ -595,7 +591,7 @@
             // we discussed this on the ML and decided that we could
             // live with this for the case where there is no central matching of references
             // to services. Any errors will be detected when the message flows.
-            logger.fine("Match because the endpoint is remote and we don't have a copy of it's interface contract");
+            matchAudit.append("Match because the endpoint is remote and we don't have a copy of it's interface contract ");
             return true;
         }
              
@@ -604,9 +600,9 @@
                                                      endpoint.getComponentServiceInterfaceContract());
         
         if (!match){
-            logger.fine("Match because the linterface contract mapper failed");
+            matchAudit.append("Match because the linterface contract mapper failed ");
         } else {
-            logger.fine("Match because the interface contract mapper succeeded");
+            matchAudit.append("Match because the interface contract mapper succeeded ");
         }
         
         return match;

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties?rev=902811&r1=902810&r2=902811&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/resources/endpoint-validation-messages.properties Mon Jan 25 14:03:24 2010
@@ -19,4 +19,5 @@
 #
 #
 NoEndpointsFound = No endpoints found in the domain that match the reference {0} 
-EndpointReferenceCantBeMatched = = Unable to match the endpoint reference {0} with the policy of the service to which it refers. 
+EndpointReferenceCantBeMatched = = Unable to match the endpoint reference {0} with the policy of the service to which it refers, matching process was {1}
+ComponentReferenceTargetNotFound = Component reference target not found, it might be a remote service running elsewhere in the SCA Domain: {1}