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