Search in sources :

Example 6 with Evaluator

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

the class URLRewriteMediatorFactory method parseRule.

private RewriteRule parseRule(OMElement ruleElement) {
    Iterator actions = ruleElement.getChildrenWithName(ACTION_Q);
    if (actions == null) {
        handleException("At least one rewrite action is required per rule");
        return null;
    }
    RewriteRule rule = new RewriteRule();
    while (actions.hasNext()) {
        rule.addRewriteAction(parseAction((OMElement) actions.next()));
    }
    OMElement condition = ruleElement.getFirstChildWithName(CONDITION_Q);
    if (condition != null) {
        OMElement child = condition.getFirstElement();
        if (child != null) {
            try {
                Evaluator eval = EvaluatorFactoryFinder.getInstance().getEvaluator(child);
                rule.setCondition(eval);
            } catch (EvaluatorException e) {
                handleException("Error while parsing the rule condition", e);
            }
        }
    }
    return rule;
}
Also used : EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator) RewriteRule(org.apache.synapse.mediators.transform.url.RewriteRule)

Example 7 with Evaluator

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

the class URLRewriteMediatorSerializer method serializeRule.

private OMElement serializeRule(RewriteRule r) throws EvaluatorException {
    OMElement rule = fac.createOMElement("rewriterule", synNS);
    Evaluator condition = r.getCondition();
    if (condition != null) {
        OMElement conditionElt = fac.createOMElement("condition", synNS);
        EvaluatorSerializer serializer = EvaluatorSerializerFinder.getInstance().getSerializer(condition.getName());
        serializer.serialize(conditionElt, condition);
        rule.addChild(conditionElt);
    }
    List<RewriteAction> actions = r.getActions();
    for (RewriteAction a : actions) {
        OMElement action = serializeAction(a);
        rule.addChild(action);
    }
    return rule;
}
Also used : RewriteAction(org.apache.synapse.mediators.transform.url.RewriteAction) OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator) EvaluatorSerializer(org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)

Example 8 with Evaluator

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

the class ConditionalRouterMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    ConditionalRouterMediator conditionalRouterMediator = new ConditionalRouterMediator();
    processAuditStatus(conditionalRouterMediator, elem);
    if (elem.getAttribute(CONTINUE_AFTER_ATTR) != null) {
        if (JavaUtils.isTrueExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
            conditionalRouterMediator.setContinueAfter(true);
        } else if (JavaUtils.isFalseExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
            conditionalRouterMediator.setContinueAfter(false);
        } else {
            handleException("continueAfter attribute value of the conditionalRouter must " + "be either 'true' or 'false', the value found is : " + elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim());
        }
    }
    Iterator itr = elem.getChildrenWithName(ROUTE_Q);
    while (itr.hasNext()) {
        OMElement routeElem = (OMElement) itr.next();
        ConditionalRoute conditionalRoute = new ConditionalRoute();
        if (routeElem.getAttribute(BREAK_ROUTE_ATTR) != null) {
            if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
                conditionalRoute.setBreakRoute(true);
            } else if (JavaUtils.isFalseExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
                conditionalRoute.setBreakRoute(false);
            } else {
                handleException("breakRoute attribute value of the conditionalRoute element must " + "be either 'true' or 'false', the value found is : " + routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim());
            }
        }
        OMElement conditionElem = routeElem.getFirstChildWithName(CONDITION_Q);
        if (conditionElem == null) {
            handleException("Couldn't find the condition of the conditional router");
            return null;
        }
        try {
            Evaluator evaluator = EvaluatorFactoryFinder.getInstance().getEvaluator(conditionElem.getFirstElement());
            conditionalRoute.setEvaluator(evaluator);
        } catch (EvaluatorException ee) {
            handleException("Couldn't build the condition of the conditional router", ee);
        }
        OMElement targetElem = routeElem.getFirstChildWithName(TARGET_Q);
        Target target = TargetFactory.createTarget(targetElem, properties);
        if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(ASYNCHRONOUS_ATTR))) {
            target.setAsynchronous(true);
        } else {
            target.setAsynchronous(false);
        }
        conditionalRoute.setTarget(target);
        conditionalRouterMediator.addRoute(conditionalRoute);
    }
    return conditionalRouterMediator;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) ConditionalRoute(org.apache.synapse.mediators.filters.router.ConditionalRoute) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator) ConditionalRouterMediator(org.apache.synapse.mediators.filters.router.ConditionalRouterMediator)

Example 9 with Evaluator

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

the class EqualSerializerTest method testURLEqualSerializer.

public void testURLEqualSerializer() {
    String input = "<equal xmlns=\"http://ws.apache.org/ns/synapse\" type=\"url\" value=\"http://foo.org\"/>";
    try {
        Evaluator eval = fac.create(AXIOMUtil.stringToOM(input));
        OMElement output = serializer.serialize(null, eval);
        assertXMLEqual(input, output.toString());
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator)

Example 10 with Evaluator

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

the class MatchSerializerTest method testHeaderMatchSerializer.

public void testHeaderMatchSerializer() {
    String input = "<match xmlns=\"http://ws.apache.org/ns/synapse\" type=\"header\" source=\"foo\" regex=\"bar\"/>";
    try {
        Evaluator eval = fac.create(AXIOMUtil.stringToOM(input));
        OMElement output = serializer.serialize(null, eval);
        assertXMLEqual(input, output.toString());
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : OMElement(org.apache.axiom.om.OMElement) Evaluator(org.apache.synapse.commons.evaluators.Evaluator)

Aggregations

Evaluator (org.apache.synapse.commons.evaluators.Evaluator)16 OMElement (org.apache.axiom.om.OMElement)15 Iterator (java.util.Iterator)4 EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 AndEvaluator (org.apache.synapse.commons.evaluators.AndEvaluator)1 Condition (org.apache.synapse.commons.evaluators.Condition)1 NotEvaluator (org.apache.synapse.commons.evaluators.NotEvaluator)1 OrEvaluator (org.apache.synapse.commons.evaluators.OrEvaluator)1 EvaluatorSerializer (org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)1 Target (org.apache.synapse.mediators.eip.Target)1 ConditionalRoute (org.apache.synapse.mediators.filters.router.ConditionalRoute)1 ConditionalRouterMediator (org.apache.synapse.mediators.filters.router.ConditionalRouterMediator)1 RewriteAction (org.apache.synapse.mediators.transform.url.RewriteAction)1 RewriteRule (org.apache.synapse.mediators.transform.url.RewriteRule)1