synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r321063 - in /incubator/synapse/trunk/scratch/saminda/src/org/apache: client/ synapse/ synapse/dispatchers/ synapse/engine/ synapse/mediators/ synapse/mediators/META-INF/ synapse/receivers/ synapse/rules/
Date Fri, 14 Oct 2005 09:42:33 GMT
Author: saminda
Date: Fri Oct 14 02:42:13 2005
New Revision: 321063

URL: http://svn.apache.org/viewcvs?rev=321063&view=rev
Log:
More robust scratch code for synapse

Modified:
    incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SampleClient.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SimpleServer.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/SynapseConstants.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/dispatchers/SynapseBaseDispatcher.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/engine/SynapseEngine.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/META-INF/synapse.xml
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/SimpleLoggingMediator.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/receivers/SynapseMessageReceiver.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/RuleBean.java
    incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/SynapseRuleEngine.java

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SampleClient.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SampleClient.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SampleClient.java (original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SampleClient.java Fri Oct
14 02:42:13 2005
@@ -18,7 +18,7 @@
  */
 public class SampleClient {
     private static EndpointReference targetEPR = new EndpointReference(
-            "http://localhost:8080/");
+            "http://localhost:8081/");
 
     public static void main(String[] args) {
         try {

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SimpleServer.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SimpleServer.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SimpleServer.java (original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/client/SimpleServer.java Fri Oct
14 02:42:13 2005
@@ -13,7 +13,7 @@
 public class SimpleServer {
     public static void main(String[] args ) {
         try {
-            SimpleSynapseServer sss = new SimpleSynapseServer("/home/saminda/myprojects/synapse/server",8080);
+            SimpleSynapseServer sss = new SimpleSynapseServer("/home/saminda/myprojects/synapse1/server",8081);
             sss.start();
         } catch (AxisFault axisFault) {
             axisFault.printStackTrace();

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/SynapseConstants.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/SynapseConstants.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/SynapseConstants.java (original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/SynapseConstants.java Fri
Oct 14 02:42:13 2005
@@ -19,4 +19,10 @@
         public static final String CONDITION = "condition";
         public static final String MEDIATOR = "mediator";
     }
+    public interface SynapseRuleEngine {
+        public static final String GENERAT_RULE_ARRAY_LIST = "generalRules";
+        public static final String XPATH_RULE_ARRAY_LIST= "xpathRules";
+        public static final String SYNAPSE_RECEIVER = "receiver";
+        public static final String SYNAPSE_RULE_ENGINE= "synapseRuleEngine";
+    }
 }

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/dispatchers/SynapseBaseDispatcher.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/dispatchers/SynapseBaseDispatcher.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/dispatchers/SynapseBaseDispatcher.java
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/dispatchers/SynapseBaseDispatcher.java
Fri Oct 14 02:42:13 2005
@@ -7,7 +7,6 @@
 import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
 import org.apache.synapse.rules.SynapseRuleEngine;
 import org.apache.synapse.rules.RuleBean;
 import org.apache.synapse.SynapseConstants;
@@ -27,20 +26,6 @@
     protected QName operationName;
 
 
-    /**
-     * Rules which is going to be populated via services.xml
-     */
-    protected SynapseRuleEngine ruleEngine;
-
-    /**
-     * to keep the state
-     */
-    private int synapseState = 0;
-
-    public SynapseBaseDispatcher() {
-        ruleEngine = new SynapseRuleEngine();
-    }
-
     public void initDispatcher() {
         init(new HandlerDescription(NAME));
     }
@@ -48,48 +33,26 @@
     public ServiceDescription findService(MessageContext messageContext)
             throws AxisFault {
 
-        /**
-         * testing the rule searching.
-         *
-         */
-        Object ruleObj = messageContext
-                .getProperty(SynapseConstants.RULE_STATE);
-        if (ruleObj == null) {
-            ruleEngine.ruleConfiguration(messageContext);
-            messageContext.setProperty(SynapseConstants.RULE_STATE, ruleEngine);
-        }
+        String opName = (String) messageContext.getProperty(
+                SynapseConstants.SynapseRuleEngine.SYNAPSE_RECEIVER);
 
-        /**
-         * here "*" all will be handled.
-         */
-        operationName = new QName(this.ruleEngine.getOperationName());
-
-        /**
-         * mediator selection
-         */
+        operationName = new QName(opName);
 
+        ArrayList generalList = (ArrayList) messageContext.getProperty(
+                SynapseConstants.SynapseRuleEngine.GENERAT_RULE_ARRAY_LIST);
         Integer state = (Integer) messageContext
                 .getProperty(SynapseConstants.SYNAPSE_STATE);
-        if (state != null) {
-            synapseState = state.intValue();
-        } else {
-            synapseState = 1;
-        }
-
-        String key = null;
-        if (synapseState == 1) {
-            key = mediatorType(messageContext, ruleEngine, synapseState);
-        } else {
-            key = mediatorType(messageContext, ruleEngine, synapseState);
+        RuleBean bean = null;
+        if (state.intValue() <= generalList.size()) {
+            bean = (RuleBean) generalList.get(state.intValue()-1);
         }
-        serviceName = key;
+        serviceName = bean.getMediator();
 
         AxisConfiguration registry =
                 messageContext.getSystemContext()
                         .getAxisConfiguration();
         return registry.getService(serviceName);
 
-
     }
 
     public OperationDescription findOperation(
@@ -101,27 +64,5 @@
             return operationDis;
         }
         return null;
-    }
-
-    private String mediatorType(MessageContext messageContext,
-                                SynapseRuleEngine ruleEngine,
-                                int synapseState) {
-        ArrayList ruleArrayList = ruleEngine.getArrayList();
-        String key = null;
-        Integer state = null;
-        if (synapseState <= ruleArrayList.size()) {
-            String rule = (String) ruleArrayList.get(synapseState - 1);
-            if (synapseState == ruleArrayList.size()) {
-                messageContext.setProperty(SynapseConstants.VALUE_FALSE,
-                        new Boolean(false));
-            } else {
-                state = new Integer(++synapseState);
-                messageContext
-                        .setProperty(SynapseConstants.SYNAPSE_STATE, state);
-            }
-
-            key = rule;
-        }
-        return key;
     }
 }

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/engine/SynapseEngine.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/engine/SynapseEngine.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/engine/SynapseEngine.java
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/engine/SynapseEngine.java
Fri Oct 14 02:42:13 2005
@@ -2,14 +2,19 @@
 
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.clientapi.MessageSender;
+import org.apache.axis2.soap.SOAPEnvelope;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.axis2.addressing.MessageInformationHeaders;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.miheaders.RelatesTo;
 import org.apache.synapse.SynapseConstants;
-
-import java.util.LinkedList;
-import java.util.ArrayList;
+import org.apache.synapse.rules.SynapseRuleEngine;
+import org.jaxen.JaxenException;
 
 /**
  * Created by IntelliJ IDEA.
@@ -19,8 +24,17 @@
  * To change this template use File | Settings | File Templates.
  */
 public class SynapseEngine {
+
     private AxisEngine axisEngine;
 
+    private SynapseRuleEngine ruleEngine;
+
+    private int synapseState = 0;
+
+    public SynapseEngine() {
+        ruleEngine = new SynapseRuleEngine();
+    }
+
     public AxisEngine getAxisEngine() {
         return axisEngine;
     }
@@ -31,6 +45,26 @@
 
     public void excecuite(MessageContext messageContext) throws AxisFault {
 
+        messageContext.setProperty(
+                SynapseConstants.SynapseRuleEngine.SYNAPSE_RECEIVER,
+                ruleEngine.getOperationName());
+        ruleEngine.ruleConfiguration(messageContext);
+
+
+        try {
+            ruleEngine.validateXpath(messageContext);
+            messageContext.setProperty(
+                    SynapseConstants.SynapseRuleEngine.SYNAPSE_RULE_ENGINE,
+                    ruleEngine);
+        } catch (JaxenException e) {
+            throw new AxisFault(e);
+        }
+
+        messageContext
+                .setProperty(SynapseConstants.SYNAPSE_STATE,
+                        synapseStateValidation(messageContext));
+
+
         if (axisEngine != null) {
             if (messageContext.getEnvelope().getBody().hasFault()) {
                 axisEngine.receiveFault(messageContext);
@@ -38,14 +72,21 @@
                 axisEngine.receive(messageContext);
             }
             /**
-             * Once the control return we would decide how to do the rule maching next
+             * Now the looping happens for new Rules
+             *
              */
 
+            moreRules(messageContext);
             /**
-             * recursivly check for more rules.
+             * If no rules available then time the message to reach its orgianl
+             * destiantion, so at this point Synapse will be the client
+             *
+             * engine.send(MessageContext) will be called at the end.
+             *
              */
+            synapseAsClient(messageContext);
+
 
-            moreRules(messageContext);
 
         }
 
@@ -58,8 +99,11 @@
         Boolean returnValue = (Boolean) returnMsgCtx
                 .getProperty(SynapseConstants.MEDEATOT_STATE);
         if (!returnValue.booleanValue()) {
-            return ;
+            return;
         } else {
+            /**
+             * states related to Synapse
+             */
             MessageContext newContext = new MessageContext(
                     returnMsgCtx.getSystemContext());
             newContext.setProperty(SynapseConstants.MEDEATOT_STATE,
@@ -71,15 +115,52 @@
                     returnMsgCtx.getProperty(SynapseConstants.VALUE_FALSE));
             newContext.setProperty(SynapseConstants.RULE_STATE,
                     returnMsgCtx.getProperty(SynapseConstants.RULE_STATE));
+            newContext.setProperty(
+                    SynapseConstants.SynapseRuleEngine.SYNAPSE_RECEIVER,
+                    returnMsgCtx.getProperty(
+                            SynapseConstants.SynapseRuleEngine.SYNAPSE_RECEIVER));
+            newContext.setProperty(
+                    SynapseConstants.SynapseRuleEngine.GENERAT_RULE_ARRAY_LIST,
+                    returnMsgCtx.getProperty(
+                            SynapseConstants.SynapseRuleEngine.GENERAT_RULE_ARRAY_LIST));
             newContext.setServerSide(true);
             newContext.setEnvelope(returnMsgCtx.getEnvelope());
             newContext.setServiceContextID(returnMsgCtx.getServiceContextID());
-            newContext.setWSAAction(returnMsgCtx.getWSAAction());
-            newContext.setSoapAction(returnMsgCtx.getSoapAction());
             axisEngine.receive(newContext);
             moreRules(newContext);
-            return ;
+            return;
+        }
+    }
+
+    public Integer synapseStateValidation(MessageContext messageContext) {
+        Integer state = (Integer) messageContext
+                .getProperty(SynapseConstants.SYNAPSE_STATE);
+
+        if (state == null) {
+            synapseState = 1;
+            return new Integer(synapseState);
+        } else {
+            return state;
         }
+    }
+
+    private void synapseAsClient(MessageContext messageContext)
+            throws AxisFault {
+        SOAPEnvelope env = messageContext.getEnvelope();
+        //just for the sake of clarity nothing else
+        //need to do more code once the architecture is finalize
+        EndpointReference epr = new EndpointReference(
+                "http://localhost:8080/axis2/services/MyService");
+
+        MessageSender msgSender = new MessageSender();
+        msgSender.setTo(epr);
+        msgSender.setSenderTransport(Constants.TRANSPORT_HTTP);
+
+        //need more modification here..
+        //need to do more modification once the architecure is finalize..
+
+        msgSender.send("ping", env.getBody().getFirstElement());
+
     }
 
 }

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/META-INF/synapse.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/META-INF/synapse.xml?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/META-INF/synapse.xml
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/META-INF/synapse.xml
Fri Oct 14 02:42:13 2005
@@ -5,18 +5,10 @@
     </rule>
     <rule>
         <condition>*</condition>
-        <mediator>Log</mediator>
-    </rule>
-    <rule>
-        <condition>*</condition>
-        <mediator>Log</mediator>
-    </rule>
-    <rule>
-        <condition>*</condition>
         <mediator>Log_1</mediator>
     </rule>
     <rule>
         <condition>*</condition>
-        <mediator>Log_1</mediator>
-    </rule>
+        <mediator>Log</mediator>
+    </rule>    
 </rules>

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/SimpleLoggingMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/SimpleLoggingMediator.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/SimpleLoggingMediator.java
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/mediators/SimpleLoggingMediator.java
Fri Oct 14 02:42:13 2005
@@ -11,23 +11,20 @@
  * Time: 5:34:01 PM
  * To change this template use File | Settings | File Templates.
  */
-public class SimpleLoggingMediator implements Mediator{
+public class SimpleLoggingMediator implements Mediator {
     /**
      * Do Some mediation and return true/false
      * false means, mediator consumes the message
      * ture means, medator return for that message, to deal with another Rule
+     *
      * @param msgContext
      * @return Boolean
      */
     public boolean mediate(MessageContext msgContext) throws AxisFault {
         System.out.println("i'm doing the logging mediation...now");
-        Boolean retbool = (Boolean) msgContext
-                .getProperty(SynapseConstants.VALUE_FALSE);
-        if (retbool != null) {
-            return false;
-        } else {
-            return true;
-        }
+
+        return false;
+
     }
 
 }

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/receivers/SynapseMessageReceiver.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/receivers/SynapseMessageReceiver.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/receivers/SynapseMessageReceiver.java
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/receivers/SynapseMessageReceiver.java
Fri Oct 14 02:42:13 2005
@@ -63,7 +63,11 @@
              * Injecting messageContext for medaite method
              * Will not be on use in the M1
              */
+
+            Integer oldSynapseState = (Integer)msgContext.getProperty(SynapseConstants.SYNAPSE_STATE);
             Boolean mediatorState = DependencyManager.mediatorBusinessLogicProvider(obj,
msgContext);
+
+            msgContext.setProperty(SynapseConstants.SYNAPSE_STATE,new Integer((oldSynapseState.intValue())+1));
             msgContext.setProperty(SynapseConstants.MEDEATOT_STATE,mediatorState);
 
         } catch (Exception e) {

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/RuleBean.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/RuleBean.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/RuleBean.java (original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/RuleBean.java Fri
Oct 14 02:42:13 2005
@@ -8,21 +8,21 @@
  * To change this template use File | Settings | File Templates.
  */
 public class RuleBean {
-    private String condition;
-    private String mediatation;
+    private String condition; // this is the xpath of the messagte
+    private String mediator; // is the mediator we need at this point 
 
     public void setCondition(String condition) {
         this.condition = condition;
     }
     public void setMediate(String mediatation) {
-        this.mediatation = mediatation;
+        this.mediator = mediatation;
     }
 
     public String getCondition(){
         return condition;
     }
-    public String getMediatation() {
-        return mediatation;   
+    public String getMediator() {
+        return mediator;
     }
 
 }

Modified: incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/SynapseRuleEngine.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/SynapseRuleEngine.java?rev=321063&r1=321062&r2=321063&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/SynapseRuleEngine.java
(original)
+++ incubator/synapse/trunk/scratch/saminda/src/org/apache/synapse/rules/SynapseRuleEngine.java
Fri Oct 14 02:42:13 2005
@@ -3,6 +3,11 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.om.xpath.AXIOMXPath;
+import org.apache.synapse.SynapseConstants;
+import org.jaxen.XPath;
+import org.jaxen.JaxenException;
+import org.jaxen.SimpleNamespaceContext;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -17,16 +22,24 @@
  * To change this template use File | Settings | File Templates.
  */
 public class SynapseRuleEngine {
-
+    /**
+     * this is the reference parameter to the MessageReceiver that
+     * should be used
+     */
     private String operationName = "receiver";
 
     private SynapseRuleReader ruleReader;
 
-    private ArrayList ruleList;
+    private ArrayList mediatorList;
+
+    private ArrayList generalRuleList; // contains the beans of Rules
+    private ArrayList xpathRuleList;   //contains the beans of Rules
 
     public SynapseRuleEngine() {
         ruleReader = new SynapseRuleReader();
-        ruleList = new ArrayList();
+        mediatorList = new ArrayList();
+        generalRuleList = new ArrayList();
+        xpathRuleList = new ArrayList();
     }
 
     public void ruleConfiguration(MessageContext msgCtx) throws AxisFault {
@@ -48,12 +61,9 @@
 
             while (iterator.hasNext()) {
                 RuleBean bean = (RuleBean) iterator.next();
-                /**
-                 * Rulling logic goes here
-                 */
 
-                if (bean.getMediatation().equalsIgnoreCase(key)) {
-                    this.ruleList.add(key);
+                if (bean.getMediator().equalsIgnoreCase(key)) {
+                    this.mediatorList.add(key);
                 }
             }
 
@@ -68,7 +78,46 @@
         return operationName;
     }    
 
-    public ArrayList getArrayList() {
-        return ruleList;
+    public ArrayList getArrayofMediatorList() {
+        return mediatorList;
+    }
+    public ArrayList getArrayofGeneralRuleList() {
+        return generalRuleList;
+    }
+    public ArrayList getArrayofXpathRuleList() {
+        return xpathRuleList;
+    }
+
+    public void validateXpath(MessageContext messageContext)
+            throws JaxenException {
+        Iterator ruleIte = ruleReader.getRulesIterator();
+
+        while (ruleIte.hasNext()) {
+            // genertal rule handling with "*"
+            RuleBean bean = (RuleBean)ruleIte.next();
+
+            if (bean.getCondition().equals("*")){
+                // this could be more than this.
+                this.generalRuleList.add(bean);
+            } else {
+                // which deal with the xpath of the message
+                String xpathExpression = bean.getCondition();
+                XPath xpath = new AXIOMXPath(xpathExpression);
+
+                //settingup the namespace which needed to be dealt with care
+                SimpleNamespaceContext nameSpace = new SimpleNamespaceContext();
+                //add the relevent name spaces
+                xpath.setNamespaceContext(nameSpace);
+
+                boolean xpathBool = xpath.booleanValueOf(nameSpace);
+
+                if (xpathBool) {
+                    this.xpathRuleList.add(bean);
+                }
+            }
+        }
+        messageContext.setProperty(SynapseConstants.SynapseRuleEngine.GENERAT_RULE_ARRAY_LIST,
generalRuleList);
+        messageContext.setProperty(SynapseConstants.SynapseRuleEngine.XPATH_RULE_ARRAY_LIST,
xpathRuleList);
     }
+
 }



Mime
View raw message