use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class Axis2MessageContextTest method testMessageContextGetStringValueBody.
public void testMessageContextGetStringValueBody() throws Exception {
SynapseXPath axiomXpath = new SynapseXPath("$body/ns1:a/ns1:c");
axiomXpath.addNamespace("ns1", nsNamespace1);
MessageContext synCtx = TestUtils.getTestContext(sampleBody);
String result = axiomXpath.stringValueOf(synCtx);
assertEquals("second", result);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class XSLTMediatorTest method testTransformXSLTCustomSourceNonMainElement.
public void testTransformXSLTCustomSourceNonMainElement() throws Exception {
// create a new switch 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");
// invoke transformation, with static enveope
MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt").setBodyFromString(ENCLOSING_SOURCE).addTextAroundBody().build();
transformMediator.mediate(synCtx);
// validate result
OMContainer body = synCtx.getEnvelope().getBody();
if (body.getFirstOMChild().getNextOMSibling() instanceof OMElement) {
OMElement someOtherElem = (OMElement) body.getFirstOMChild().getNextOMSibling();
assertTrue("someOtherElement".equals(someOtherElem.getLocalName()));
assertTrue("http://someother".equals(someOtherElem.getNamespace().getNamespaceURI()));
assertQuoteElement(someOtherElem.getFirstOMChild());
} else {
fail("Unexpected element found in SOAP body");
}
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario3.
public void testConditionalRewriteScenario3() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setValue("localhost");
action1.setFragmentIndex(URIFragments.HOST);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
EqualEvaluator eval1 = new EqualEvaluator();
URLTextRetriever txtRtvr1 = new URLTextRetriever();
txtRtvr1.setSource(EvaluatorConstants.URI_FRAGMENTS.host.name());
eval1.setTextRetriever(txtRtvr1);
eval1.setValue("myhost");
rule1.setCondition(eval1);
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);
MatchEvaluator eval2 = new MatchEvaluator();
URLTextRetriever txtRtvr2 = new URLTextRetriever();
txtRtvr2.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
eval2.setTextRetriever(txtRtvr2);
eval2.setRegex(Pattern.compile(".*/MyService"));
rule2.setCondition(eval2);
mediator.addRule(rule2);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://myhost:8280/MyService"));
msgCtx.setProperty("port", 9000);
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class DynamicEndpointTest method testContextProperties.
public void testContextProperties() throws Exception {
SynapseXPath xpath = new SynapseXPath("$ctx:timeout");
AbstractEndpoint endpoint = new AddressEndpoint();
EndpointDefinition definition = new EndpointDefinition();
endpoint.setDefinition(definition);
definition.setDynamicTimeoutExpression(xpath);
MessageContext synCtx = new TestMessageContext();
synCtx.setProperty("timeout", "90000");
assertEquals(Long.valueOf((String) xpath.evaluate(synCtx)).longValue(), endpoint.getDefinition().evaluateDynamicEndpointTimeout(synCtx));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class PropertyMediatorTest method testSetAndReadContextProperty.
public void testSetAndReadContextProperty() throws Exception {
PropertyMediator propMediator = new PropertyMediator();
propMediator.setName("name");
propMediator.setValue("value");
// set a local property to the synapse context
PropertyMediator propMediatorTwo = new PropertyMediator();
propMediatorTwo.setName("nameTwo");
propMediatorTwo.setValue("valueTwo");
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
propMediator.mediate(synCtx);
propMediatorTwo.mediate(synCtx);
assertTrue("value".equals((new SynapseXPath("synapse:get-property('name')")).stringValueOf(synCtx)));
assertTrue("valueTwo".equals((new SynapseXPath("synapse:get-property('nameTwo')")).stringValueOf(synCtx)));
PropertyMediator propMediatorThree = new PropertyMediator();
propMediatorThree.setName("name");
propMediatorThree.setValue("value");
propMediatorThree.setAction(PropertyMediator.ACTION_REMOVE);
propMediatorThree.mediate(synCtx);
assertNull((new SynapseXPath("synapse:get-property('name')")).stringValueOf(synCtx));
assertTrue("valueTwo".equals((new SynapseXPath("synapse:get-property('nameTwo')")).stringValueOf(synCtx)));
}
Aggregations