Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/OnceRuleEngine.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/OnceRuleEngine.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/OnceRuleEngine.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/OnceRuleEngine.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,92 @@
+/*

+ * 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.

+ */

+package org.apache.synapse.ruleEngines;

+

+import java.util.Iterator;

+import java.util.LinkedList;

+import java.util.List;

+

+import javax.xml.namespace.QName;

+

+

+import org.apache.axis2.om.OMElement;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+

+

+import org.apache.synapse.SynapseException;

+import org.apache.synapse.api.MediatorConfiguration;

+import org.apache.synapse.api.SOAPMessageContext;

+import org.apache.synapse.api.SynapseEnvironment;

+import org.apache.synapse.spi.RuleEngine;

+

+// This implements a class of rule engine. These rule engines have a specific

+// behaviour which is to

+// 

+public abstract class OnceRuleEngine implements RuleEngine {

+

+       Log log = LogFactory.getLog(getClass());

+       private List rules = new LinkedList();

+       

+

+       public abstract RuleCondition getRuleCondition(OMElement om);

+

+       public abstract QName getRuleQName();

+

+       public void init(OMElement om, ClassLoader cl) {

+               log.debug("initialising rule engine"+om.toString());

+               Iterator it = om.getChildrenWithName(getRuleQName());

+               if (!it.hasNext()) { throw new SynapseException("no rules in 
stage"+om.toString()); }

+               while (it.hasNext()) {

+                       OMElement rule = (OMElement) it.next();

+                       RuleCondition rc = getRuleCondition(rule);

+                       Rule ra = new Rule();

+                       ra.init(rule, cl);

+                       ra.setRuleCondition(rc);

+                       rules.add(ra);

+               }

+

+       }

+

+       public boolean process(SynapseEnvironment se, SOAPMessageContext smc) {

+               log.debug("processing message "+smc.getEnvelope());

+               

+               Iterator it = rules.iterator();

+               while (it.hasNext()) {

+

+                       Rule ra = (Rule) it.next();

+                       RuleCondition rc = ra.getRuleCondition();

+                       if (rc.matches(smc)) {

+                               log.info("matched: 
"+ra.getRuleCondition().toString());

+                               List medConfigs = 
ra.getMediatorConfigurations();

+                               if (medConfigs==null) return true;

+                               Iterator mcs = medConfigs.iterator();

+                               while (mcs.hasNext()) {

+                                       MediatorConfiguration mc = 
(MediatorConfiguration)mcs.next();

+                                       boolean ret = se.executeMediator(mc, 
smc);

+                                       if (!ret) return false;

+                               }

+                               

+                       }

+                       else {

+                               log.info("did NOT 
match"+ra.getRuleCondition().toString());

+                       }

+               }

+               return true;

+       }

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RegexRuleEngine.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RegexRuleEngine.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RegexRuleEngine.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RegexRuleEngine.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,47 @@
+/*

+ * 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.

+ */

+package org.apache.synapse.ruleEngines;

+

+

+import org.apache.axis2.om.OMElement;

+

+

+import org.apache.synapse.api.SOAPMessageContext;

+import org.apache.synapse.api.SynapseEnvironment;

+import org.apache.synapse.spi.RuleEngine;

+

+public class RegexRuleEngine implements RuleEngine {

+

+       

+       // TBD

+       public String getRulesetType() {

+               return RuleEngineTypes.REGEX;

+       }

+

+

+

+

+       public boolean process(SynapseEnvironment sc, SOAPMessageContext smc) {

+               // TODO Auto-generated method stub

+               return false;

+       }

+

+       public void init(OMElement om, ClassLoader cl) {

+               // TODO Auto-generated method stub

+               

+       }

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/Rule.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/Rule.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/Rule.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/Rule.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,54 @@
+package org.apache.synapse.ruleEngines;

+

+import java.util.List;

+import java.util.Iterator;

+import java.util.LinkedList;

+

+import org.apache.axis2.om.OMAttribute;

+import org.apache.axis2.om.OMElement;

+import org.apache.synapse.Constants;

+import org.apache.synapse.SynapseException;

+import org.apache.synapse.api.MediatorConfiguration;

+import org.apache.synapse.mediators.MediatorTypes;

+import org.apache.synapse.spi.MediatorConfigurator;

+

+public class Rule {

+       private RuleCondition rc = null;

+       private List mcs = new LinkedList();

+       

+       

+       public void init(OMElement ruleContainer, ClassLoader cl) {

+               Iterator it = 
ruleContainer.getChildrenWithName(Constants.MEDIATOR_Q);

+               

+               if (!it.hasNext()) { throw new SynapseException("no mediators 
defined on rule"+ruleContainer.toString());}

+               while (it.hasNext()) {

+                       OMElement med = (OMElement)it.next(); 

+                       OMAttribute type = 
med.getAttribute(Constants.TYPE_ATT_Q);

+                       if (type==null) throw new SynapseException("no type 
declaration on "+med.toString());

+                       MediatorConfigurator config = 
MediatorTypes.getMediatorConfigurator(type.getAttributeValue());

+                       if (config!=null) {

+                               MediatorConfiguration mc = config.parse(med, 
cl);

+                               if (mc!=null) {

+                                       mcs.add(mc);

+                               }

+                               else throw new SynapseException("failed to 
parse mediator component"+med.toString());

+                       }

+                       else throw new SynapseException("could not find 
mediator configurator for type "+type.getAttributeValue());                     
        

+               }

+               // deal with QoS apply elements here TODO

+       }

+       

+       //public QoS getQoS();

+       

+       public List getMediatorConfigurations() {

+               return mcs;

+       }

+       

+       public RuleCondition getRuleCondition() {

+               return rc;

+       }

+       public void setRuleCondition(RuleCondition rc) {

+               this.rc = rc;

+       }

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleCondition.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleCondition.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleCondition.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleCondition.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,13 @@
+package org.apache.synapse.ruleEngines;

+

+import org.apache.synapse.api.SOAPMessageContext;

+

+

+

+

+

+public interface RuleCondition {

+

+       boolean matches(SOAPMessageContext smc);

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleEngineTypes.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleEngineTypes.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleEngineTypes.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/RuleEngineTypes.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,35 @@
+/*

+ * 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.

+ */

+package org.apache.synapse.ruleEngines;

+

+import org.apache.synapse.spi.RuleEngine;

+

+public class RuleEngineTypes {

+       // this class could be replaced with a dynamic registry bootstrapped 
using JAR services 

+       

+       public static final String XPATH="xpath";

+       public static final String REGEX="regex";

+       public static final String ALL="all";

+       

+       

+       public static RuleEngine getRuleEngine(String type) {

+               if (type.toLowerCase().equals(XPATH)) return new 
XPathRuleEngine();

+               else if (type.toLowerCase().equals(REGEX)) return new 
RegexRuleEngine();

+               else if (type.toLowerCase().equals(ALL)) return new 
AllRuleEngine();

+               return null;

+       }

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/XPathRuleEngine.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/XPathRuleEngine.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/XPathRuleEngine.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/ruleEngines/XPathRuleEngine.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,72 @@
+package org.apache.synapse.ruleEngines;

+

+import java.util.Iterator;

+

+import javax.xml.namespace.QName;

+

+

+import org.apache.axis2.om.OMAttribute;

+import org.apache.axis2.om.OMElement;

+import org.apache.axis2.om.OMNamespace;

+import org.apache.axis2.om.xpath.AXIOMXPath;

+

+import org.apache.synapse.Constants;

+

+import org.apache.synapse.SynapseException;

+import org.apache.synapse.api.SOAPMessageContext;

+import org.jaxen.JaxenException;

+

+public class XPathRuleEngine extends OnceRuleEngine {

+       private static final String XPATH="xpath";

+       private static final QName XPATH_RULE_Q = new QName(

+                       Constants.SYNAPSE_NAMESPACE, "rule");

+       private static final QName XPATH_CONDITION_ATT_Q = new QName(XPATH); 

+

+       public RuleCondition getRuleCondition(OMElement om) {

+               OMAttribute xpath=om.getAttribute(XPATH_CONDITION_ATT_Q);

+               if (xpath==null) {

+                       throw new SynapseException("rule must have xpath 
attribute: "+om.toString());

+               }

+               RuleCondition rc = null;

+               try {

+                       

+                       rc = new 
XPathRuleCondition(om.getAllDeclaredNamespaces(), 
xpath.getAttributeValue().trim());

+               }

+               catch (JaxenException e) {

+                       throw new SynapseException("Problem with xpath 
expression "+xpath.getAttributeValue(), e);

+               }

+               return rc;

+       }

+

+       public QName getRuleQName() {

+               return XPATH_RULE_Q;

+       }

+

+       protected class XPathRuleCondition implements RuleCondition {

+               private AXIOMXPath xp = null;

+               protected XPathRuleCondition(Iterator namespaces, String xpath) 
throws JaxenException {

+                       

+                       this.xp = new AXIOMXPath(xpath);

+                       while (namespaces!=null && namespaces.hasNext()) {

+                               OMNamespace n = (OMNamespace)namespaces.next();

+                               xp.addNamespace(n.getPrefix(),n.getName());

+                       }

+               }

+               

+               public boolean matches(SOAPMessageContext smc) {

+                       try {

+                               return xp.booleanValueOf(smc.getEnvelope());

+                       } catch (JaxenException e) {

+                               throw new SynapseException ("Problem trying to 
evaluate XPATH "+xp.getRootExpr()+" on "+smc.getEnvelope().toString(),e);

+                               

+                       }

+               }

+               public String toString() { return "xpath: 
"+xp.getRootExpr().getText(); }

+       }

+

+       public String getRulesetType() {

+               

+               return XPATH;

+       }

+       

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/MediatorConfigurator.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/MediatorConfigurator.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/MediatorConfigurator.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/MediatorConfigurator.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,24 @@
+/*

+ * 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.

+ */

+package org.apache.synapse.spi;

+

+import org.apache.axis2.om.OMElement;

+import org.apache.synapse.api.MediatorConfiguration;

+

+public interface MediatorConfigurator {

+           public MediatorConfiguration parse(OMElement el, ClassLoader cl);

+       

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/RuleEngine.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/RuleEngine.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/RuleEngine.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/org/apache/synapse/spi/RuleEngine.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,34 @@
+/*

+ * 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.

+ */

+package org.apache.synapse.spi;

+

+

+import org.apache.axis2.om.OMElement;

+import org.apache.synapse.api.SOAPMessageContext;

+import org.apache.synapse.api.SynapseEnvironment;

+

+public interface RuleEngine {

+

+       public String getRulesetType();

+

+       public void init(OMElement om, ClassLoader cl); // gets passed the 
<synapse:ruleset>

+                                                                       // 
element.

+

+       public boolean process(SynapseEnvironment sc, SOAPMessageContext smc); 
// stateless

+                                                                               
                                                        // per

+                                                                               
                                                        // invocation

+

+}


Added: 
incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/Logger.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/Logger.java?rev=344984&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/Logger.java 
(added)
+++ incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/Logger.java 
Wed Nov 16 03:27:13 2005
@@ -0,0 +1,58 @@
+/*

+ * 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.

+ */

+package sampleMediators;

+

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamWriter;

+

+

+

+import org.apache.axis2.soap.SOAPEnvelope;

+import org.apache.synapse.api.Mediator;

+import org.apache.synapse.api.SOAPMessageContext;

+

+

+/**

+ * TODO: add comment

+ */

+public class Logger implements Mediator {

+

+    /*

+     * (non-Javadoc)

+     * 

+     * @see 
org.apache.synapse.mediator.Mediator#mediate(org.apache.axis2.context.MessageContext)

+     */

+    public boolean mediate(SOAPMessageContext mc) {

+        System.out.println("Logger.mediate:");

+        if (mc.getTo()!=null && mc.getTo().getAddress()!=null) 
System.out.println("Logger.mediate to:" + mc.getTo().getAddress());

+        else System.out.println("Empty To");

+        if (mc.getReplyTo()!=null && mc.getReplyTo().getAddress()!=null) 
System.out.println("Logger.mediate ReplyTo:" + mc.getReplyTo().getAddress());

+        else System.out.println("Empty ReplyTo");

+

+        XMLOutputFactory xof = XMLOutputFactory.newInstance();

+        try {

+            XMLStreamWriter writer = xof.createXMLStreamWriter(System.out);

+            SOAPEnvelope env = mc.getEnvelope();

+            env.serialize(writer);

+            writer.flush();

+        } catch (Exception e) {

+            e.printStackTrace();

+        }

+        System.out.println();

+        return true;

+    }

+

+}
\ No newline at end of file

Added: 
incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/SpringRedirect.java
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/SpringRedirect.java?rev=344984&view=auto
==============================================================================
--- 
incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/SpringRedirect.java
 (added)
+++ 
incubator/synapse/trunk/scratch/prototype2/src/sampleMediators/SpringRedirect.java
 Wed Nov 16 03:27:13 2005
@@ -0,0 +1,35 @@
+/*

+ * 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.

+ */

+package sampleMediators;

+

+

+import org.apache.axis2.addressing.EndpointReference;

+import org.apache.synapse.api.Mediator;

+import org.apache.synapse.api.SOAPMessageContext;

+

+public class SpringRedirect implements Mediator {

+       private String uri = null;

+       public void setUri(String uri) {

+               this.uri = uri;

+       }

+    public boolean mediate(SOAPMessageContext mc) {

+               

+        System.out.println("Redirect.mediate: "+uri);

+

+        mc.setTo(new EndpointReference(uri));

+        return true;

+    }

+}
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/prototype2/synapse.xml
URL: 
http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype2/synapse.xml?rev=344984&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype2/synapse.xml (added)
+++ incubator/synapse/trunk/scratch/prototype2/synapse.xml Wed Nov 16 03:27:13 
2005
@@ -0,0 +1,28 @@
+<synapse xmlns="http://ws.apache.org/ns/synapse";

+               

+               xmlns:sq="urn:xmethods-delayed-quotes">

+      

+    

+    <stage name="logall" rule-type="all">

+        <rule>

+            <mediator type="builtin" name="log" />

+        </rule>

+    </stage>

+    <stage name="service-specific" rule-type="xpath">

+               <rule xpath="//sq:getQuote" 
xmlns:sq="urn:xmethods-delayed-quotes">

+                       <mediator type="spring" name="redirect" bean="redirect">

+                               <beans>

+                                       <bean id="redirect" 
class="sampleMediators.SpringRedirect">

+                                               <!--property name="uri" 
value="http://64.124.140.30:9090/soap"/-->

+                                               <property name="uri" 
value="http://FREO:8080/axis/services/E4XStock"/>

+                                       </bean>

+                               </beans>

+                       </mediator>

+               </rule>

+       </stage>

+       <stage name="sender" rule-type="all">

+               <rule>

+                       <mediator type="builtin" name="sender"/>

+               </rule>

+       </stage>

+</synapse>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to