Package org.apache.synapse.util.xpath

Examples of org.apache.synapse.util.xpath.SynapseXPath


        // 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");
View Full Code Here


    private void testMultipleKeys(int num) throws Exception {

        String xsltKeyValue = null;

        String path;
        SynapseXPath xpath;
        Value xsltKey;
        XSLTMediator transformMediator = new XSLTMediator();

        //default source, xsltFile, and state of key (dynamic or static)
        String source = "";
        String xsltFile = "";
        boolean isDynamicKey = true;

        // based on source, different XSLTFiles can be used
        if (num == 0) {
            source = SOURCE_STATIC_KEY;
            xsltFile = "static_key.xslt";
            xsltKeyValue = "StaticXsltKey";
            isDynamicKey = false;

        } else if (num == 1) {
            source = SOURCE_DYNAMIC_KEY1;
            xsltFile = "dynamic_key_1.xslt";
            xsltKeyValue = "DynamicXsltKey1";
            isDynamicKey = true;
        } else if (num == 2) {
            source = SOURCE_DYNAMIC_KEY2;
            xsltFile = "dynamic_key_2.xslt";
            xsltKeyValue = "DynamicXsltKey2";
            isDynamicKey = true;
        }

        if (isDynamicKey) {
            path = "//m0:CheckPriceRequest/m0:" + xsltKeyValue;
            xpath = new SynapseXPath(path);
            xpath.addNamespace("m0", "http://services.samples/xsd");

            // Create key from dynamic key (xpath)
            xsltKey = new Value(xpath);
            // set XSLT transformation URL (Xpath)
            transformMediator.setXsltKey(xsltKey);
View Full Code Here

        OMElement pool;

        try {
            // get the 'pool' element and determine if we need to create a DataSource or
            // lookup using JNDI
            SynapseXPath xpath = new SynapseXPath("self::node()/syn:connection/syn:pool");
            xpath.addNamespace("syn", XMLConfigConstants.SYNAPSE_NAMESPACE);
            pool = (OMElement) xpath.selectSingleNode(elem);
            if (pool.getFirstChildWithName(DSNAME_Q) != null) {
                readLookupConfig(mediator, pool);
            } else if (pool.getFirstChildWithName(DRIVER_Q) != null) {
                readCustomDataSourceConfig(pool, mediator);
            } else {
View Full Code Here

                String xpath = getAttribute(paramElt, ATT_EXPRN);
                String value = getAttribute(paramElt, ATT_VALUE);

                if (xpath != null || value != null) {

                    SynapseXPath xp = null;
                    if (xpath != null) {
                        try {
                            xp = SynapseXPathFactory.getSynapseXPath(paramElt, ATT_EXPRN);

                        } catch (JaxenException e) {
View Full Code Here

public class SynapseXPathTest extends TestCase {

    String message = "This is XPath test";   

    public void testStringXPath() throws Exception {
        SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test");
        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\">" + message + "</m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\">" + message + "</m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testStringXPath2() throws Exception {
        SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test/{http://someother}another");
        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\"><m1:another xmlns:m1=\"http://someother\">" + message + "</m1:another></m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\"><m1:another xmlns:m1=\"http://someother\">" + message + "</m1:another></m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testAbsoluteXPath() throws Exception {
        SynapseXPath xpath = new SynapseXPath("//test");
        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testBodyRelativeXPath() throws Exception {
        SynapseXPath xpath = new SynapseXPath("$body/test");
        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        assertEquals(message, xpath.stringValueOf(ctx));
        Object node = xpath.selectSingleNode(ctx);
        assertTrue(node instanceof OMElement);
        assertEquals(message, ((OMElement)node).getText());
    }
View Full Code Here

        OMFactory fac = ctx.getEnvelope().getOMFactory();
        OMNamespace ns = fac.createOMNamespace("http://test", "t");
        ctx.getEnvelope().getHeader().addHeaderBlock("test", ns).setText(message);
        ctx.getEnvelope().getHeader().addHeaderBlock("test2", ns);
       
        SynapseXPath xpath = new SynapseXPath("$header/t:test");
        xpath.addNamespace(ns);
        assertEquals(message, xpath.stringValueOf(ctx));
       
        xpath = new SynapseXPath("$header/*");
        assertEquals(2, xpath.selectNodes(ctx).size());
    }
View Full Code Here

        xpath = new SynapseXPath("$header/*");
        assertEquals(2, xpath.selectNodes(ctx).size());
    }

    public void testContextProperties() throws Exception {
        SynapseXPath xpath = new SynapseXPath("$ctx:test");
        MessageContext synCtx = new TestMessageContext();
        synCtx.setProperty("test", message);
        assertEquals(xpath.evaluate(synCtx), message);
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.util.xpath.SynapseXPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.