Wednesday, May 29, 2013

Datapower XI50 - Dynamic routing to backends with End Points stored in WSRR

Problem

WSRR stores the End Point URLs for the same service. Based on an attribute in the request we would need to route to different backend URLs by looking up WSRR in a Datapower X150 applicance

Solution

The multiple end point URLs are stored as additional properties for a service definition in WSRR. From Datapower XI50 we query WSRR using the REST API provided by WSRR. We get the URLs as addtional properties and route to appropriate URL using DP variable - var://service/routing-url

Querying the WSRR is encapsulated with a seperate XML Firewall Proxy (XMLFW). The main Web Service Proxy (WSP) queries the XMLFW to get the End Point URLs as XML

Addtional IBM documentation - http://www.redbooks.ibm.com/redpapers/pdfs/redp4559.pdf

The XSLT to query the XMLFW is below

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
    xmlns:dpconfig="http://www.datapower.com/param/config" xmlns:exsl="http://exslt.org/common"
    extension-element-prefixes="dp dpconfig exsl" exclude-result-prefixes="dp dpconfig exsl">
    <xsl:param name="dpconfig:wsdlName" />
    <xsl:param name="dpconfig:queryWsrrUrl" />
    <xsl:template match="/">
        <xsl:variable name="wsrrResult">
            <dp:url-open target="{$dpconfig:queryWsrrUrl}">
                <querywsrr>
                    <wsdl><xsl:value-of select="$dpconfig:wsdlName"/></wsdl>
                   
                </querywsrr>
            </dp:url-open>
        </xsl:variable>
           
        <xsl:choose>
            <xsl:when
                test="dp:variable('var://context/Backend') = 'Backend1'">
                    <dp:set-variable name="'var://service/routing-url'"
                    value="exsl:node-set($wsrrResult)/resources/resource/properties/property[@name='Backend1_URL']/@value" />
            </xsl:when>
            <xsl:when
                test="dp:variable('var://context/RetrieveAutoPolicyDetailV2/Backend') = 'Backend2'">
                   
                    <dp:set-variable name="'var://service/routing-url'"
                    value="exsl:node-set($wsrrResult)/resources/resource/properties/property[@name='Backend2_URL']/@value" />

            </xsl:when>
            <xsl:when
                test="dp:variable('var://context/RetrieveAutoPolicyDetailV2/Backend') = 'Backend3'">
                    <dp:set-variable name="'var://service/routing-url'"
                    value="exsl:node-set($wsrrResult)/resources/resource/properties/property[@name='Backend3_URL']/@value" />
            </xsl:when>
           
            <xsl:otherwise>
                <dp:set-variable name="'var://service/routing-url'"
                    value="exsl:node-set($wsrrResult)/resources/resource/properties/property[@name='Backend4_URL']/@value" />
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
</xsl:stylesheet>

1 comment: