Wednesday, May 29, 2013

Datapower XI50 - Calling an external URL based on while construct and aggregating data

Problem

The problem occurs from having to aggregate data from an external URL (HTTP, MQ etc) until a particular condition is reached (while construct). This is on a Datapower XI50 appliance

Solution

We can simulate the while construct using a XSLT running on Datapower. The logic for calling the backend (either HTTP, MQ etc) can be encapsulated within a Multi Protocol Gateway (MPGW). The main Web Service Proxy (WSP) has the XSLT as a action which contains the while construct and call the MPGW using datapower extension function url:open()
The XSLT to perform the while construct is below


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:dp="http://www.datapower.com/extensions"
    xmlns:exsl="http://exslt.org/common"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    extension-element-prefixes="dp exsl" exclude-result-prefixes="dp exsl">

    <xsl:output method="xml" />

    <xsl:template match="/">
        <xsi:element name="test2">
            <xsl:call-template name="dots">
                <!--<xsl:with-param name="result1" select="start" />-->
            </xsl:call-template>
        </xsi:element>
    </xsl:template>

    <xsl:template name="dots">
        <!--<xsl:param name="result1" select="started" />-->
        <!--
            Invoking the HTTP / MQ URL and store it into a XSL Variable
        -->
        <xsl:variable name="tmp">
            <dp:url-open
                target="URL (Can be HTTP or MQ)">
                <xsl:copy-of select="dp:variable('var://context/INPUT')" />
            </dp:url-open>
        </xsl:variable>


        <xsl:copy-of select="$tmp" />


         <xsi:element name="blah">
         <xsl:copy-of select="<COLLECT DATA FROM OUTPUT FROM FIRST CALL>" />
        </xsi:element>
       

        <xsl:if
            test="{CONDITION}">
            <!-- Used for recursion -->
            <xsl:call-template name="dots">
               
                <!--
                    Used for aggregating results by sending back to the loop.
                    <xsl:with-param name="result1" select="concat($result1,$tmp)" />
                -->
            </xsl:call-template>
        </xsl:if>
        <!-- </xsl:if> -->

    </xsl:template>

</xsl:stylesheet>

No comments:

Post a Comment