Search in sources :

Example 31 with MessageContext

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());
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) TestMessageContextBuilder(org.apache.synapse.TestMessageContextBuilder) MessageContext(org.apache.synapse.MessageContext)

Example 32 with MessageContext

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());
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 33 with MessageContext

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"));
}
Also used : MessageContext(org.apache.synapse.MessageContext)

Example 34 with MessageContext

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"));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) MessageContext(org.apache.synapse.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 35 with MessageContext

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"));
}
Also used : SOAPEnvelopeTextRetriever(org.apache.synapse.commons.evaluators.source.SOAPEnvelopeTextRetriever) MessageContext(org.apache.synapse.MessageContext) EqualEvaluator(org.apache.synapse.commons.evaluators.EqualEvaluator) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

MessageContext (org.apache.synapse.MessageContext)220 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)86 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)54 SynapseException (org.apache.synapse.SynapseException)29 TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)26 ArrayList (java.util.ArrayList)24 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)24 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)24 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)18 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)18 OMElement (org.apache.axiom.om.OMElement)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17 HashMap (java.util.HashMap)16 Mediator (org.apache.synapse.Mediator)16 TestMessageContext (org.apache.synapse.TestMessageContext)16 Map (java.util.Map)15 Properties (java.util.Properties)15 Test (org.junit.Test)15 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)14 QName (javax.xml.namespace.QName)13