use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.
the class MatchFactory method create.
public Evaluator create(OMElement e) throws EvaluatorException {
MatchEvaluator equal = new MatchEvaluator();
SourceTextRetriever textRetriever = getSourceTextRetriever(e);
equal.setTextRetriever(textRetriever);
OMAttribute regExAttr = e.getAttribute(new QName(EvaluatorConstants.REGEX));
if (regExAttr == null) {
handleException(EvaluatorConstants.REGEX + " attribute is required");
return null;
}
equal.setRegex(Pattern.compile(regExAttr.getAttributeValue()));
return equal;
}
use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario3.
public void testConditionalRewriteScenario3() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setValue("localhost");
action1.setFragmentIndex(URIFragments.HOST);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
EqualEvaluator eval1 = new EqualEvaluator();
URLTextRetriever txtRtvr1 = new URLTextRetriever();
txtRtvr1.setSource(EvaluatorConstants.URI_FRAGMENTS.host.name());
eval1.setTextRetriever(txtRtvr1);
eval1.setValue("myhost");
rule1.setCondition(eval1);
mediator.addRule(rule1);
RewriteAction action2 = new RewriteAction();
action2.setValue("/services/SimpleStockQuoteService");
action2.setFragmentIndex(URIFragments.PATH);
RewriteAction action3 = new RewriteAction();
action3.setXpath(new SynapseXPath("get-property('port')"));
action3.setFragmentIndex(URIFragments.PORT);
RewriteRule rule2 = new RewriteRule();
rule2.addRewriteAction(action2);
rule2.addRewriteAction(action3);
MatchEvaluator eval2 = new MatchEvaluator();
URLTextRetriever txtRtvr2 = new URLTextRetriever();
txtRtvr2.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
eval2.setTextRetriever(txtRtvr2);
eval2.setRegex(Pattern.compile(".*/MyService"));
rule2.setCondition(eval2);
mediator.addRule(rule2);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://myhost:8280/MyService"));
msgCtx.setProperty("port", 9000);
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
Aggregations