Search in sources :

Example 1 with EqualEvaluator

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

the class EqualBuilderTest method testParameterEqual.

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

Example 2 with EqualEvaluator

use of org.apache.synapse.commons.evaluators.EqualEvaluator 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 3 with EqualEvaluator

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

the class URLRewriteMediatorTest method testConditionalRewriteScenario4.

public void testConditionalRewriteScenario4() throws Exception {
    URLRewriteMediator mediator = new URLRewriteMediator();
    mediator.setOutputProperty("outURL");
    RewriteAction action1 = new RewriteAction();
    action1.setRegex("MyService");
    action1.setValue("SimpleStockQuoteService");
    action1.setFragmentIndex(URIFragments.PATH);
    action1.setActionType(RewriteAction.ACTION_REPLACE);
    RewriteRule rule1 = new RewriteRule();
    rule1.addRewriteAction(action1);
    EqualEvaluator eval1 = new EqualEvaluator();
    SOAPEnvelopeTextRetriever txtRtvr1 = new SOAPEnvelopeTextRetriever("//symbol");
    eval1.setTextRetriever(txtRtvr1);
    eval1.setValue("IBM");
    rule1.setCondition(eval1);
    mediator.addRule(rule1);
    MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<getQuote><symbol>IBM</symbol></getQuote>");
    msgCtx.setTo(new EndpointReference("http://localhost:9000/services/MyService"));
    mediator.mediate(msgCtx);
    assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
Also used : SOAPEnvelopeTextRetriever(org.apache.synapse.commons.evaluators.source.SOAPEnvelopeTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with EqualEvaluator

use of org.apache.synapse.commons.evaluators.EqualEvaluator 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 5 with EqualEvaluator

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

the class EqualBuilderTest method testHeaderEqual.

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

Aggregations

EqualEvaluator (org.apache.synapse.commons.evaluators.EqualEvaluator)9 SourceTextRetriever (org.apache.synapse.commons.evaluators.source.SourceTextRetriever)5 URLTextRetriever (org.apache.synapse.commons.evaluators.source.URLTextRetriever)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 MessageContext (org.apache.synapse.MessageContext)4 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 MatchEvaluator (org.apache.synapse.commons.evaluators.MatchEvaluator)1 HeaderTextRetriever (org.apache.synapse.commons.evaluators.source.HeaderTextRetriever)1 ParameterTextRetriever (org.apache.synapse.commons.evaluators.source.ParameterTextRetriever)1 SOAPEnvelopeTextRetriever (org.apache.synapse.commons.evaluators.source.SOAPEnvelopeTextRetriever)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1