Saminda
The only problem is that the individual rules don't signal whether they matched. The true/false is not an indication.
That's why i was thinking of having a signalling variable inside of <regex/> and <xpath/> for <regex/> as follows,
public class RegexProcessor extends ListProcessor {
....// other variables
//pass readonly property
private boolean pass = false;
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
if (pattern == null) {
log.debug("trying to process with empty pattern");
return true;
}
String toMatch = null;
if (property != null) {
toMatch = smc.getProperty(property).toString();
} else {
toMatch = headerType.getHeader(smc);
}
if (toMatch==null) return true;
if (pattern.matcher(toMatch).matches()) {
log.debug("Regex pattern " + pattern.toString() + " matched "
+ toMatch);
pass = true;
return super.process(se, smc);
}
return true;
}
public boolean isPass() {
return pass;
}
...// other methods
}
So SwitchProcessor will be signalled if the underline <regex/> or <xpath/> processors pass. So SwitchProcessor can take the control and when ever the first mediator pass, others mediators can be false through as follows,
public class SwitchProcessor extends ListProcessor {
private Log log = LogFactory.getLog(getClass());
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
log.debug("processing in the MatchProcessor");
if (processors == null) {
log.info("process called on empty processor list");
return true;
}
Iterator it = processors.iterator();
while (it.hasNext()) {
Processor p = (Processor) it.next();
log.debug(p.getName() + " = " + p.getClass());
if (p instanceof XPathProcessor) {
XPathProcessor xp = (XPathProcessor) p;
if (xp.process(se, smc)) {
if (xp.isPass()) {
return true;
}
}
} else if (p instanceof RegexProcessor) {
RegexProcessor rp = (RegexProcessor) p;
if (rp.process(se, smc)) {
if (rp.isPass()) {
return true;
}
}
} else {
throw new SynapseException(
"<switch/> contains a non-conditional mediator");
}
}
return true;
}
I agree with Sanjva. It's not a good idea for mixing <regex/> and <xpaths/>
So how about this structure
<switch type="regex">
<regex/>* <!-- only regexes -->
<default/>?
</switch>
<switch type="xpath">
<xpath/>* <!-- only xpaths -->
<default/>?
</switch>
So we only need to introduce only <default/> optional mediator. With a minor modification to code in SwithProcessor, we can achieve the "exactlyone" behavior with <switch/>.
Thank you,
Saminda
So I was imagining this:
<switch type="regex">
<pattern pattern=" http://foo/.*">
<mediator1>
</pattern>
<pattern pattern=" http://bar/.*">
<mediator2>
</pattern>
</switch>
PaulOn 3/1/06, Saminda Abeyruwan <[EMAIL PROTECTED]> wrote:Title: Proposal for <switch/> mediator
Let's start with the syntax
<switch >
<xpath/>*
<regex/>*
</switch>
Note: "*" means 0 or N number of mediators.
Description:
All the mediators available in Synapse, <regex/> and <xpath/> can be considered as the conditional mediators and all other mediators are static and guarantee of doing some mediation work in line.
Say a scenario as follows,
<switch>
<xpaht dosomething1/>
<regex dosomething2/>
<regext dosomething3/>
<xpath dosomething4/>
</switch>
So if <regex dosomething2/> is passed, all the other mediators thereafter will be ignored. So "exactly one" mediator <regex/> or <xpath/> will be invoked.
The possible disadvantage is, there is no default mediator to execute, if all the mediators in the list failed. Since all <switch/> can include <xpaths/>'s and <regex/>'s.
I feel this is as a "extension" to Synapse rather being core feature.
Please comment.
Thank you
Saminda
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
[EMAIL PROTECTED]
"Oxygenating the Web Service Platform", www.wso2.com
