You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2008/05/08 12:01:27 UTC

svn commit: r654462 - in /synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse: config/xml/endpoints/ endpoints/

Author: indika
Date: Thu May  8 03:01:26 2008
New Revision: 654462

URL: http://svn.apache.org/viewvc?rev=654462&view=rev
Log:
Fix an issue with indirect endpoints 


Modified:
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/FailoverEndpointFactory.java
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/LoadbalanceEndpointFactory.java
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=654462&r1=654461&r2=654462&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java Thu May  8 03:01:26 2008
@@ -29,9 +29,12 @@
 import org.apache.synapse.config.XMLToObjectMapper;
 import org.apache.synapse.config.xml.XMLConfigConstants;
 import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.IndirectEndpoint;
 import org.apache.synapse.endpoints.utils.EndpointDefinition;
 
 import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * All endpoint factories should implement this interface. Use EndpointFactory to obtain the
@@ -331,6 +334,36 @@
         return null;
     }
 
+    /**
+     * Helper method to construct children endpoints
+     *
+     * @param listEndpointElement OMElement representing  the children endpoints
+     * @param parent              Parent endpoint
+     * @return List of children endpoints
+     */
+    protected ArrayList<Endpoint> getEndpoints(OMElement listEndpointElement, Endpoint parent) {
+
+        ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
+        ArrayList<String> keys = new ArrayList<String>();
+        Iterator iter = listEndpointElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
+        while (iter.hasNext()) {
+            OMElement endptElem = (OMElement) iter.next();
+            Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true);
+            if (endpoint instanceof IndirectEndpoint) {
+                String key = ((IndirectEndpoint) endpoint).getKey();
+                if (!keys.contains(key)) {
+                    keys.add(key);
+                } else {
+                    handleException("Same endpoint definition cannot be used with in the siblings");
+                }
+            }
+            endpoint.setParentEndpoint(parent);
+            endpoints.add(endpoint);
+        }
+
+        return endpoints;
+    }
+
     protected static void handleException(String msg) {
         log.error(msg);
         throw new SynapseException(msg);

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/FailoverEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/FailoverEndpointFactory.java?rev=654462&r1=654461&r2=654462&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/FailoverEndpointFactory.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/FailoverEndpointFactory.java Thu May  8 03:01:26 2008
@@ -24,6 +24,7 @@
 import org.apache.synapse.config.xml.XMLConfigConstants;
 import org.apache.synapse.endpoints.Endpoint;
 import org.apache.synapse.endpoints.FailoverEndpoint;
+import org.apache.synapse.endpoints.IndirectEndpoint;
 
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
@@ -64,21 +65,7 @@
             failoverEndpoint.setEndpoints(getEndpoints(failoverElement, failoverEndpoint));
             return failoverEndpoint;
         }
-
         return null;
     }
-    
-    private ArrayList<Endpoint> getEndpoints(OMElement failoverElement, Endpoint parent) {
-
-        ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
-        Iterator iter = failoverElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
-        while (iter.hasNext()) {
-            OMElement endptElem = (OMElement) iter.next();
-            Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true);
-            endpoint.setParentEndpoint(parent);
-            endpoints.add(endpoint);
-        }
 
-        return endpoints;
-    }
 }

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/LoadbalanceEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/LoadbalanceEndpointFactory.java?rev=654462&r1=654461&r2=654462&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/LoadbalanceEndpointFactory.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/LoadbalanceEndpointFactory.java Thu May  8 03:01:26 2008
@@ -90,18 +90,4 @@
 
         return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
-
-    private ArrayList<Endpoint> getEndpoints(OMElement loadbalanceElement, Endpoint parent) {
-
-        ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
-        Iterator iter = loadbalanceElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
-        while (iter.hasNext()) {
-            OMElement endptElem = (OMElement) iter.next();
-            Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true);
-            endpoint.setParentEndpoint(parent);
-            endpoints.add(endpoint);
-        }
-
-        return endpoints;
-    }
 }

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java?rev=654462&r1=654461&r2=654462&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java Thu May  8 03:01:26 2008
@@ -140,18 +140,4 @@
 
         return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
