You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by sa...@apache.org on 2005/11/02 14:49:32 UTC

svn commit: r330252 - in /incubator/synapse/trunk/scratch/prototype1: src/org/apache/synapse/ src/org/apache/synapse/engine/ src/org/apache/synapse/rule/ src/org/apache/synapse/samples/ src/org/apache/synapse/samples/mediators/ test/org/apache/synapse/...

Author: saminda
Date: Wed Nov  2 05:49:12 2005
New Revision: 330252

URL: http://svn.apache.org/viewcvs?rev=330252&view=rev
Log:
1. RuleSelectorImpl updated
2. Rules updated to handle xpath
3. SynapseDeployer update
4. Two very simple test cases added to test SynapseDeployer and RuleSelectorImpl
5. Two simple dummy mediators added
6. synapse.xml changed 

Added:
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java
    incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/
    incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java
    incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/
    incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/RuleSelectorImplTest.java
Modified:
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/SynapseConstants.java
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/SynapseDeployer.java
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/synapse.xml
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/Rule.java
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelector.java
    incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/SynapseConstants.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/SynapseConstants.java?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/SynapseConstants.java (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/SynapseConstants.java Wed Nov  2 05:49:12 2005
@@ -8,8 +8,8 @@
     public static final String SYNAPSE_ENGINE = "Synapse Engine";
     String SYNAPSE_SERVICE ="SynapseServie";
     String SYNAPSE_OPERATION ="SynapseOp";
-    String DIRECTION_IN ="incomming" ;
-    String DIRECTION_OUT ="outgoing" ;
+    String DIRECTION_IN ="INCOMING" ;
+    String DIRECTION_OUT ="OUTGOING" ;
     String DIRECTION ="direction" ;
     String STAGE_IN ="IN" ;
     String STAGE_PROCESS ="PROCESS" ;

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/SynapseDeployer.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/SynapseDeployer.java?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/SynapseDeployer.java (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/SynapseDeployer.java Wed Nov  2 05:49:12 2005
@@ -54,7 +54,7 @@
             StAXOMBuilder staxOMBuilder = new StAXOMBuilder(fac, xmlReader);
             OMElement element = staxOMBuilder.getDocumentElement();
             element.build();
-            Iterator disElements = element.getChildrenWithName(new QName(SynapseConstants.DIRECTION_IN));
+            Iterator disElements = element.getChildElements();
             while (disElements.hasNext()) {
                 OMElement omElement = (OMElement) disElements.next();
                 OMAttribute nameatt = omElement.getAttribute(new QName("name"));

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/synapse.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/synapse.xml?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/synapse.xml (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/engine/synapse.xml Wed Nov  2 05:49:12 2005
@@ -1,19 +1,24 @@
 <synapse>
-    <direction name="incomming">
+    <direction name="INCOMING">
         <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="IN">
             <rule name="Rule1">
                 <xpath>*</xpath>
-                <mediator name="Log"/>
-                <!--<mediator>Log</mediator>-->
+                <mediator name="Log" class="org.apache.synapse.samples.mediators.LogMediator"/>
+                <mediator name="Admin_Log" class="org.apache.synapse.samples.mediators.AdminMediator">
+                    <parameter>wsa:to='http://cnn.com'</parameter>
+                </mediator>
                 <qos>Addressing</qos>
             </rule>
         </ruleSet>
-        <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="PROCESS"/>
+        <ruleSet class="
+                      org.apache.synapse.rule.RuleSelectorImpl"
+                 stage="PROCESS"/>
         <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="OUT"/>
     </direction>
-    <direction name="outgoing">
+    <direction name="OUTGOING">
         <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="IN"/>
-        <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="PROCESS"/>
+        <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl"
+                 stage="PROCESS"/>
         <ruleSet class="org.apache.synapse.rule.RuleSelectorImpl" stage="OUT"/>
     </direction>
 </synapse>

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/Rule.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/Rule.java?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/Rule.java (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/Rule.java Wed Nov  2 05:49:12 2005
@@ -11,6 +11,7 @@
     private Mediator[] mediators;
     private List qosModules;
     private String name;
+    private String xpath;
 
     public Mediator[] getMediators() {
         return mediators;
@@ -34,5 +35,11 @@
 
     public void setName(String name) {
         this.name = name;
+    }
+    public String getXpath() {
+        return xpath;
+    }
+    public void setXpath(String xpath) {
+        this.xpath = xpath;    
     }
 }

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelector.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelector.java?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelector.java (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelector.java Wed Nov  2 05:49:12 2005
@@ -3,6 +3,7 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.om.OMElement;
 import org.apache.synapse.rule.Rule;
+import org.apache.synapse.SynapseException;
 
 import java.util.Iterator;
 
@@ -16,7 +17,7 @@
      * a particular stage for a given direction
      * In other words, RuleSelector should be created per stage per direction
      */
-    public void init(OMElement ruleSet);
+    public void init(OMElement ruleSet) throws SynapseException;
 
 
     Rule [] getRules();

Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java?rev=330252&r1=330251&r2=330252&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java (original)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java Wed Nov  2 05:49:12 2005
@@ -5,6 +5,8 @@
 import org.apache.axis2.om.OMAttribute;
 import org.apache.synapse.rule.Rule;
 import org.apache.synapse.rule.RuleSelector;
+import org.apache.synapse.mediator.Mediator;
+import org.apache.synapse.SynapseException;
 
 import javax.xml.namespace.QName;
 import java.util.Iterator;
@@ -22,21 +24,32 @@
      * a particular stage for a given direction
      * In other words, RuleSelector should be created per stage per direction
      */
-    public void init(OMElement ruleSet) {
+    public void init(OMElement ruleSet) throws SynapseException {
         ArrayList ruleslist = new ArrayList();
         Iterator itsruls = ruleSet.getChildrenWithName(new QName("rule"));
         while (itsruls.hasNext()) {
-            OMElement ruleelement = (OMElement) itsruls.next();
-            OMAttribute attributeName = ruleelement.getAttribute(new QName("name"));
+            OMElement ruleElement = (OMElement) itsruls.next();
+            OMAttribute attributeName = ruleElement.getAttribute(new QName("name"));
             if(attributeName != null){
                 String rulename = attributeName.getAttributeValue();
                 Rule rule = new Rule();
-                Iterator mediatoes =  ruleelement.getChildrenWithName(new QName("mediator"));
+                Iterator mediatoes =  ruleElement.getChildrenWithName(new QName("mediator"));
+                ArrayList mediatorList = new ArrayList();
                 while (mediatoes.hasNext()) {
                     OMElement mediatorElement = (OMElement) mediatoes.next();
-                    OMAttribute mediatorName = mediatorElement.getAttribute(new QName("name"));
+                    OMAttribute mediatorName = mediatorElement.getAttribute(new QName("name")); //what is the use of this
+                    OMAttribute mediatorImplClass = mediatorElement.getAttribute(new QName("class"));
+
+                    try {
+                        Mediator mediator = (Mediator) Class.forName(mediatorImplClass.getAttributeValue()).newInstance();
+                        mediatorList.add(mediator);
+                    } catch (Exception e){
+                        throw new SynapseException(e);
+                    }
+
                     //todo: Deepal mediator has to create and add the rule
                 }
+                rule.setMediators((Mediator[])mediatorList.toArray(new Mediator[mediatorList.size()]));
                 rule.setName(rulename);
                 ruleslist.add(rule);
             }

Added: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java?rev=330252&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java (added)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java Wed Nov  2 05:49:12 2005
@@ -0,0 +1,34 @@
+package org.apache.synapse.samples.mediators;
+
+import org.apache.synapse.mediator.Mediator;
+import org.apache.axis2.context.MessageContext;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+public class AdminMediator implements Mediator {
+    public boolean mediate(MessageContext messageContext) {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void addParameter(String key, Object value) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Object getParameter(String key) {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java?rev=330252&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java (added)
+++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java Wed Nov  2 05:49:12 2005
@@ -0,0 +1,34 @@
+package org.apache.synapse.samples.mediators;
+
+import org.apache.synapse.mediator.Mediator;
+import org.apache.axis2.context.MessageContext;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+public class LogMediator implements Mediator {
+    public boolean mediate(MessageContext messageContext) {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void addParameter(String key, Object value) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Object getParameter(String key) {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java?rev=330252&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java (added)
+++ incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java Wed Nov  2 05:49:12 2005
@@ -0,0 +1,58 @@
+package org.apache.synapse.engine;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+import org.apache.synapse.rule.RuleSelectorImpl;
+import org.apache.synapse.rule.Rule;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+public class SynapseDeployerTest extends TestCase {
+
+    public void testSynapseDeployer() throws Exception {
+        String file = "/home/saminda/myprojects/scratch-synapse/scratch/prototype1/src/org/apache/synapse/engine";
+        File in = new File (file,"synapse.xml");
+        SynapseDeployer deployer = new SynapseDeployer(in);
+
+        SynapseConfiguration config = deployer.populteConfig();
+        System.out.println(config.getIncomingPreStageRuleSet());
+        System.out.println(config.getIncomingProcessingStageRuleSet().toString());
+        System.out.println(config.getIncomingPostStageRuleSet().toString());
+
+        System.out.println(config.getOutgoingPreStageRuleSet().toString());
+        System.out.println(config.getOutgoingProcessingStageRuleSet());
+        System.out.println(config.getOutgoingPostStageRuleSet());
+
+        RuleSelectorImpl selectorImpl = new RuleSelectorImpl();
+        selectorImpl.init(config.getIncomingPreStageRuleSet());
+
+        Rule[] rules = selectorImpl.getRules();
+        for (int i = 0 ; i < rules.length ; i++) {
+            Rule pertRule = rules[i];
+            System.out.println(pertRule.getName());
+            System.out.println(pertRule.getMediators());
+
+        }
+
+
+
+    }
+
+}

Added: incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/RuleSelectorImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/RuleSelectorImplTest.java?rev=330252&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/RuleSelectorImplTest.java (added)
+++ incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/rule/RuleSelectorImplTest.java Wed Nov  2 05:49:12 2005
@@ -0,0 +1,25 @@
+package org.apache.synapse.rule;
+
+import junit.framework.TestCase;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+public class RuleSelectorImplTest extends TestCase {
+    public void testRuleSelector() throws Exception {
+        
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org