synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r382375 - in /incubator/synapse/trunk/java/modules/core: src/org/apache/synapse/ src/org/apache/synapse/processors/ src/org/apache/synapse/processors/conditions/ src/org/apache/synapse/processors/rules/ src/org/apache/synapse/xml/ test/org/...
Date Thu, 02 Mar 2006 13:17:37 GMT
Author: saminda
Date: Thu Mar  2 05:17:34 2006
New Revision: 382375

URL: http://svn.apache.org/viewcvs?rev=382375&view=rev
Log:
<exactlyone/ > mediator will be the predecessor of what is gonna be in <switch/>.

This has the following structure.
< exactlyone >
    <regex/>*
    <xpath/>*
    <default/>?
</ exactlyone >

if exactly one of <regex/> or <xpath/> passes, then other mediators there after
false through. If no condition passes 
<default/> will work. <default/> is optional.  <default/> should be the
last otherwise exception will be thrown. 

Added:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseMessageConstants.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessor.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessorConfigurator.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessor.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessorConfigurator.java
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/
    incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/ExactlyOneProcessorWithRuleTest.java
Modified:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/ListProcessor.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/RegexProcessor.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/XPathProcessor.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseMessageConstants.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseMessageConstants.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseMessageConstants.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/SynapseMessageConstants.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,20 @@
+package org.apache.synapse;
+/*
+ * 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 interface SynapseMessageConstants {
+    String MATCHED = "--BOOLEAN_MATCH__";
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/ListProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/ListProcessor.java?rev=382375&r1=382374&r2=382375&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/ListProcessor.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/ListProcessor.java
Thu Mar  2 05:17:34 2006
@@ -38,7 +38,7 @@
 	
 	private Log log = LogFactory.getLog(getClass());
 
-	List processors = null;
+	protected List processors = null;
 	
 	public boolean process(SynapseEnvironment se, SynapseMessage smc) {
 		log.debug("process");

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessor.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessor.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessor.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,27 @@
+package org.apache.synapse.processors.conditions;
+
+import org.apache.synapse.processors.ListProcessor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+/*
+ * 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 DefaultProcessor extends ListProcessor {
+    public boolean process(SynapseEnvironment se, SynapseMessage smc) {
+        return  super.process(se,smc);
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessorConfigurator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessorConfigurator.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessorConfigurator.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/DefaultProcessorConfigurator.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,40 @@
+package org.apache.synapse.processors.conditions;
+
+import org.apache.synapse.xml.AbstractListProcessorConfigurator;
+import org.apache.synapse.xml.Constants;
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.axis2.om.OMElement;
+
+import javax.xml.namespace.QName;
+/*
+ * 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 DefaultProcessorConfigurator
+        extends AbstractListProcessorConfigurator {
+
+    private static final QName DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE,
+			"default");
+    public Processor createProcessor(SynapseEnvironment se, OMElement el) {
+        DefaultProcessor dp = new DefaultProcessor();
+        super.addChildrenAndSetName(se,el,dp);
+        return dp;  
+    }
+
+    public QName getTagQName() {
+        return DEFAULT_Q;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessor.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessor.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessor.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,73 @@
+package org.apache.synapse.processors.conditions;
+
+import org.apache.synapse.processors.ListProcessor;
+import org.apache.synapse.processors.rules.XPathProcessor;
+import org.apache.synapse.processors.rules.RegexProcessor;
+import org.apache.synapse.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+
+/**
+ * Corresponding to <exactly/>
+ * This conatins conditional mediators such as <regex/> and <xpath/>
+ * It will look for the first match, if the first match is true then all the other
+ * mediators listed thereafter will be ingnored
+ */
+public class ExactlyOneProcessor extends ListProcessor {
+
+    private Log log = LogFactory.getLog(getClass());
+
+    public boolean process(SynapseEnvironment se, SynapseMessage smc) {
+        log.debug("processing in the SwitchProcessor");
+        if (processors == null) {
+            log.info("process called on empty processor list");
+            return true;
+        }
+        Iterator it = processors.iterator();
+        int processorListSize = processors.size();
+        int count = 0;
+        while (it.hasNext()) {
+            Processor p = (Processor) it.next();
+            log.debug(p.getName() + " = " + p.getClass());
+            ++count;
+            if (count <= processorListSize) {
+                if (p instanceof XPathProcessor) {
+                    XPathProcessor xp = (XPathProcessor) p;
+                    if (xp.process(se, smc)) {
+                        if (smc.getProperty(
+                                SynapseMessageConstants.MATCHED) != null &&
+                                ((Boolean) smc.getProperty(
+                                        SynapseMessageConstants.MATCHED))
+                                        .booleanValue()) {
+                            return true;
+                        }
+                    }
+                } else if (p instanceof RegexProcessor) {
+                    RegexProcessor rp = (RegexProcessor) p;
+                    if (rp.process(se, smc)) {
+                        if (smc.getProperty(
+                                SynapseMessageConstants.MATCHED) != null &&
+                                ((Boolean) smc.getProperty(
+                                        SynapseMessageConstants.MATCHED))
+                                        .booleanValue()) {
+                            return true;
+                        }
+                    }
+                } else if (count == processorListSize &&
+                        (p instanceof DefaultProcessor)) {
+                    DefaultProcessor defaultProcessor =
+                            (DefaultProcessor) p;
+                    if (!defaultProcessor.process(se, smc)) {
+                        return false;
+                    }
+                } else {
+                    throw new SynapseException("Mismatch with the Type ");
+                }
+            }
+        }
+        return true;
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessorConfigurator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessorConfigurator.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessorConfigurator.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/conditions/ExactlyOneProcessorConfigurator.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,38 @@
+package org.apache.synapse.processors.conditions;
+
+import org.apache.synapse.xml.AbstractListProcessorConfigurator;
+import org.apache.synapse.xml.Constants;
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.axis2.om.OMElement;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This will create <exactlyone>
+ *                       <regex/>[0..n]
+ *                       <xpath/>[0..n]
+ *                       <default/> ?
+ *                  </exactlyone>
+ *
+ *
+ */
+public class ExactlyOneProcessorConfigurator extends AbstractListProcessorConfigurator {
+
+    private static final String EXACTLYONE = "exactlyone";
+
+	private static final QName SWITCH_Q = new QName(Constants.SYNAPSE_NAMESPACE,
+			EXACTLYONE);
+
+
+    public Processor createProcessor(SynapseEnvironment se, OMElement el) {
+        ExactlyOneProcessor exactlyOneProcessor = new ExactlyOneProcessor();
+        super.addChildrenAndSetName(se,el,exactlyOneProcessor);
+
+        return exactlyOneProcessor;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_Q;
+    }
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/RegexProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/RegexProcessor.java?rev=382375&r1=382374&r2=382375&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/RegexProcessor.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/RegexProcessor.java
Thu Mar  2 05:17:34 2006
@@ -24,6 +24,7 @@
 import org.apache.synapse.HeaderType;
 import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseMessageConstants;
 
 import org.apache.synapse.processors.ListProcessor;
 
@@ -81,13 +82,14 @@
 		} else {
 			toMatch = headerType.getHeader(smc);
 		}
-		
+
 		if (toMatch==null) return true;
-		
+
 		if (pattern.matcher(toMatch).matches()) {
 			log.debug("Regex pattern " + pattern.toString() + " matched "
 					+ toMatch);
-			return super.process(se, smc);
+            smc.setProperty(SynapseMessageConstants.MATCHED,Boolean.TRUE);
+            return super.process(se, smc);
 		}
 		return true;
 	}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/XPathProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/XPathProcessor.java?rev=382375&r1=382374&r2=382375&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/XPathProcessor.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/processors/rules/XPathProcessor.java
Thu Mar  2 05:17:34 2006
@@ -22,6 +22,7 @@
 import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseMessageConstants;
 import org.apache.synapse.processors.ListProcessor;
 import org.jaxen.JaxenException;
 
@@ -41,7 +42,7 @@
 
 	private AXIOMXPath xp = null;
 
-	
+
 	public boolean process(SynapseEnvironment se, SynapseMessage smc) {
 		if (xp == null) {
 			log.debug("trying to process xpath without being set");
@@ -51,7 +52,8 @@
 			if (xp.booleanValueOf(smc.getEnvelope())) {
 				log.debug("matched xpath: " + xp.toString());
 				// now do "all"
-				return super.process(se, smc);
+                smc.setProperty(SynapseMessageConstants.MATCHED,Boolean.TRUE);
+                return super.process(se, smc);
 			}
 
 		} catch (JaxenException je) {

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java?rev=382375&r1=382374&r2=382375&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/ProcessorConfiguratorFinder.java
Thu Mar  2 05:17:34 2006
@@ -32,6 +32,8 @@
 import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.processors.builtin.xslt.XSLTProcessorConfigurator;
+import org.apache.synapse.processors.conditions.ExactlyOneProcessorConfigurator;
+import org.apache.synapse.processors.conditions.DefaultProcessorConfigurator;
 
 import sun.misc.Service;
 
@@ -63,7 +65,8 @@
 			NeverProcessorConfigurator.class, RefProcessorConfigurator.class,
             XSLTProcessorConfigurator.class,DefineProcessorConfigurator.class,
             SendNowProcessorConfigurator.class,DropProcessorConfigurator.class,
-            RefDefineProcessorConfigurator.class};
+            RefDefineProcessorConfigurator.class, ExactlyOneProcessorConfigurator.class,
+            DefaultProcessorConfigurator.class};
 
 	private static void initialise() {
 

Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/ExactlyOneProcessorWithRuleTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/ExactlyOneProcessorWithRuleTest.java?rev=382375&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/ExactlyOneProcessorWithRuleTest.java
(added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/spi/conditions/ExactlyOneProcessorWithRuleTest.java
Thu Mar  2 05:17:34 2006
@@ -0,0 +1,69 @@
+package org.apache.synapse.spi.conditions;
+
+import junit.framework.TestCase;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.om.OMElement;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.Constants;
+import org.apache.synapse.util.Axis2EnvSetup;
+import org.apache.synapse.axis2.Axis2SynapseEnvironment;
+import org.apache.synapse.axis2.Axis2SynapseMessage;
+
+/**
+ * TestCase for SwitchProcessor
+ */
+public class ExactlyOneProcessorWithRuleTest extends TestCase {
+    private MessageContext mc;
+    private OMElement config;
+    private SynapseEnvironment env;
+    private String synapsexml1 =
+            "<synapse xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
+                    "<exactlyone>"+
+                    "    <regex message-address=\"to\" pattern=\"http://xmethods..\\*\"/>\n"
+
+                    "    <xpath expr=\"//ns:text\" xmlns:ns=\"urn:text-body\">\n" +
+                              "<engage-addressing-in/>"+
+                    "    </xpath>"+
+                    "</exactlyone>"+
+                    "</synapse>";
+
+    private String synapsexml2 =
+            "<synapse xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
+                    "<exactlyone>"+
+                    "    <xpath expr=\"//ns:text_empty\" xmlns:ns=\"urn:text-body\"/>\n"
+
+                    "    <xpath expr=\"//ns:text_empty2\" xmlns:ns=\"urn:text-body\">\n"
+
+                              "<engage-addressing-in/>"+
+                    "    </xpath>"+
+                    "    <default> "+
+                    "        <engage-addressing-in/>"+
+                    "    </default> "+
+                    "</exactlyone>"+
+                    "</synapse>";
+
+
+
+    public void testXathSwithProcessor() throws Exception {
+            mc = Axis2EnvSetup
+                    .axis2Deployment("target/synapse-repository");
+            config = Axis2EnvSetup.getSynapseConfigElement(synapsexml1);
+            env = new Axis2SynapseEnvironment(config,
+                    Thread.currentThread().getContextClassLoader());
+            SynapseMessage smc = new Axis2SynapseMessage(mc);
+            env.injectMessage(smc);
+            assertTrue(((Boolean) smc.getProperty(
+                    Constants.MEDIATOR_RESPONSE_PROPERTY)).booleanValue());
+        }
+
+        public void testDefaultProcessor() throws Exception {
+            mc = Axis2EnvSetup
+                    .axis2Deployment("target/synapse-repository");
+            config = Axis2EnvSetup.getSynapseConfigElement(synapsexml2);
+            env = new Axis2SynapseEnvironment(config,
+                    Thread.currentThread().getContextClassLoader());
+            SynapseMessage smc = new Axis2SynapseMessage(mc);
+            env.injectMessage(smc);
+            assertTrue(((Boolean) smc.getProperty(
+                    Constants.MEDIATOR_RESPONSE_PROPERTY)).booleanValue());
+        }
+
+}



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


Mime
View raw message