Search in sources :

Example 1 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever in project wso2-synapse by wso2.

the class URLRewriteMediatorTest method testConditionalRewriteScenario1.

public void testConditionalRewriteScenario1() throws Exception {
    URLRewriteMediator mediator = new URLRewriteMediator();
    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.getTo().getAddress());
}
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 2 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever in project wso2-synapse by wso2.

the class EqualBuilderTest method testURLEqual2.

public void testURLEqual2() {
    String input = "<equal type=\"url\" value=\"" + VALUE + "\"" + " source=\"" + FRAGMENT + "\"/>";
    try {
        EqualEvaluator eval = (EqualEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof URLTextRetriever);
        assertEquals(eval.getValue(), VALUE);
        assertEquals(txtRtvr.getSource(), FRAGMENT);
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator)

Example 3 with URLTextRetriever

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

Example 4 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever in project wso2-synapse by wso2.

the class MatchBuilderTest method testURLMatch2.

public void testURLMatch2() {
    String input = "<match type=\"url\" regex=\"" + REGEX + "\" source=\"" + FRAGMENT + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof URLTextRetriever);
        assertEquals(eval.getRegex().pattern(), REGEX);
        assertEquals(txtRtvr.getSource(), FRAGMENT);
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Example 5 with URLTextRetriever

use of org.apache.synapse.commons.evaluators.source.URLTextRetriever in project wso2-synapse by wso2.

the class MatchBuilderTest method testURLMatch.

public void testURLMatch() {
    String input = "<match type=\"url\" regex=\"" + REGEX + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof URLTextRetriever);
        assertEquals(eval.getRegex().pattern(), REGEX);
        assertNull(txtRtvr.getSource());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error while parsing the input XML");
    }
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

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