Search in sources :

Example 6 with EqualEvaluator

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");
    }
}
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 7 with EqualEvaluator

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;
}
Also used : QName(javax.xml.namespace.QName) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) OMAttribute(org.apache.axiom.om.OMAttribute) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator)

Example 8 with EqualEvaluator

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"));
}
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 9 with EqualEvaluator

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"));
}
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

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