You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by Saminda Abeyruwan <sa...@gmail.com> on 2006/03/01 08:51:42 UTC
Proposal for mediator
*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
Re: Proposal for mediator
Posted by Saminda Abeyruwan <sa...@gmail.com>.
Hi,
On 3/1/06, Paul Fremantle <pz...@gmail.com> wrote:
>
> 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>
>
> Paul
>
>
> On 3/1/06, Saminda Abeyruwan <sa...@gmail.com> 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
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
Re: Proposal for mediator
Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Wed, 2006-03-01 at 16:06 +0000, Paul Fremantle wrote:
> Saminda
>
> The only problem is that the individual rules don't signal whether
> they matched. The true/false is not an indication.
>
> So I was imagining this:
>
> <switch type="regex">
> <pattern pattern=" http://foo/.*">
> <mediator1>
> </pattern>
> <pattern pattern="http://bar/.*">
> <mediator2>
> </pattern>
> </switch>
Please add a default:
<switch ..>
<pattern ../>*
<default>
<mediatorx/>
</default>
</switch>
(Optional, of course.)
To me the idea of combining two pattern languages (regex and xpath) in
one thing is bad. Why can't switch/@type be switch/@pattern and be of
xpath type?
Sanjiva.
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org
Re: Proposal for mediator
Posted by Paul Fremantle <pz...@gmail.com>.
Saminda
The only problem is that the individual rules don't signal whether they
matched. The true/false is not an indication.
So I was imagining this:
<switch type="regex">
<pattern pattern="http://foo/.*">
<mediator1>
</pattern>
<pattern pattern="http://bar/.*">
<mediator2>
</pattern>
</switch>
Paul
On 3/1/06, Saminda Abeyruwan <sa...@gmail.com> 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
paul@wso2.com
"Oxygenating the Web Service Platform", www.wso2.com