Sample dynamic routing stylesheet
You can use this sample stylesheet to handle the dynamic routing of requests between IBM MobileFirst™ Platform Foundation and IBM MobileFirst Platform Application Center. You refer to the stylesheet when you create rules to define a form-based authentication policy that generates and verifies LTPA tokens.
You provide a custom dynamic routing stylesheet when you define rule worklight-ssl-policy_verifyLTPA (see Integrating IBM WebSphere DataPower with a cluster of instances of MobileFirst Server, Table 3), and when you define rule worklight-ssl-policy_worklightSSLLogin (see Integrating IBM WebSphere DataPower with a cluster of instances of MobileFirst Server, Table 5).
<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:re="http://exslt.org/regular-expressions"
extension-element-prefixes="dp re dpconfig"
exclude-result-prefixes="dp">
<xsl:param name="dpconfig:worklightBackend"/>
<xsl:param name="dpconfig:applicationcenterBackend"/>
<xsl:template match="/">
<xsl:variable name="worklight" select="'worklight'"/>
<xsl:variable name="worklightconsole" select="'worklightconsole'"/>
<xsl:variable name="wladmin" select="'wladmin'"/>
<xsl:variable name="applicationcenter" select="'applicationcenter'"/>
<xsl:variable name="appcenterconsole" select="'appcenterconsole'"/>
<xsl:variable name="worklightBackend" select="$dpconfig:worklightBackend"/>
<xsl:variable name="applicationcenterBackend" select="$dpconfig:applicationcenterBackend"/>
<xsl:variable name="incomingURI" select="dp:variable('var://service/URI')"/>
<xsl:variable name="httpContentType" select="dp:http-request-header('Content-Type')"/>
<xsl:variable name="accessControlRequestHeaders" select="dp:http-request-header('Access-Control-Request-Headers')"/>
<xsl:variable name="accessControlRequestMethod" select="dp:http-request-header('Access-Control-Request-Method')"/>
<xsl:choose>
<!-- set the backend server if the url is /worklight -->
<xsl:when test="contains(dp:variable('var://service/URI'), $worklight) or contains(dp:variable('var://service/URI'), $worklightconsole) or contains(dp:variable('var://service/URI'), $wladmin)">
<dp:set-http-request-header name="'Content-Type'" value="$httpContentType"/>
<dp:set-variable name="'var://service/routing-url'" value="$worklightBackend"/>
<dp:set-variable name="'var://service/URI'" value="$incomingURI"/>
</xsl:when>
<xsl:when test="contains(dp:variable('var://service/URI'), $applicationcenter) or contains(dp:variable('var://service/URI'), $appcenterconsole)">
<dp:set-http-request-header name="'Content-Type'" value="$httpContentType"/>
<dp:set-http-request-header name="'Access-Control-Request-Headers'" value="$accessControlRequestHeaders"/>
<dp:set-http-request-header name="'Access-Control-Request-Method'" value="$accessControlRequestMethod"/>
<dp:set-variable name="'var://service/routing-url'" value="$applicationcenterBackend"/>
<dp:set-variable name="'var://service/URI'" value="$incomingURI"/>
</xsl:when>
<xsl:when test="contains(dp:variable('var://service/URI'), 'j_security_check')">
<dp:set-http-request-header name="'Content-Type'" value="$httpContentType"/>
<dp:set-variable name="'var://service/routing-url'" value="$applicationcenterBackend"/>
<dp:set-variable name="'var://service/URI'" value="'/appcenterconsole/login/j_security_check'"/>
</xsl:when>
<xsl:otherwise>
<xsl:message dp:type="all" dp:priority="error"> No matching url found. </xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>