Search in sources :

Example 6 with EvaluatorException

use of org.apache.synapse.commons.evaluators.EvaluatorException 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)

Example 7 with EvaluatorException

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

the class RewriteRule method rewrite.

public void rewrite(URIFragments fragments, MessageContext messageContext) throws URISyntaxException {
    if (condition != null) {
        String uriString = fragments.toURIString();
        Map<String, String> headers = getHeaders(messageContext);
        EvaluatorContext ctx = new EvaluatorContext(uriString, headers);
        ctx.setProperties(((Axis2MessageContext) messageContext).getProperties());
        ctx.setMessageContext(((Axis2MessageContext) messageContext).getAxis2MessageContext());
        if (log.isTraceEnabled()) {
            log.trace("Evaluating condition with URI: " + uriString);
        }
        try {
            if (!condition.evaluate(ctx)) {
                if (log.isTraceEnabled()) {
                    log.trace("Condition evaluated to 'false' - Skipping the current action");
                }
                return;
            }
            if (log.isTraceEnabled()) {
                log.trace("Condition evaluated to 'true' - Performing the stated action");
            }
        } catch (EvaluatorException e) {
            log.warn("Error while evaluating the condition - Skipping the rule as it failed", e);
            return;
        }
    }
    for (RewriteAction action : actions) {
        action.execute(fragments, messageContext);
    }
}
Also used : EvaluatorContext(org.apache.synapse.commons.evaluators.EvaluatorContext) EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException)

Example 8 with EvaluatorException

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

the class AbstractEvaluatorSerializer method serializeChildren.

protected void serializeChildren(OMElement parent, Evaluator[] childEvaluators) throws EvaluatorException {
    for (Evaluator evaluator : childEvaluators) {
        String name = evaluator.getName();
        EvaluatorSerializer serializer = EvaluatorSerializerFinder.getInstance().getSerializer(name);
        if (serializer != null) {
            serializer.serialize(parent, evaluator);
        } else {
            String msg = "Couldn't find the serializer for evaliator: " + name;
            log.error(msg);
            throw new EvaluatorException(msg);
        }
    }
}
Also used : EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) Evaluator(org.apache.synapse.commons.evaluators.Evaluator)

Example 9 with EvaluatorException

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

the class ConditionSerializer method serializer.

public OMElement serializer(OMElement parent, Condition condition) throws EvaluatorException {
    OMElement conditionElement = fac.createOMElement(new QName(EvaluatorConstants.CONDITION));
    conditionElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.PRIORITY, nullNS, condition.getPriority() + ""));
    EvaluatorSerializer serializer = EvaluatorSerializerFinder.getInstance().getSerializer(condition.getEvaluator().getName());
    if (serializer != null) {
        serializer.serialize(conditionElement, condition.getEvaluator());
    } else {
        String msg = "Couldn't find the serializer for evaliator: " + condition.getEvaluator().getName();
        log.error(msg);
        throw new EvaluatorException(msg);
    }
    if (parent != null) {
        parent.addChild(conditionElement);
    }
    return conditionElement;
}
Also used : EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 10 with EvaluatorException

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

the class URLRewriteMediatorSerializer method serializeSpecificMediator.

protected OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof URLRewriteMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
        return null;
    }
    URLRewriteMediator mediator = (URLRewriteMediator) m;
    OMElement rewrite = fac.createOMElement("rewrite", synNS);
    String inProperty = mediator.getInputProperty();
    String outProperty = mediator.getOutputProperty();
    if (inProperty != null) {
        rewrite.addAttribute(fac.createOMAttribute("inProperty", nullNS, inProperty));
    }
    if (outProperty != null) {
        rewrite.addAttribute(fac.createOMAttribute("outProperty", nullNS, outProperty));
    }
    saveTracingState(rewrite, mediator);
    List<RewriteRule> rules = mediator.getRules();
    try {
        for (RewriteRule r : rules) {
            OMElement rule = serializeRule(r);
            rewrite.addChild(rule);
        }
    } catch (EvaluatorException e) {
        handleException("Error while serializing the rewrite rule", e);
    }
    return rewrite;
}
Also used : URLRewriteMediator(org.apache.synapse.mediators.transform.url.URLRewriteMediator) EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) OMElement(org.apache.axiom.om.OMElement) RewriteRule(org.apache.synapse.mediators.transform.url.RewriteRule)

Aggregations

EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)10 OMElement (org.apache.axiom.om.OMElement)6 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)3 Iterator (java.util.Iterator)2 QName (javax.xml.namespace.QName)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 EvaluatorContext (org.apache.synapse.commons.evaluators.EvaluatorContext)2 ConditionalRoute (org.apache.synapse.mediators.filters.router.ConditionalRoute)2 ConditionalRouterMediator (org.apache.synapse.mediators.filters.router.ConditionalRouterMediator)2 RewriteRule (org.apache.synapse.mediators.transform.url.RewriteRule)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 OMDocumentImpl (org.apache.axiom.om.impl.llom.OMDocumentImpl)1 OMElementImpl (org.apache.axiom.om.impl.llom.OMElementImpl)1 OMTextImpl (org.apache.axiom.om.impl.llom.OMTextImpl)1 AXIOMXPath (org.apache.axiom.om.xpath.AXIOMXPath)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 Parser (org.apache.synapse.commons.evaluators.Parser)1 EvaluatorSerializer (org.apache.synapse.commons.evaluators.config.EvaluatorSerializer)1