Search in sources :

Example 1 with EvaluatorSerializer

use of org.apache.synapse.commons.evaluators.config.EvaluatorSerializer 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 2 with EvaluatorSerializer

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

the class ConditionalRouterMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    OMElement conditionalRouterElem = fac.createOMElement("conditionalRouter", synNS);
    saveTracingState(conditionalRouterElem, m);
    ConditionalRouterMediator conditionalRouterMediator = (ConditionalRouterMediator) m;
    if (conditionalRouterMediator.isContinueAfterExplicitlySet()) {
        conditionalRouterElem.addAttribute("continueAfter", Boolean.toString(conditionalRouterMediator.isContinueAfter()), nullNS);
    }
    for (ConditionalRoute conditionalRoute : conditionalRouterMediator.getConditionalRoutes()) {
        OMElement routeElem = fac.createOMElement("conditionalRoute", synNS);
        if (conditionalRoute.isBreakRouteExplicitlySet()) {
            routeElem.addAttribute("breakRoute", Boolean.toString(conditionalRoute.isBreakRoute()), nullNS);
        }
        if (conditionalRoute.getEvaluator() != null) {
            EvaluatorSerializer evaluatorSerializer = EvaluatorSerializerFinder.getInstance().getSerializer(conditionalRoute.getEvaluator().getName());
            if (evaluatorSerializer != null) {
                OMElement conditionElement = fac.createOMElement("condition", synNS);
                try {
                    evaluatorSerializer.serialize(conditionElement, conditionalRoute.getEvaluator());
                } catch (EvaluatorException e) {
                    handleException("Cannot serialize the Evaluator", e);
                }
                routeElem.addChild(conditionElement);
            }
        }
        if (conditionalRoute.getTarget() != null) {
            routeElem.addChild(TargetSerializer.serializeTarget(conditionalRoute.getTarget()));
        } else {
            handleException("ConditionalRoute in a conditional router has to have a target");
        }
        if (conditionalRoute.getTarget().isAsynchronous()) {
            routeElem.addAttribute(fac.createOMAttribute("asynchronous", nullNS, "true"));
        }
        conditionalRouterElem.addChild(routeElem);
    }
    return conditionalRouterElem;
}
Also used : EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) ConditionalRoute(org.apache.synapse.mediators.filters.router.ConditionalRoute) OMElement(org.apache.axiom.om.OMElement) ConditionalRouterMediator(org.apache.synapse.mediators.filters.router.ConditionalRouterMediator) EvaluatorSerializer(org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)

Aggregations

OMElement (org.apache.axiom.om.OMElement)2 EvaluatorSerializer (org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)2 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)1 EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)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