Search in sources :

Example 1 with RewriteRule

use of org.apache.synapse.mediators.transform.url.RewriteRule 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 2 with RewriteRule

use of org.apache.synapse.mediators.transform.url.RewriteRule 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

OMElement (org.apache.axiom.om.OMElement)2 EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)2 RewriteRule (org.apache.synapse.mediators.transform.url.RewriteRule)2 Iterator (java.util.Iterator)1 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)1 URLRewriteMediator (org.apache.synapse.mediators.transform.url.URLRewriteMediator)1