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;
}
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;
}
Aggregations