-
-    private ArrayList<Endpoint> getEndpoints(OMElement loadbalanceElement, Endpoint parent) {
-
-        ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
-        Iterator iter = loadbalanceElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
-        while (iter.hasNext()) {
-            OMElement endptElem = (OMElement) iter.next();
-            Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true);
-            endpoint.setParentEndpoint(parent);
-            endpoints.add(endpoint);
-        }
-
-        return endpoints;
-    }
 }

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java?rev=654462&r1=654461&r2=654462&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/IndirectEndpoint.java Thu May  8 03:01:26 2008
@@ -19,15 +19,12 @@
 
 package org.apache.synapse.endpoints;
 
-import org.apache.axis2.clustering.ClusterManager;
-import org.apache.axis2.context.ConfigurationContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.FaultHandler;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.endpoints.utils.EndpointDefinition;
 
 /**
@@ -38,7 +35,7 @@
  * As this is also an instance of endpoint, this can be used any place, where a normal endpoint is
  * used.
  */
-public class IndirectEndpoint implements Endpoint {
+public class IndirectEndpoint extends FaultHandler implements Endpoint {
 
     private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     private static final Log log = LogFactory.getLog(IndirectEndpoint.class);
@@ -47,12 +44,6 @@
     private String key = null;
     private Endpoint parentEndpoint = null;
 
-    /**
-     * This should have a reference to the current message context as it gets the referred endpoint
-     * from it.
-     */
-    private final EndpointContext endpointContext = new EndpointContext();
-
     public void send(MessageContext synMessageContext) {
 
         // get the actual endpoint and send
@@ -61,43 +52,11 @@
             handleException("Reference to non-existent endpoint for key : " + key);
         }
 
-        boolean isClusteringEnable = false;
-        // get Axis2 MessageContext and ConfigurationContext
-        org.apache.axis2.context.MessageContext axisMC =
-                ((Axis2MessageContext) synMessageContext).getAxis2MessageContext();
-        ConfigurationContext cc = axisMC.getConfigurationContext();
-
-        //The check for clustering environment
-
-        ClusterManager clusterManager = cc.getAxisConfiguration().getClusterManager();
-        if (clusterManager != null &&
-                clusterManager.getContextManager() != null) {
-            isClusteringEnable = true;
-        }
-
-        String endPointName = this.getName();
-        if (endPointName == null) {
-
-            if (log.isDebugEnabled() && isClusteringEnable) {
-                log.warn("In a clustering environment , the endpoint  name should be specified" +
-                        "even for anonymous endpoints. Otherwise , the clustering would not be " +
-                        "functioned correctly if there are more than one anonymous endpoints. ");
-            }
-            endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
-        }
-
-        if (isClusteringEnable) {
-            // if this is a cluster environment , then set configuration context to endpoint context
-            if (endpointContext.getConfigurationContext() == null) {
-                endpointContext.setConfigurationContext(cc);
-                endpointContext.setContextID(endPointName);
-            }
-        }
-
         assert endpoint != null;
         if (endpoint.isActive(synMessageContext)) {
+             // register this as the immediate fault handler for this message.
+            synMessageContext.pushFaultHandler(this);
             endpoint.send(synMessageContext);
-
         } else {
             // if this is a child of some other endpoint, inform parent about the failure.
             // if not, inform to the next fault handler.
@@ -217,4 +176,17 @@
                         synCtx.getTracingState() == SynapseConstants.TRACING_ON));
     }
 
+    public void onFault(MessageContext synMessageContext) {
+        // At this point,child endpoint is in inactive state
+        // if this is a child of some other endpoint, inform parent about the failure.
+        // if not, inform to the next fault handler.
+        if (parentEndpoint != null) {
+            parentEndpoint.onChildEndpointFail(this, synMessageContext);
+        } else {
+            Object o = synMessageContext.getFaultStack().pop();
+            if (o != null) {
+                ((FaultHandler) o).handleFault(synMessageContext);
+            }
+        }
+    }
 }