use of org.apache.synapse.commons.evaluators.EqualEvaluator in project wso2-synapse by wso2.
the class EqualBuilderTest method testURLEqual.
public void testURLEqual() {
String input = "<equal type=\"url\" value=\"" + VALUE + "\"/>";
try {
EqualEvaluator eval = (EqualEvaluator) fac.create(AXIOMUtil.stringToOM(input));
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getValue(), VALUE);
assertNull(txtRtvr.getSource());
} catch (Exception e) {
fail("Error while parsing the input XML");
}
}
use of org.apache.synapse.commons.evaluators.EqualEvaluator in project wso2-synapse by wso2.
the class EqualFactory method create.
public Evaluator create(OMElement e) throws EvaluatorException {
EqualEvaluator equal = new EqualEvaluator();
SourceTextRetriever textRetriever = getSourceTextRetriever(e);
equal.setTextRetriever(textRetriever);
OMAttribute valueAttr = e.getAttribute(new QName(EvaluatorConstants.VALUE));
if (valueAttr == null) {
handleException(EvaluatorConstants.VALUE + " attribute is required");
return null;
}
equal.setValue(valueAttr.getAttributeValue());
return equal;
}
use of org.apache.synapse.commons.evaluators.EqualEvaluator in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario2.
public void testConditionalRewriteScenario2() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action = new RewriteAction();
action.setValue(targetURL);
RewriteRule rule = new RewriteRule();
EqualEvaluator eval = new EqualEvaluator();
URLTextRetriever txtRtvr = new URLTextRetriever();
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
eval.setTextRetriever(txtRtvr);
eval.setValue("8280");
rule.setCondition(eval);
rule.addRewriteAction(action);
mediator.addRule(rule);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://localhost:8280"));
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.synapse.commons.evaluators.EqualEvaluator 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