use of org.apache.synapse.commons.evaluators.EvaluatorException in project wso2-synapse by wso2.
the class ConditionalRouterMediator method mediate.
public boolean mediate(MessageContext synCtx) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (super.divertMediationRoute(synCtx)) {
return true;
}
}
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
Map<String, String> evaluatorHeaders = new HashMap<String, String>();
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
for (Object entryObj : headersMap.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
evaluatorHeaders.put((String) entry.getKey(), (String) entry.getValue());
}
}
}
String url = synCtx.getTo().getAddress();
EvaluatorContext context = new EvaluatorContext(url, evaluatorHeaders);
context.setProperties(((Axis2MessageContext) synCtx).getProperties());
context.setMessageContext(((Axis2MessageContext) synCtx).getAxis2MessageContext());
try {
for (ConditionalRoute conditionalRoute : conditionalRoutes) {
if (conditionalRoute.getEvaluator().evaluate(context)) {
conditionalRoute.getTarget().mediate(synCtx);
if (conditionalRoute.isBreakRoute()) {
break;
}
}
}
} catch (EvaluatorException ee) {
handleException("Couldn't evaluate the route condition", ee, synCtx);
}
return continueAfter;
}
use of org.apache.synapse.commons.evaluators.EvaluatorException in project wso2-synapse by wso2.
the class SOAPEnvelopeTextRetriever method getSourceText.
public String getSourceText(EvaluatorContext context) throws EvaluatorException {
SOAPEnvelope envelope = context.getMessageContext().getEnvelope();
Object result;
try {
if (compiledXPath == null) {
compiledXPath = new AXIOMXPath(source);
}
result = compiledXPath.evaluate(envelope);
} catch (JaxenException e) {
throw new EvaluatorException("Error while parsing the XPath expression: " + source, e);
}
if (result instanceof List) {
List list = (List) result;
if (list.size() == 1 && list.get(0) == null) {
return null;
}
StringBuffer textValue = new StringBuffer();
for (Object o : list) {
if (o instanceof OMTextImpl) {
textValue.append(((OMTextImpl) o).getText());
} else if (o instanceof OMElementImpl) {
String s = ((OMElementImpl) o).getText();
if (s.trim().length() == 0) {
s = o.toString();
}
textValue.append(s);
} else if (o instanceof OMDocumentImpl) {
textValue.append(((OMDocumentImpl) o).getOMDocumentElement().toString());
} else if (o instanceof OMAttribute) {
textValue.append(((OMAttribute) o).getAttributeValue());
}
}
return textValue.toString();
} else {
return result.toString();
}
}
use of org.apache.synapse.commons.evaluators.EvaluatorException 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.EvaluatorException in project wso2-synapse by wso2.
the class ListenerContextBuilder method createParser.
private Parser createParser(final OMElement definitions) throws AxisFault {
OMElement conditionsElem = definitions.getFirstChildWithName(new QName(EvaluatorConstants.CONDITIONS));
if (conditionsElem == null) {
handleException("Conditions configuration is mandatory for priority based routing");
}
assert conditionsElem != null;
OMAttribute defPriorityAttr = conditionsElem.getAttribute(new QName(EvaluatorConstants.DEFAULT_PRIORITY));
Parser parser;
if (defPriorityAttr != null) {
parser = new Parser(Integer.parseInt(defPriorityAttr.getAttributeValue()));
} else {
parser = new Parser();
}
try {
parser.init(conditionsElem);
} catch (EvaluatorException e) {
handleException("Invalid " + EvaluatorConstants.CONDITIONS + " configuration for priority based mediation", e);
}
return parser;
}
use of org.apache.synapse.commons.evaluators.EvaluatorException 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;
}
Aggregations