Search in sources :

Example 6 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever 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"));
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 7 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever 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"));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) MessageContext(org.apache.synapse.MessageContext) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

URLTextRetriever (org.apache.synapse.commons.evaluators.source.URLTextRetriever)7 EqualEvaluator (org.apache.synapse.commons.evaluators.EqualEvaluator)5 SourceTextRetriever (org.apache.synapse.commons.evaluators.source.SourceTextRetriever)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 MessageContext (org.apache.synapse.MessageContext)3 MatchEvaluator (org.apache.synapse.commons.evaluators.MatchEvaluator)3 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1