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