use of org.apache.synapse.commons.evaluators.EvaluatorContext 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.EvaluatorContext in project wso2-synapse by wso2.
the class SourceTextRetrieverTest method testHeaderTextRetriever.
public void testHeaderTextRetriever() throws EvaluatorException {
Map<String, String> headers = new HashMap<String, String>();
headers.put("key1", "value1");
headers.put("key2", "value2");
EvaluatorContext context = new EvaluatorContext(null, headers);
HeaderTextRetriever txtRtvr = new HeaderTextRetriever("key1");
assertEquals(headers.get("key1"), txtRtvr.getSourceText(context));
txtRtvr = new HeaderTextRetriever("bogusKey");
assertNull(txtRtvr.getSourceText(context));
}
use of org.apache.synapse.commons.evaluators.EvaluatorContext in project wso2-synapse by wso2.
the class SourceTextRetrieverTest method testURLTextRetriever.
public void testURLTextRetriever() throws EvaluatorException {
try {
URI uri = new URI("http://host:9000/path");
EvaluatorContext context = new EvaluatorContext(uri.toString(), null);
URLTextRetriever txtRtvr = new URLTextRetriever();
assertEquals(uri.toString(), txtRtvr.getSourceText(context));
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.host.name());
assertEquals(uri.getHost(), txtRtvr.getSourceText(context));
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
assertEquals(String.valueOf(uri.getPort()), txtRtvr.getSourceText(context));
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.protocol.name());
assertEquals(uri.getScheme(), txtRtvr.getSourceText(context));
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
assertEquals(uri.getPath(), txtRtvr.getSourceText(context));
} catch (URISyntaxException ignore) {
}
}
use of org.apache.synapse.commons.evaluators.EvaluatorContext in project wso2-synapse by wso2.
the class SourceTextRetrieverTest method testPropertyTextRetriver.
public void testPropertyTextRetriver() throws EvaluatorException {
Map<String, Object> props = new HashMap<String, Object>();
props.put("key1", "value1");
props.put("key2", "value2");
EvaluatorContext context = new EvaluatorContext(null, null);
context.setProperties(props);
PropertyTextRetriever txtRtvr = new PropertyTextRetriever("key1");
assertEquals(props.get("key1"), txtRtvr.getSourceText(context));
txtRtvr = new PropertyTextRetriever("key2");
assertEquals(props.get("key2"), txtRtvr.getSourceText(context));
txtRtvr = new PropertyTextRetriever("bogusKey");
assertNull(txtRtvr.getSourceText(context));
}
use of org.apache.synapse.commons.evaluators.EvaluatorContext in project wso2-synapse by wso2.
the class SourceTextRetrieverTest method testParameterTextRetriever.
public void testParameterTextRetriever() throws EvaluatorException {
String url = "http://host:9000/path?key1=value1&key2=value2";
EvaluatorContext context = new EvaluatorContext(url, null);
ParameterTextRetriever txtRtvr = new ParameterTextRetriever("key1");
assertEquals("value1", txtRtvr.getSourceText(context));
txtRtvr = new ParameterTextRetriever("key2");
assertEquals("value2", txtRtvr.getSourceText(context));
txtRtvr = new ParameterTextRetriever("bogusKey");
assertNull(txtRtvr.getSourceText(context));
}
Aggregations