use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class XSLTMediatorTest method testTransformXSLTCustomSource.
public void testTransformXSLTCustomSource() throws Exception {
// create a new XSLT mediator
XSLTMediator transformMediator = new XSLTMediator();
// set xpath condition to select source
SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest");
xpath.addNamespace("m0", "http://services.samples/xsd");
transformMediator.setSource(xpath);
// set XSLT transformation URL
setXsltTransformationURL(transformMediator, "xslt-key");
MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt").setBodyFromString(SOURCE).addTextAroundBody().build();
transformMediator.mediate(synCtx);
// validate result
assertQuoteElement(synCtx.getEnvelope().getBody().getFirstOMChild().getNextOMSibling());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario1.
public void testConditionalRewriteScenario1() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
RewriteAction action = new RewriteAction();
action.setValue(targetURL);
RewriteRule rule = new RewriteRule();
EqualEvaluator eval = new EqualEvaluator();
URLTextRetriever txtRtvr = new URLTextRetriever();
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
eval.setTextRetriever(txtRtvr);
eval.setValue("8280");
rule.setCondition(eval);
rule.addRewriteAction(action);
mediator.addRule(rule);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://localhost:8280"));
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getTo().getAddress());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testUnconditionalRewriteScenario2.
public void testUnconditionalRewriteScenario2() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action = new RewriteAction();
action.setValue(targetURL);
RewriteRule rule = new RewriteRule();
rule.addRewriteAction(action);
mediator.addRule(rule);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testUnconditionalRewriteScenario3.
public void testUnconditionalRewriteScenario3() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setValue(targetURL);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
mediator.addRule(rule1);
RewriteAction action2 = new RewriteAction();
action2.setValue("/services/SimpleStockQuoteService");
action2.setFragmentIndex(URIFragments.PATH);
RewriteAction action3 = new RewriteAction();
action3.setXpath(new SynapseXPath("get-property('port')"));
action3.setFragmentIndex(URIFragments.PORT);
RewriteRule rule2 = new RewriteRule();
rule2.addRewriteAction(action2);
rule2.addRewriteAction(action3);
mediator.addRule(rule2);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://localhost:8280"));
msgCtx.setProperty("port", 9000);
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario4.
public void testConditionalRewriteScenario4() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setRegex("MyService");
action1.setValue("SimpleStockQuoteService");
action1.setFragmentIndex(URIFragments.PATH);
action1.setActionType(RewriteAction.ACTION_REPLACE);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
EqualEvaluator eval1 = new EqualEvaluator();
SOAPEnvelopeTextRetriever txtRtvr1 = new SOAPEnvelopeTextRetriever("//symbol");
eval1.setTextRetriever(txtRtvr1);
eval1.setValue("IBM");
rule1.setCondition(eval1);
mediator.addRule(rule1);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<getQuote><symbol>IBM</symbol></getQuote>");
msgCtx.setTo(new EndpointReference("http://localhost:9000/services/MyService"));
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
Aggregations